使用来自另一个Google Project的服务帐户创建Google Compute实例

时间:2018-08-06 21:21:33

标签: google-compute-engine gcloud service-accounts

我想知道是否可以将在 my-project-b 中在 my-project-a 中创建的服务帐户附加到Google Compute Engine实例。 >?

以下命令:

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.

不确定是否与此相关,但是查看UI(在 my-project-b 中)时,无法选择从任何其他项目中添加服务帐户。我希望能够添加帐户 my-service-account@my-project-a.iam.gserviceaccount.com

enter image description here

1 个答案:

答案 0 :(得分:2)

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

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

    gcloud auth激活服务帐户--key-file = YOUR_JSON_FILE

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

    gcloud身份验证列表

相关问题