本頁說明如何刪除密鑰及其所有版本。
如要只刪除密鑰版本,請參閱刪除區域密鑰版本。
必要的角色
如要取得刪除密碼所需的權限,請要求管理員授予您密碼、專案、資料夾或機構的 Secret Manager 管理員 (roles/secretmanager.admin
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
刪除密鑰
如要刪除密鑰,請使用下列其中一種方法:
控制台
-
前往 Google Cloud 控制台的「Secret Manager」頁面。
-
在「Secret Manager」頁面中,按一下「區域性密鑰」分頁標籤。
-
選取要刪除的密鑰。
-
按一下「動作」
,然後按一下「刪除」。 -
在隨即顯示的確認對話方塊中輸入密鑰名稱,然後按一下「刪除密鑰」。
gcloud
請確認您已設定 Secret Manager 使用區域端點,以便管理區域密鑰。使用下方的任何指令資料之前,請先替換以下項目:
- SECRET_ID:密鑰的 ID 或密鑰的完整 ID
- LOCATION:密鑰的 Google Cloud 位置
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud secrets delete SECRET_ID \ --location=LOCATION
Windows (PowerShell)
gcloud secrets delete SECRET_ID ` --location=LOCATION
Windows (cmd.exe)
gcloud secrets delete SECRET_ID ^ --location=LOCATION
回應會傳回密鑰。
REST
使用任何要求資料之前,請先替換以下項目:
- LOCATION:密鑰的 Google Cloud 位置
- PROJECT_ID:專案 ID Google Cloud
- SECRET_ID:密鑰的 ID 或密鑰的完整 ID
HTTP 方法和網址:
DELETE https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID
JSON 要求主體:
{}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{}
Go
如要執行這段程式碼,請先設定 Go 開發環境,並安裝 Secret Manager Go SDK。在 Compute Engine 或 GKE 上,您必須使用 cloud-platform 範圍進行驗證。
Java
如要執行這段程式碼,請先設定 Java 開發環境,並安裝 Secret Manager Java SDK。在 Compute Engine 或 GKE 上,您必須使用 cloud-platform 範圍進行驗證。
Node.js
如要執行這段程式碼,請先設定 Node.js 開發環境,並安裝 Secret Manager Node.js SDK。在 Compute Engine 或 GKE 上,您必須使用 cloud-platform 範圍進行驗證。
Python
如要執行這段程式碼,請先設定 Python 開發環境,然後安裝 Secret Manager Python SDK。在 Compute Engine 或 GKE 上,您必須使用 cloud-platform 範圍進行驗證。