google-cloud-platform - 如何使用GCP服务帐户用户角色创建资源?

标签 google-cloud-platform service-accounts

在 GCP 文档上:

Users granted the Service Account User role on a service account can use it to indirectly access all the resources to which the service account has access. For example, if a service account has been granted the Compute Admin role (roles/compute.admin), a user that has been granted the Service Account Users role (roles/iam.serviceAccountUser) on that service account can act as the service account to start a Compute Engine instance. In this flow, the user impersonates the service account to perform any tasks using its granted roles and permissions.

所以我想尝试一下这个功能:

  1. 创建项目
  2. 添加<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c28392f28292f392e1c39243d312c3039723f3331" rel="noreferrer noopener nofollow">[email protected]</a>到项目并授予查看者角色。
  3. 打开新浏览器并使用 testuser 登录 GCP 控制台,并确认用户只能查看实例,不能创建实例。
  4. 添加服务帐户:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b081a56151a161e3b0b0914111e180f56121f55121a16551c081e090d12181e1a1818140e150f55181416" rel="noreferrer noopener nofollow">[email protected]</a> ,并授予Compute Admin角色,因此该服务帐户可以创建实例。
  5. 授予<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2c6d7c1c6c7c1d7c0f2d7cad3dfc2ded79cd1dddf" rel="noreferrer noopener nofollow">[email protected]</a>service account user此服务帐户的角色。

因此,根据上述 GCP 文档,我预计 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3b7a6b0b7b6b0a6b183a6bba2aeb3afa6eda0acae" rel="noreferrer noopener nofollow">[email protected]</a>可以创建实例,但是Create instance按钮保持禁用状态。

然后我授予<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d09180e09080e180f3d18051c100d1118531e1210" rel="noreferrer noopener nofollow">[email protected]</a>service account user在项目层面的作用,依然是Create instance按钮保持禁用状态。

那么到底出了什么问题呢?

  1. 我理解错了吗?授予<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8bcadbbbcbdbbadba88adb0a9a5b8a4ade6aba7a5" rel="noreferrer noopener nofollow">[email protected]</a>service account user角色没有赋予 testuser 创建实例的能力?

  2. 我做错了什么吗?

  3. 如何通过 service account user 创建实例?

最佳答案

当您明确要求 gcloud CLI 使用模拟时,模拟可与命令行配合使用。但默认情况下它不处于事件状态,因此无法在 GUI 上运行。

尝试使用参数 --impersonate-service-account=<ServiceAccountEmail> 的 gcloud 命令

注意:您需要在项目级别授予用户“服务使用消费者”角色,并在服务帐户级别(或项目级别)授予用户“服务帐户 token 创建者”角色如果你想模拟项目的所有服务帐户)。更多详细信息,请参阅 blog post of John Hanley

关于google-cloud-platform - 如何使用GCP服务帐户用户角色创建资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62925708/

相关文章:

google-app-engine - Google 云平台 (GCP) 未知错误。原始错误消息 : Operation failed: Insufficient CPU quota in region

google-cloud-platform - 谷歌 CloudSQL 实例存储增长失控

python - 服务帐户没有对 Google Cloud Storage 的 storage.objects.get 访问权限

google-api - 如何授权服务帐户访问 Google Admin API

google-cloud-platform - 在同一个Google云端项目中添加多个git存储库的可能方法

javascript - typescript 导入@google-cloud/pubsub

postgresql - 对Cloud SQL(GCP)进行维护后pg_repack版本不匹配

google-apps-script - 通过服务帐户使用高级 Google 服务

google-api - 服务帐户 json 文件是什么样的?

android - 将文件上传到 android 中唯一的谷歌驱动器帐户