Secret Manager 提供 REST API 和 gRPC API,可直接或在應用程式中使用及管理密鑰。本頁說明如何啟用 Secret Manager API,以及如何設定 Google Cloud 專案,以便首次使用 Secret Manager。
這是 Secret Manager 中所有工作的必要步驟,包括快速入門導覽課程。
熟悉 Secret Manager 後,建議使用獨立的 Google Cloud 專案。刪除專案時,系統也會一併刪除測試期間建立的所有資源,包括可計費資源。
如果您在安裝 Cloud Code 的 IDE 中開發應用程式,Secret Manager 會整合到擴充功能中。也就是說,您不必離開 IDE,就能建立、查看、更新及使用密鑰。如要進一步瞭解如何搭配使用 Secret Manager 與 Cloud Code,請參閱您偏好 IDE 的密鑰管理指南:VS Code、IntelliJ 或 Cloud Shell 編輯器。
事前準備
-
In the Google Cloud console, go to 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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
啟用 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 工作階段中設定專案,請執行
gcloud config set project
Google Cloud 指令。將 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
確認 Secret Manager API 列在已啟用 API 的清單中。
設定角色和權限
如要取得設定 Secret Manager 所需的權限,請要求管理員為您授予專案的 Secret Manager 管理員 (roles/secretmanager.admin
) 身分與存取權管理角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
如要進一步瞭解 Secret Manager 的存取權控管機制,請參閱「使用 IAM 控管存取權」。