在 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.
所以我想尝试一下这个功能:
- 创建项目
- 添加
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5c28392f28292f392e1c39243d312c3039723f3331" rel="noreferrer noopener nofollow">[email protected]</a>
到项目并授予查看者角色。 - 打开新浏览器并使用
testuser
登录 GCP 控制台,并确认用户只能查看实例,不能创建实例。 - 添加服务帐户:
<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
角色,因此该服务帐户可以创建实例。 - 授予
<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
按钮保持禁用状态。
那么到底出了什么问题呢?
我理解错了吗?授予
<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 创建实例的能力?我做错了什么吗?
如何通过
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/