Secret Manager 提供 REST API 和 gRPC API 以用于直接在应用中使用或管理密文。本页介绍了首次使用 Secret Manager 时如何启用 Secret Manager API 并配置项目。 Google Cloud
此步骤是 Secret Manager 中所有任务的前提条件,包括快速入门。
当您熟悉 Secret Manager 后,建议使用单独的 Google Cloud 项目。删除项目时,也会删除测试期间创建的所有资源,包括收费资源。
如果您是在安装了 Cloud Code 的 IDE 中开发应用,则 Secret Manager 已集成到该扩展程序中。这意味着,您无需离开 IDE 即可创建、查看、更新和使用 Secret。如需详细了解如何将 Secret Manager 与 Cloud Code 搭配使用,请参阅适用于您偏好的 IDE(VS Code、IntelliJ 或 Cloud Shell Editor)的密钥管理指南。
准备工作
-
In the Google Cloud console, go to the project selector page.
-
Select or create a Google Cloud project.
启用 Secret Manager API
控制台
在 Google Cloud 控制台中,前往 Secret Manager API 页面。
验证项目名称是否显示在页面顶部的项目选择器中。
如果您没有看到项目名称,请点击项目选择器,然后选择您的项目。
- 点击启用。
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
- 如需在 gcloud 会话中设置 Google Cloud 项目,请运行
gcloud config set project
命令。将 PROJECT_ID 替换为您的 Google Cloud 项目 ID。gcloud config set project PROJECT_ID
- 如需启用 Secret Manager API,请运行
gcloud services enable
命令:gcloud services enable secretmanager.googleapis.com
- 如需验证 Secret Manager API 是否已启用,请运行
gcloud services list
命令:gcloud services list --enabled
验证已启用的 API 列表中是否列出了 Secret Manager API。
配置角色和权限
如需获得设置 Secret Manager 所需的权限,请让您的管理员向您授予项目的 Secret Manager Admin (roles/secretmanager.admin
) IAM 角色。
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
如需详细了解 Secret Manager 的访问权限控制,请参阅使用 IAM 进行访问权限控制。
后续步骤
- 详细了解如何对 Secret Manager API 进行身份验证和访问。
- 详细了解如何创建密文。
- 详细了解如何添加 Secret 版本。