当您在项目中添加新成员时,可以使用 Identity and Access Management (IAM) 政策为该成员授予一个或多个 IAM 角色。每个 IAM 角色都包含授予成员访问特定资源的权限。
Compute Engine 具有一组预定义 IAM 角色,本页对这些角色进行了说明。您还可以创建自定义角色,这些角色包含的权限子集直接对应于您的需要。
如需了解每种方法所需的权限,请参阅 Compute Engine API 参考文档:
如需了解如何授予访问权限,请参阅以下页面。
- 如需在项目级层设置 IAM 政策,请参阅 IAM 文档中的授予、更改和撤消对资源的访问权限。
- 如需针对特定 Compute Engine 资源设置政策,请阅读授予对 Compute Engine 资源的访问权限。
- 如需为 Compute Engine 服务账号分配角色,请阅读为实例创建和启用服务账号。
什么是 IAM?
Google Cloud 提供 IAM,可让您授予对特定 Google Cloud 资源的更细化访问权限,并防止对其他资源进行不必要的访问。IAM 允许您采用最小权限安全原则,您只需授予对您资源的必要访问权限。
IAM 允许您通过设置 IAM 政策来控制谁(身份)对哪些资源具有何种权限(角色)。IAM 政策可为项目成员授予一个或多个特定角色,进而授予相应身份特定权限。例如,您可以为 Google 账号分配给定资源(如项目)的 roles/compute.networkAdmin
角色,此后该账号便可控制项目中网络相关的资源,但无法管理实例和磁盘等其他资源。您还可以使用 IAM 来管理为项目团队成员授予的 Google Cloud 控制台旧版角色。
serviceAccountUser 角色
同时授予 roles/compute.instanceAdmin.v1
和 roles/iam.serviceAccountUser
角色时,后者会授予成员创建和管理使用服务账号的实例的权限。具体而言,同时授予 roles/iam.serviceAccountUser
和 roles/compute.instanceAdmin.v1
角色可让成员拥有执行以下操作的权限:
- 创建一个以服务账号身份运行的实例。
- 将永久性磁盘附加到以服务账号身份运行的实例上。
- 在以服务账号身份运行的实例上设置实例元数据。
- 通过 SSH 连接到一个以服务账号身份运行的实例。
- 将实例重新配置为以服务账号身份运行。
您可以通过以下两种方式之一授予 roles/iam.serviceAccountUser
:
推荐。将该角色授予特定服务账号中的成员。这会使得该成员有权访问具有
iam.serviceAccountUser
角色的服务账号,但不允许其访问不具有iam.serviceAccountUser
角色的其他服务账号。在项目级层为成员授予该角色。该成员有权访问项目中的所有服务账号,包括将来创建的服务账号。
如果您对服务账号不熟悉,请详细了解服务账号。
Google Cloud Console 权限
如需使用 Google Cloud Console 访问 Compute Engine 资源,您必须拥有一个包含项目的以下权限的角色:
compute.projects.get
以 instanceAdmin 身份连接到实例
为项目成员授予 roles/compute.instanceAdmin.v1
角色后,该项目成员即可使用标准 Google Cloud 工具(例如 gcloud CLI 或在浏览器中使用 SSH)连接到虚拟机 (VM) 实例。
当成员使用 gcloud CLI 或 SSH-in-browser 时,该工具将自动生成公钥/私钥对,并将公钥添加到项目元数据中。如果成员没有修改项目元数据的权限,则该工具会将成员的公钥添加到实例元数据中。
如果成员已有想使用的现有密钥对,则可以手动将其公钥添加到实例元数据中。详细了解如何将 SSH 密钥添加到实例。
IAM 与服务账号
创建新的自定义服务账号并将 IAM 角色授予服务账号以限制访问实例的权限。将 IAM 角色与自定义服务账号结合使用,您可以:
- 通过精细的 IAM 角色限制您的实例对 Google Cloud API 的访问权限。
- 为每个实例或每组实例授予唯一身份。
- 限制您的默认服务账号的访问权限。
托管实例组和 IAM
代管式实例组 (MIG) 是代表您执行操作的资源,无需直接的用户互动。例如,MIG 可以在实例组中添加和移除虚拟机。
由 Compute Engine 执行的属于 MIG 的所有操作都是使用您项目的 Google API 服务代理完成的,此服务代理具有如下所示的电子邮件地址:PROJECT_ID@cloudservices.gserviceaccount.com
默认情况下,Google API 服务代理会在项目级层被授予 Editor 角色 (roles/editor
),从而获得足够的权限根据 MIG 的配置创建资源。如果您要为 Google API 服务代理自定义访问权限,请授予 Compute Instance Admin (v1) 角色 (roles/compute.instanceAdmin.v1
) 和(可选)Service Account User 角色 (roles/iam.serviceAccountUser
)。仅当 MIG 创建可以服务账号身份运行的虚拟机时,才需要 Service Account User 角色。
请注意,Google API 服务代理也会被其他进程(包括 Deployment Manager)使用。
当您创建 MIG 或更新其实例模板时,Compute Engine 会验证 Google API 服务代理具有以下角色和权限:
- Service Account User 角色;如果您计划创建可以服务账号身份运行的实例,则该角色很重要
- 针对通过实例模板引用的所有资源(例如映像、磁盘、VPC 网络和子网)的权限
预定义 Compute Engine IAM 角色
使用 IAM 时,Compute Engine API 中的每个 API 方法都要求发出 API 请求的身份具有使用相应资源的适当权限。您可以通过设置政策为项目成员(用户、群组或服务账号)授予角色,进而授予相应权限。
除了基本角色(Viewer、Editor、Owner)和自定义角色之外,您还可以为项目成员分配以下 Compute Engine 预定义角色。
您可以针对同一资源向某位成员授予多个角色。例如,如果您的网络团队还负责管理防火墙规则,您可以将 roles/compute.networkAdmin
和 roles/compute.securityAdmin
同时授予该网络团队的 Google 群组。
下表描述了预定义 Compute Engine IAM 角色,以及每个角色所包含的权限。每个角色包含一组适合特定任务的权限。例如,Instance Admin 角色授予管理实例的权限,与网络相关的角色具有管理网络相关资源的权限,而安全角色具有管理安全相关资源(如防火墙和 SSL 证书)的权限。
Compute Admin role
Details | Permissions |
---|---|
Compute Admin( Full control of all Compute Engine resources.
If the user will be managing virtual machine instances that are configured
to run as a service account, you must also grant the
Lowest-level resources where you can grant this role:
|
|
Compute Future Reservation Admin role
Details | Permissions |
---|---|
Compute Future Reservation Admin Beta(
|
|
Compute Future Reservation User role
Details | Permissions |
---|---|
Compute Future Reservation User Beta(
|
|
Compute Future Reservation Viewer role
Details | Permissions |
---|---|
Compute Future Reservation Viewer Beta(
|
|
Compute Image User role
Details | Permissions |
---|---|
Compute Image User( Permission to list and read images without having other permissions on the image. Granting this role at the project level gives users the ability to list all images in the project and create resources, such as instances and persistent disks, based on images in the project. Lowest-level resources where you can grant this role:
|
|
Compute Instance Admin (beta) role
Details | Permissions |
---|---|
Compute Instance Admin (beta)( Permissions to create, modify, and delete virtual machine instances. This includes permissions to create, modify, and delete disks, and also to configure Shielded VM settings.
If the user will be managing virtual machine instances that are configured
to run as a service account, you must also grant the
For example, if your company has someone who manages groups of virtual machine instances but does not manage network or security settings and does not manage instances that run as service accounts, you can grant this role on the organization, folder, or project that contains the instances, or you can grant it on individual instances. Lowest-level resources where you can grant this role:
|
|
Compute Instance Admin (v1) role
Details | Permissions |
---|---|
Compute Instance Admin (v1)( Full control of Compute Engine instances, instance groups, disks, snapshots, and images. Read access to all Compute Engine networking resources. If you grant a user this role only at an instance level, then that user cannot create new instances. |
|
Compute Load Balancer Admin role
Details | Permissions |
---|---|
Compute Load Balancer Admin( Permissions to create, modify, and delete load balancers and associate resources. For example, if your company has a load balancing team that manages load balancers, SSL certificates for load balancers, SSL policies, and other load balancing resources, and a separate networking team that manages the rest of the networking resources, then grant this role to the load balancing team's group. Lowest-level resources where you can grant this role:
|
|
Compute Load Balancer Services User role
Details | Permissions |
---|---|
Compute Load Balancer Services User( Permissions to use services from a load balancer in other projects. |
|
Compute Network Admin role
Details | Permissions |
---|---|
Compute Network Admin( Permissions to create, modify, and delete networking resources, except for firewall rules and SSL certificates. The network admin role allows read-only access to firewall rules, SSL certificates, and instances (to view their ephemeral IP addresses). The network admin role does not allow a user to create, start, stop, or delete instances.
For example, if your company has a security team that manages firewalls
and SSL certificates and a networking team that manages the rest of the
networking resources, then grant this role to the networking team's group.
Or, if you have a combined team that manages both security and networking,
then grant this role as well as the
Lowest-level resources where you can grant this role:
|
|
Compute Network User role
Details | Permissions |
---|---|
Compute Network User( Provides access to a shared VPC network Once granted, service owners can use VPC networks and subnets that belong to the host project. For example, a network user can create a VM instance that belongs to a host project network but they cannot delete or create new networks in the host project. Lowest-level resources where you can grant this role:
|
|
Compute Network Viewer role
Details | Permissions |
---|---|
Compute Network Viewer( Read-only access to all networking resources For example, if you have software that inspects your network configuration, you could grant this role to that software's service account. Lowest-level resources where you can grant this role:
|
|
Compute Organization Firewall Policy Admin role
Details | Permissions |
---|---|
Compute Organization Firewall Policy Admin( Full control of Compute Engine Organization Firewall Policies. |
|
Compute Organization Firewall Policy User role
Details | Permissions |
---|---|
Compute Organization Firewall Policy User( View or use Compute Engine Firewall Policies to associate with the organization or folders. |
|
Compute Organization Security Policy Admin role
Details | Permissions |
---|---|
Compute Organization Security Policy Admin( Full control of Compute Engine Organization Security Policies. |
|
Compute Organization Security Policy User role
Details | Permissions |
---|---|
Compute Organization Security Policy User( View or use Compute Engine Security Policies to associate with the organization or folders. |
|
Compute Organization Resource Admin role
Details | Permissions |
---|---|
Compute Organization Resource Admin( Full control of Compute Engine Firewall Policy associations to the organization or folders. |
|
Compute OS Admin Login role
Details | Permissions |
---|---|
Compute OS Admin Login( Access to log in to a Compute Engine instance as an administrator user. Lowest-level resources where you can grant this role:
|
|
Compute OS Login role
Details | Permissions |
---|---|
Compute OS Login( Access to log in to a Compute Engine instance as a standard user. Lowest-level resources where you can grant this role:
|
|
Compute OS Login External User role
Details | Permissions |
---|---|
Compute OS Login External User( Available only at the organization level. Access for an external user to set OS Login information associated with this organization. This role does not grant access to instances. External users must be granted one of the required OS Login roles in order to allow access to instances using SSH. Lowest-level resources where you can grant this role:
|
|
Compute packet mirroring admin role
Details | Permissions |
---|---|
Compute packet mirroring admin( Specify resources to be mirrored. |
|
Compute packet mirroring user role
Details | Permissions |
---|---|
Compute packet mirroring user( Use Compute Engine packet mirrorings. |
|
Compute Public IP Admin role
Details | Permissions |
---|---|
Compute Public IP Admin( Full control of public IP address management for Compute Engine. |
|
Compute Security Admin role
Details | Permissions |
---|---|
Compute Security Admin( Permissions to create, modify, and delete firewall rules and SSL certificates, and also to configure Shielded VM settings. For example, if your company has a security team that manages firewalls and SSL certificates and a networking team that manages the rest of the networking resources, then grant this role to the security team's group. Lowest-level resources where you can grant this role:
|
|
Compute Sole Tenant Viewer role
Details | Permissions |
---|---|
Compute Sole Tenant Viewer( Permissions to view sole tenancy node groups |
|
Compute Storage Admin role
Details | Permissions |
---|---|
Compute Storage Admin( Permissions to create, modify, and delete disks, images, and snapshots. For example, if your company has someone who manages project images and you don't want them to have the editor role on the project, then grant this role to their account on the project. Lowest-level resources where you can grant this role:
|
|
Compute Viewer role
Details | Permissions |
---|---|
Compute Viewer( Read-only access to get and list Compute Engine resources, without being able to read the data stored on them. For example, an account with this role could inventory all of the disks in a project, but it could not read any of the data on those disks. Lowest-level resources where you can grant this role:
|
|
Compute Shared VPC Admin role
Details | Permissions |
---|---|
Compute Shared VPC Admin( Permissions to administer shared VPC host projects, specifically enabling the host projects and associating shared VPC service projects to the host project's network. At the organization level, this role can only be granted by an organization admin.
Google Cloud recommends that the Shared VPC Admin be the owner of the shared VPC host project. The
Shared VPC Admin is responsible for granting the Compute Network User role
( Lowest-level resources where you can grant this role:
|
|
OS Config Admin role
Details | Permissions |
---|---|
OS Config Admin Beta( Full access to OS Config resources |
|
GuestPolicy Admin role
Details | Permissions |
---|---|
GuestPolicy Admin Beta( Full admin access to GuestPolicies |
|
GuestPolicy Editor role
Details | Permissions |
---|---|
GuestPolicy Editor Beta( Editor of GuestPolicy resources |
|
GuestPolicy Viewer role
Details | Permissions |
---|---|
GuestPolicy Viewer Beta( Viewer of GuestPolicy resources |
|
InstanceOSPoliciesCompliance Viewer role
Details | Permissions |
---|---|
InstanceOSPoliciesCompliance Viewer Beta( Viewer of OS Policies Compliance of VM instances |
|
OS Inventory Viewer role
Details | Permissions |
---|---|
OS Inventory Viewer( Viewer of OS Inventories |
|
OSPolicyAssignment Admin role
Details | Permissions |
---|---|
OSPolicyAssignment Admin( Full admin access to OS Policy Assignments |
|
OSPolicyAssignment Editor role
Details | Permissions |
---|---|
OSPolicyAssignment Editor( Editor of OS Policy Assignments |
|
OSPolicyAssignmentReport Viewer role
Details | Permissions |
---|---|
OSPolicyAssignmentReport Viewer( Viewer of OS policy assignment reports for VM instances |
|
OSPolicyAssignment Viewer role
Details | Permissions |
---|---|
OSPolicyAssignment Viewer( Viewer of OS Policy Assignments |
|
PatchDeployment Admin role
Details | Permissions |
---|---|
PatchDeployment Admin( Full admin access to PatchDeployments |
|
PatchDeployment Viewer role
Details | Permissions |
---|---|
PatchDeployment Viewer( Viewer of PatchDeployment resources |
|
Patch Job Executor role
Details | Permissions |
---|---|
Patch Job Executor( Access to execute Patch Jobs. |
|
Patch Job Viewer role
Details | Permissions |
---|---|
Patch Job Viewer( Get and list Patch Jobs. |
|
PolicyOrchestrator Admin role
Details | Permissions |
---|---|
PolicyOrchestrator Admin Beta( Admin of PolicyOrchestrator resources |
|
PolicyOrchestrator Viewer role
Details | Permissions |
---|---|
PolicyOrchestrator Viewer Beta( Viewer of PolicyOrchestrator resources |
|
Project Feature Settings Editor role
Details | Permissions |
---|---|
Project Feature Settings Editor( Read/write access to project feature settings |
|
Project Feature Settings Viewer role
Details | Permissions |
---|---|
Project Feature Settings Viewer( Read access to project feature settings |
|
Upgrade Report Viewer role
Details | Permissions |
---|---|
Upgrade Report Viewer Beta( Provides read-only access to VM Manager Upgrade Reports |
|
OS Config Viewer role
Details | Permissions |
---|---|
OS Config Viewer Beta( Readonly access to OS Config resources |
|
OS VulnerabilityReport Viewer role
Details | Permissions |
---|---|
OS VulnerabilityReport Viewer( Viewer of OS VulnerabilityReports |
|
DNS Administrator role
Details | Permissions |
---|---|
DNS Administrator( Provides read-write access to all Cloud DNS resources. Lowest-level resources where you can grant this role:
|
|
DNS Peer role
Details | Permissions |
---|---|
DNS Peer( Access to target networks with DNS peering zones |
|
DNS Reader role
Details | Permissions |
---|---|
DNS Reader( Provides read-only access to all Cloud DNS resources. Lowest-level resources where you can grant this role:
|
|
Service Account Admin role
Details | Permissions |
---|---|
Service Account Admin( Create and manage service accounts. Lowest-level resources where you can grant this role:
|
|
Create Service Accounts role
Details | Permissions |
---|---|
Create Service Accounts( Access to create service accounts. |
|
Delete Service Accounts role
Details | Permissions |
---|---|
Delete Service Accounts( Access to delete service accounts. |
|
Service Account Key Admin role
Details | Permissions |
---|---|
Service Account Key Admin( Create and manage (and rotate) service account keys. Lowest-level resources where you can grant this role:
|
|
Service Account OpenID Connect Identity Token Creator role
Details | Permissions |
---|---|
Service Account OpenID Connect Identity Token Creator( Create OpenID Connect (OIDC) identity tokens |
|
Service Account Token Creator role
Details | Permissions |
---|---|
Service Account Token Creator( Impersonate service accounts (create OAuth2 access tokens, sign blobs or JWTs, etc). Lowest-level resources where you can grant this role:
|
|
Service Account User role
Details | Permissions |
---|---|
Service Account User( Run operations as the service account. Lowest-level resources where you can grant this role:
|
|
View Service Accounts role
Details | Permissions |
---|---|
View Service Accounts( Read access to service accounts, metadata, and keys. |
|
Workload Identity User role
Details | Permissions |
---|---|
Workload Identity User( Impersonate service accounts from federated workloads. |
|