如何将源存储库中的存储库克隆到计算引擎以在需要时手动提取它

时间:2018-05-17 21:47:49

标签: google-compute-engine google-iam google-source-repositories

在我的本地macOS上,以下命令工作正常:

$ gcloud source repos clone myrepo --project=myproject

(虽然我不确定它是否有效,因为之前我遵循~/.gitcookies程序)

但是当我在CE上这样做时:

$ gcloud source repos clone myrepo --project=myproject
ERROR: (gcloud.source.repos.clone) PERMISSION_DENIED: Request had insufficient authentication scopes.

$ gcloud source repos list
ERROR: (gcloud.source.repos.list) User [<digits>-compute@developer.gserviceaccount.com] does not have permission to access project [<myproject>] (or it may not exist): Request had insufficient authentication scopes.

$ gcloud auth list
                  Credentialed Accounts
ACTIVE  ACCOUNT
*       <digits>-compute@developer.gserviceaccount.com

在IAM选项卡中,我看到此服务帐户具有“所有资源的编辑者访问权限”,但它没有帮助。即使我添加角色Source Repository Read + Write。

UPD:我在“角色”标签中找不到.clone角色:

enter image description here

$ gcloud help source repos

COMMANDS
    COMMAND is one of the following:

     clone
        Clone a cloud source repository.
     create
        Create a cloud source repository.
     delete
        Delete a cloud source repository.
     describe
        Describe a cloud source repository.
     get-iam-policy
        Get the IAM policy for the named cloud source repository.
     list
        List the repositories the currently active project.
     set-iam-policy
        Set the IAM policy for the named repository.

但它可能包含在.get中,因此Reader已经尝试过了:

enter image description here

UPD2:sudo /usr/local/share/google/google-cloud-sdk/bin/gcloud components update没有帮助。

我现在想象的唯一两个选项是编辑

enter image description here

(这是我在互联网上发现的唯一似乎是解决方案的东西,但是博客文章是用某种东方语言编写的,所以我不确定)但是它需要VM停止是不可接受的。

或伪造另一个服务帐户,但我不确定在gcloud CLI中切换它不会破坏在该计算机上运行的其他应用程序。或者也许我只能在克隆回购时使用它一次,它会坚持下去吗?

2 个答案:

答案 0 :(得分:0)

如果您使用的是Google Compute Engine实例的服务帐户,可以在此处阅读[1],则需要将访问范围授予Cloud Source Repositories为Full或Read / Write。要做到这一点,你必须停止实例。

如果您不想停止实例,可以创建新的服务帐户并使用以下命令激活服务帐户:

$ gcloud auth activate-service-account --key-file = [KEY.JSON]

并且这个开始使用gcloud工具的新服务帐户:

$ gcloud init

如果您在此新服务帐户中使用角色编辑器,则存在一个已知问题,因为角色编辑器没有source.repos.create权限。

$ gcloud iam角色描述角色/编辑器| grep“source.repos”

  • source.repos.get
  • source.repos.getIamPolicy
  • source.repos.list
  • source.repos.update

作为一个工作场所,为了创建云源存储库,您需要具有角色:“roles / source.admin”,您可以在这里阅读[2]:“提供创建,更新,删除,列出的权限,克隆,获取和浏览存储库。还提供读取和更改IAM策略的权限。“

这里[3]您可以跟踪此问题的状态,但请记住,没有ETA或担保将被修复。

[1] https://cloud.google.com/compute/docs/access/service-accounts#accesscopesiam

[2] https://cloud.google.com/iam/docs/understanding-roles#source_repository_roles

[3] https://issuetracker.google.com/80329938

答案 1 :(得分:0)

您可以通过实例设置启用Full Access to All Cloud APIs。您首先需要停止VM。只需单击实例名称,按Stop,然后等待,一旦实例停止,按Edit并检查API Access的适当设置。然后启动实例。