如何为 GCP 实例提供计算操作系统登录

如何为 GCP 实例提供计算操作系统登录

我正在尝试授予其中一名团队成员仅限计算操作系统登录的访问权限,但我无法建立它。

我做得如何?

步骤1

In the appropriate project under the IAM I added the user email and given Role for Compute OS Login after that.

第2步

在终端尝试

# glcoud init 

在我提供了所有必要的信息后,我尝试使用 gcloud 登录

# gcloud compute ssh sjkeerthi@test-instance -- -p 2020

No zone specified. Using zone [europe-west2-c] for instance: [test-instance].
Updating project ssh metadata...failed.                                                                                                              
Updating instance ssh metadata...failed.                                                                                                             
ERROR: (gcloud.compute.ssh) Could not add SSH key to instance metadata:
 - The user does not have access to service account '[email protected]'.  User: '[email protected]'.  Ask a project owner to grant you the iam.serviceAccountActor role on the service account

注意:- 即使我在元数据下设置了 enable-oslogin=True

答案1

我认为以下公开文献在用户账户上配置 OS 登录角色会很有帮助。您收到的错误表明您的用户缺少 (iam.serviceAccountUser) 角色。

The user does not have access to service account '[email protected]'. User: '[email protected]'. Ask a project owner to grant you the iam.serviceAccountActor role on the service account

根据公共文档中提供的示例,您可以通过以下流程向用户授予即时访问权限:

授予用户必要的实例访问角色。

用户必须具有以下角色:

  1. iam.serviceAccountUser 角色。

以下登录角色之一:

  1. compute.osLogin 角色不授予管理员权限
  2. compute.osAdminLogin 角色,授予管理员权限

答案2

您需要将服务帐户参与者角色添加到用户帐户,以便它可以充当服务帐户“[电子邮件保护]“。

此角色已被弃用,现在您必须将服务帐户用户角色和服务帐户令牌创建者授予 IAM 中的用户帐户。

有关更多详细信息,您可以参考此处的公开文档关联

如果您尝试从 Google Compute Engine (GCE) 实例通过 ssh 连接到另一个 GCE 实例,请确保源实例在其配置设置中将 Compute Engine 范围设置为读/写,以便它可以访问其他 GCE 实例。

答案3

您需要向您的 IAM 账户添加以下角色,如图所示

  • 服务帐户用户roles/iam.serviceAccountUser
  • 以下任一角色:
    • 计算操作系统登录roles/compute.osLogin如果你只想以普通用户身份登录
    • 计算操作系统管理员登录roles/compute.osAdminLogin如果你想要能够以管理员身份登录或拥有 root 权限

相关内容