本主题介绍如何管理对 Cloud KMS 资源的访问权限。
概览
要管理对 Cloud KMS 资源(例如密钥和密钥环)的访问权限,您需要授予 Identity and Access Management (IAM) 角色。您可以授予或限制执行特定加密操作的权限,例如轮替密钥或加密数据。您可以针对以下资源授予 IAM 角色:
- 密钥
- 密钥环,由密钥环中的所有密钥继承
- Google Cloud 项目,由项目中的所有密钥继承
- 一个 Google Cloud 文件夹,由文件夹中所有项目中的所有密钥继承
- 组织,由组织中文件夹中的所有密钥继承 Google Cloud
如需查看 Cloud KMS 操作以及 IAM 角色和权限的完整列表,请参阅 权限和角色。如需查看 Cloud KMS 资源的完整列表以及这些资源之间的关系,请参阅 Cloud KMS 资源。
准备工作
如需完成这些任务,您需要具备管理项目 Google Cloud 中的 Cloud KMS
资源的权限。Cloud KMS Admin 角色
(roles/cloudkms.admin) 包含所需的权限。
- 登录您的 Google Cloud 账号。如果您是新手 Google Cloud, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
安装 Google Cloud CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init - 创建资源,例如密钥环。
- 获取所创建资源的资源 ID,例如密钥环、密钥和密钥版本。
只有具有 Owner (roles/owner) 或 Cloud KMS Admin (roles/cloudkms.admin) 角色的 IAM
主账号才能授予或撤消对 Cloud KMS 资源的访问权限。
针对资源授予角色
以下示例授予一个角色,该角色提供对 Cloud KMS 密钥的访问权限:
gcloud
如需在命令行上使用 Cloud KMS,请先 安装或升级到最新版本的 Google Cloud CLI。
gcloud kms keys add-iam-policy-binding key \
--keyring key-ring \
--location location \
--member principal-type:principal-email \
--role roles/role
将 key 替换为密钥的名称。将 key-ring 替换为密钥所在的密钥环的名称。将 location 替换为密钥环的 Cloud KMS 位置。 将 principal-type 和 principal-email 替换为主账号的类型 和主账号的电子邮件地址。将 role 替换为要添加的角色的名称。
C#
要运行此代码,请先设置 C# 开发环境并 安装 Cloud KMS C# SDK。
Go
要运行此代码,请先设置 Go 开发环境并 安装 Cloud KMS Go SDK。
Java
要运行此代码,请先设置 Java 开发环境并 安装 Cloud KMS Java SDK。