GCP IAM:向服务帐户授予角色 while/after 通过 python API 创建它
GCP IAM: Granting a role to a service account while/after creating it via python API
目标:
使用 python,我想在 Google 云平台上的项目中创建一个服务帐户并授予该服务帐户一个角色。
问题:
文档解释 here how to grant a single role to the service account. However, it seems to be only possible by using the Console or the gcloud tool, not with python. The alternative for python is to update the whole IAM policy of the project to grant the role for the single service account and overwrite it (described here)。 但是,覆盖整个策略似乎风险很大,因为如果出现错误,整个项目的策略可能会丢失。 因此我想避免这种情况。
问题:
我正在使用 here in the docs 提供的 python 代码创建服务帐户。是否可以在使用此代码或以任何其他方式创建服务帐户时已经授予角色?
创建服务帐户、创建服务帐户密钥、下载服务帐户 JSON 密钥文件和授予角色是单独的步骤。没有单一的API创建一个服务帐户并同时授予一个角色。
任何时候更新项目的 IAM 绑定都是有风险的。 Google 防止多个应用程序同时更新 IAM。通过在没有成员的情况下覆盖策略,可以将所有人(用户和服务)锁定在项目之外。
我建议您创建一个测试项目并针对该项目开发和调试您的代码。使用对您的其他项目没有权限的凭据。否则使用 CLI 或 Terraform 来最小化风险。
只要您了解 API、IAM 绑定和 JSON 数据结构,API 就非常易于使用。
正如 John 的回答中提到的,您在操作 IAM 模块时应该非常小心,如果出现问题,可能会导致服务完全无法运行。
这是 Google 的文档,其中 manipulates the IAM resources using the REST API.
所有者角色可以授予用户、serviceAccount 或属于组织的组。例如,group@myownpersonaldomain.com 可以作为所有者添加到 myownpersonaldomain.com 组织中的项目,但不能添加到 examplepetstore.com 组织中。
目标:
使用 python,我想在 Google 云平台上的项目中创建一个服务帐户并授予该服务帐户一个角色。
问题:
文档解释 here how to grant a single role to the service account. However, it seems to be only possible by using the Console or the gcloud tool, not with python. The alternative for python is to update the whole IAM policy of the project to grant the role for the single service account and overwrite it (described here)。 但是,覆盖整个策略似乎风险很大,因为如果出现错误,整个项目的策略可能会丢失。 因此我想避免这种情况。
问题:
我正在使用 here in the docs 提供的 python 代码创建服务帐户。是否可以在使用此代码或以任何其他方式创建服务帐户时已经授予角色?
创建服务帐户、创建服务帐户密钥、下载服务帐户 JSON 密钥文件和授予角色是单独的步骤。没有单一的API创建一个服务帐户并同时授予一个角色。
任何时候更新项目的 IAM 绑定都是有风险的。 Google 防止多个应用程序同时更新 IAM。通过在没有成员的情况下覆盖策略,可以将所有人(用户和服务)锁定在项目之外。
我建议您创建一个测试项目并针对该项目开发和调试您的代码。使用对您的其他项目没有权限的凭据。否则使用 CLI 或 Terraform 来最小化风险。
只要您了解 API、IAM 绑定和 JSON 数据结构,API 就非常易于使用。
正如 John 的回答中提到的,您在操作 IAM 模块时应该非常小心,如果出现问题,可能会导致服务完全无法运行。 这是 Google 的文档,其中 manipulates the IAM resources using the REST API.
所有者角色可以授予用户、serviceAccount 或属于组织的组。例如,group@myownpersonaldomain.com 可以作为所有者添加到 myownpersonaldomain.com 组织中的项目,但不能添加到 examplepetstore.com 组织中。