如何模拟 GCP 服务帐户以访问 Web 控制台?

How can I impersonate a GCP service account for web console access?

我想要类似于 AWS 角色切换的功能。在 AWS 中,我可以切换到 AWS Web 控制台中的角色 - 模拟“服务帐户”以通过网站访问 AWS。

Gcloud 支持模拟服务帐户,但我找不到有关如何模拟服务帐户以访问 Web 控制台的示例。

有些用户偶尔需要访问生产 gcp 项目。有时他们使用 Web 控制台比使用 cli 更方便。我不想让他们的用户帐户直接访问生产,我想遵循最佳实践并要求提升权限。我也不想为他们创建新的、额外的用户帐户以进行生产访问。

在 Gcloud 中很容易模拟服务帐户,但是 Web 控制台访问是否支持此操作?

可以使用 gcloud CLI 模拟服务帐户来访问项目资源,但不能使用它们通过控制台访问项目资源,因为服务帐户严格来说是 non-human 帐户。它们适用于您的应用程序需要访问资源或自行执行操作的场景。

如果您想为您的用户提供对 Web 控制台的访问权限,请配置 user accounts:

User accounts are managed as Google Accounts, and they represent a developer, administrator, or any other person who interacts with Google Cloud. They are intended for scenarios where your application needs to access resources on behalf of a human user.

When an application needs to access Google Cloud APIs on behalf of an end user, the application initiates an OAuth consent flow. After the user completes the flow, your application receives an access token that enables your application to call Google Cloud APIs on behalf of the user.

Here 您可以找到有关使用身份平台在 Web 上登录用户的指南。

并且 here 您将找到有关使用 OAuth 2.0 访问 Google API 的更多信息

对于 Google Cloud,我实施的一项技术是分组。每个组都有一组角色。当用户需要访问云资源时,他们会去后端应用程序请求访问。后端应用程序将他们的身份附加到所需的组一段时间,然后自动删除该身份。

可以扩展此概念以允许用户 select 后端应用添加到项目的 IAM 绑定并自动删除的其他 IAM 角色。用户还可以单击“我完成了”按钮以删除其提升的角色。

这确实需要开发,但实施起来相对较小。用户现在知道他们提升的访问权限是 monitored/tracked 并且经过良好的培训只有在实际需要时才使用它。