代码之家  ›  专栏  ›  技术社区  ›  Jan Krynauw

使用另一个Google项目中的服务帐户创建Google Compute实例

  •  0
  • Jan Krynauw  · 技术社区  · 7 年前

    我想知道是否可以附加在中创建的服务帐户 我的项目A 到一个谷歌计算引擎实例 我的项目B ?

    以下命令:

    gcloud beta compute instances create my-instance \
    
    --service-account=my-service-account@my-project-a.iam.gserviceaccount.com \
    --scopes=https://www.googleapis.com/auth/cloud-platform \
    --project=my-project-b
    

    给出以下错误:

    (gcloud.beta.compute.instances.create) Could not fetch resource:
    - The user does not have access to service account 'my-service-account@my-project-a.iam.gserviceaccount.com'.  User: 'me@mysite.com'.  Ask a project owner to grant you the iam.serviceAccountUser role on the service account.  me@mysite.com is my account and I'm the owner of the org.
    

    不确定这是否相关,但查看用户界面(在 我的项目B )没有从任何其他项目添加服务帐户的选项。我希望能添加帐户 我的-service-account@my-project-a.iam.gsserviceaccount.com

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  2
  •   F10    7 年前

    您可以按照以下步骤将服务帐户从my-project-a验证到my-project-b中的实例:

    1. 在my-project-a中为计算引擎创建具有适当角色的服务帐户
    2. 下载JSON文件。
    3. 复制我的项目-新服务帐户电子邮件
    4. 在我的项目B上, add a team member 使用上一步复制的电子邮件
    5. 通过ssh连接到my-project-b中的实例
    6. 从my-project-b实例的步骤2复制JSON文件
    7. 运行以下命令 activate the service account :

      gcloud auth activate service account--密钥文件=您的\json \u文件

    8. 使用以下命令进行验证:

      gCloud身份验证列表

    推荐文章