本頁面說明如何設定密鑰版本的延遲刪除作業、更新或移除刪除延遲時間長度,以及還原排定刪除的密鑰版本。
根據預設,使用者在 Secret Manager 中選擇刪除密鑰版本時,系統會立即永久刪除密鑰內容。不過,具備 Secret Manager 管理員角色的使用者可以設定延遲刪除密鑰版本,確保系統不會在收到要求後立即刪除密鑰版本,且在可設定的期間內仍可復原。
如果密鑰已啟用延遲刪除功能,且您刪除密鑰版本,系統會執行下列操作:
-
該版本已停用,因此無法使用。
-
系統會在延遲期結束時,安排永久刪除該版本。
-
延遲期限過後,密鑰版本就會永久刪除,無法復原。
優點
這項功能可帶來下列好處:
-
多一層保護,防止重要密鑰內容意外或惡意遭到破壞。具備「Secret Manager Secret Version Manager」角色的使用者可以銷毀密鑰版本。這項操作無法復原。設定延遲刪除,即可避免立即刪除密鑰版本。您可以授予使用者管理密碼版本生命週期的最低必要存取權,以便監控及防止機密資料遭到意外毀損。
-
銷毀密鑰版本會觸發
SECRET_VERSION_DESTROY_SCHEDULED通知 ,傳送至密鑰上設定的 Pub/Sub 主題。具備 Secret Manager 管理員角色的使用者可以啟用或停用密鑰版本,取消排定的刪除作業並還原密鑰版本。
事前準備
-
如果尚未啟用 Secret Manager API,請啟用。
啟用 API 時所需的角色
如要啟用 API,您必須具備
serviceusage.services.enable權限。如果您建立了專案,可能已透過「擁有者」角色 (roles/owner) 取得這項權限。否則,您可以透過「服務使用管理員」角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色。 -
設定驗證方法。
選取這個頁面上範例的預計用途分頁:
控制台
使用 Cloud de Confiance 控制台存取 Cloud de Confiance by S3NS 服務和 API 時,不需要設定驗證。
gcloud
安裝 Google Cloud CLI,然後 使用聯合身分登入 gcloud CLI。登入後,執行下列指令來初始化 Google Cloud CLI:
gcloud initREST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用聯合身分登入 gcloud CLI。
詳情請參閱 Cloud de Confiance 驗證說明文件中的「使用 REST 進行驗證」一節。
必要的角色
如要取得設定延後銷毀密碼版本所需的權限,請要求管理員授予您密碼的「Secret Manager 管理員 」(roles/secretmanager.admin) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
設定延遲刪除
建立或更新密鑰時,您可以啟用密鑰版本延遲刪除功能。如要設定延遲銷毀,請使用下列其中一種方法:
控制台
-
前往 Cloud de Confiance 控制台的「Secret Manager」頁面。
-
在「Secret Manager」頁面中,按一下「Regional secrets」(區域密鑰) 分頁標籤,然後點選「Create regional secret」(建立區域密鑰)。
-
在「建立區域密鑰」頁面的「名稱」欄位中,輸入密鑰名稱。
-
輸入密鑰值 (例如
abcd1234)。您也可以使用「上傳檔案」選項,上傳含有密鑰值的文字檔。這項操作會自動建立密鑰版本。 -
從「Region」(區域) 清單中,選擇要儲存區域密鑰的位置。
-
前往「延遲刪除密鑰版本」部分,然後選取「設定延遲刪除的時長」核取方塊。
-
在「銷毀延遲時間長度」欄位中,輸入延遲時間長度 (以天為單位)。可輸入的最小值為 1 天,最大值為 1000 天。
-
點選「建立密鑰」。
gcloud
使用下列任何指令資料前,請先替換以下項目:
- SECRET_ID:密鑰 ID。
- LOCATION:密鑰的 Cloud de Confiance by S3NS 位置。
- TTL_DURATION:密鑰版本的刪除延遲時長。你可以輸入任何格式的持續時間,例如天數、小時或秒數。最短時間為 1 天,最長可設為 1000 天。
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud secrets create SECRET_ID --location=LOCATION --version-destroy-ttl=TTL_DURATION
Windows (PowerShell)
gcloud secrets create SECRET_ID --location=LOCATION --version-destroy-ttl=TTL_DURATION
Windows (cmd.exe)
gcloud secrets create SECRET_ID --location=LOCATION --version-destroy-ttl=TTL_DURATION
回應中會包含新建立的密鑰。
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:密鑰的 Cloud de Confiance by S3NS 位置。
- PROJECT_ID: Cloud de Confiance by S3NS 專案 ID。
- SECRET_ID:密鑰 ID。
- TTL_DURATION:密鑰版本的刪除延遲時間長度。輸入時間長度 (以秒為單位)。請注意,最短期限為 1 天,最長期限則可設為 1,000 天。
HTTP 方法和網址:
POST https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets?secretId=SECRET_ID
JSON 要求內文:
{
"version_destroy_ttl":"TTL_DURATION"
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-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?secretId=SECRET_ID"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-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?secretId=SECRET_ID" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID",
"createTime": "2024-09-04T06:34:32.995517Z",
"etag": "\"1621455df3febd\"",
"versionDestroyTtl": "TTL_DURATION"
}
延遲刪除不適用於下列情況:
-
刪除密鑰後,系統會立即刪除所有密鑰資料和相關密鑰版本。
-
如果密鑰設有到期日,且密鑰已過期,即使密鑰已啟用延遲刪除功能,所有密鑰版本仍會立即刪除。
更新刪除延遲時長
如要更新銷毀延遲時間長度,請使用下列其中一種方法:
控制台
-
前往 Cloud de Confiance 控制台的「Secret Manager」頁面。
-
在「Secret Manager」頁面中,按一下「Regional secrets」分頁標籤。
-
如要編輯密鑰,請使用下列其中一種方法:
-
按一下要編輯的密鑰「動作」,然後按一下「編輯」。
-
按一下密鑰名稱,前往密鑰詳細資料頁面。在密鑰詳細資料頁面中,按一下「編輯密鑰」。
-
-
在「Edit secret」(編輯密鑰) 頁面,前往「Delay secret version destroy」(延遲刪除密鑰版本) 區段。 視需要更新延遲時間,然後按一下「更新密鑰」。
gcloud
使用下列任何指令資料前,請先替換以下項目:
- SECRET_ID:密鑰 ID
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
- TTL_DURATION:密鑰版本的刪除延遲時長
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud secrets update SECRET_ID --location=LOCATION --version-destroy-ttl=TTL_DURATION
Windows (PowerShell)
gcloud secrets update SECRET_ID --location=LOCATION --version-destroy-ttl=TTL_DURATION
Windows (cmd.exe)
gcloud secrets update SECRET_ID --location=LOCATION --version-destroy-ttl=TTL_DURATION
回應會包含新建立的密鑰。
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
- PROJECT_ID: Cloud de Confiance by S3NS 專案 ID
- SECRET_ID:密鑰 ID
- TTL_DURATION:密鑰版本的刪除延遲時長
HTTP 方法和網址:
PATCH https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID?updateMask=version_destroy_ttl
JSON 要求內文:
{
"version_destroy_ttl":"TTL_DURATION"
}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X PATCH \
-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?updateMask=version_destroy_ttl"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-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?updateMask=version_destroy_ttl" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID",
"createTime": "2024-09-04T06:34:32.995517Z",
"etag": "\"16214561a80d09\"",
"versionDestroyTtl": "TTL_DURATION"
}
受延遲刪除時間影響的密鑰版本取決於下列因素:
-
首次為密鑰設定延遲刪除功能時,刪除延遲時間會影響密鑰的所有有效版本 (已啟用和已停用)。
-
更新或移除刪除延遲時間後,只有在嘗試刪除新版密鑰時,才會反映相關變更。已排定刪除的密鑰版本仍會在排定時間刪除。
停用延遲刪除
如要停用延遲刪除版本功能,請使用下列其中一種方法:
控制台
-
前往 Cloud de Confiance 控制台的「Secret Manager」頁面。
-
在「Secret Manager」頁面中,按一下「Regional secrets」分頁標籤。
-
如要編輯密鑰,請使用下列其中一種方法:
-
按一下要編輯的密鑰「動作」,然後按一下「編輯」。
-
按一下密鑰名稱,前往密鑰詳細資料頁面。在密鑰詳細資料頁面中,按一下「編輯密鑰」。
-
-
在「Edit secret」(編輯密鑰) 頁面中,前往「Delay secret version destroy」(延遲刪除密鑰版本) 區段。 取消勾選「Set duration for delayed destruction」(設定延遲刪除時長) 核取方塊,然後按一下「Update secret」(更新密鑰)。
gcloud
使用下列任何指令資料之前,請先替換以下項目:
- SECRET_ID:密鑰 ID
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud secrets update SECRET_ID --location=LOCATION --remove-version-destroy-ttl
Windows (PowerShell)
gcloud secrets update SECRET_ID --location=LOCATION --remove-version-destroy-ttl
Windows (cmd.exe)
gcloud secrets update SECRET_ID --location=LOCATION --remove-version-destroy-ttl
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
- PROJECT_ID: Cloud de Confiance by S3NS 專案 ID
- SECRET_ID:Secret 的 ID
HTTP 方法和網址:
PATCH https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID?updateMask=version_destroy_ttl
JSON 要求內文:
{}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X PATCH \
-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?updateMask=version_destroy_ttl"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-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?updateMask=version_destroy_ttl" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID",
"createTime": "2024-09-04T06:34:32.995517Z",
"etag": "\"16214564f18f19\""
}
排定延遲刪除密鑰版本
如要排定延遲刪除密鑰版本,請使用下列其中一種方法:
控制台
-
前往 Cloud de Confiance 控制台的「Secret Manager」頁面。
-
在「Secret Manager」頁面中,按一下「Regional secrets」分頁標籤,然後按一下密鑰存取其版本。必須為這組密鑰設定延遲刪除版本。
-
在密鑰詳細資料頁面的「版本」分頁中,選取要銷毀的密鑰版本。
-
按一下「動作」,然後按一下「銷毀」。
-
在顯示的確認對話方塊中,輸入密鑰 ID 進行確認,然後按一下「Schedule selected versions for destruction」(安排刪除所選版本)。
gcloud
使用下列任何指令資料之前,請先替換以下項目:
- SECRET_VERSION_ID:版本 ID 或完整 ID
- SECRET_ID:密鑰 ID
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud secrets versions destroy SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
Windows (PowerShell)
gcloud secrets versions destroy SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
Windows (cmd.exe)
gcloud secrets versions destroy SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
- PROJECT_ID: Cloud de Confiance by S3NS 專案 ID
- SECRET_ID:密鑰 ID
- VERSION_ID:版本 ID 或完整 ID
HTTP 方法和網址:
POST https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID/versions/VERSION_ID:destroy
JSON 要求內文:
{}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-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/versions/VERSION_ID:destroy"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-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/versions/VERSION_ID:destroy" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_ID/secrets/SECRET_ID/versions/VERSION_ID",
"createTime": "2024-09-04T06:41:57.859674Z",
"state": "DISABLED",
"etag": "\"16214579184a2c\"",
"scheduledDestroyTime": "2024-09-05T13:15:28.357251843Z"
}
密鑰版本會立即停用,並在延遲刪除時間過後刪除。您可以在「版本」表格的「預計刪除時間」欄下方,查看版本確切的刪除日期和時間。
還原 Secret 版本
如要還原已排定刪除的密鑰版本,請啟用或停用該版本。
啟用已排定刪除的密鑰版本
如要啟用排定刪除的密鑰版本,請使用下列任一方法:
控制台
-
前往 Cloud de Confiance 控制台的「Secret Manager」頁面。
-
在「Secret Manager」頁面中,按一下「Regional secrets」分頁標籤,然後按一下密鑰即可存取其版本。
-
在密鑰詳細資料頁面的「版本」分頁中,選取預計要銷毀的密鑰版本。
-
按一下「動作」,然後按一下「啟用」。
-
在隨即顯示的確認對話方塊中,按一下「啟用所選版本」。
gcloud
使用下列任何指令資料前,請先替換以下項目:
- SECRET_VERSION_ID:版本 ID 或完整 ID
- SECRET_ID:Secret 的 ID
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud secrets versions enable SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
Windows (PowerShell)
gcloud secrets versions enable SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
Windows (cmd.exe)
gcloud secrets versions enable SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
- PROJECT_ID: Cloud de Confiance by S3NS 專案 ID
- SECRET_ID:密鑰 ID
- VERSION_ID:版本 ID 或完整 ID
HTTP 方法和網址:
POST https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID/versions/VERSION_ID:enable
JSON 要求內文:
{}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-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/versions/VERSION_ID:enable"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-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/versions/VERSION_ID:enable" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_ID/secrets/SECRET_ID/versions/VERSION_ID",
"createTime": "2024-09-04T06:41:57.859674Z",
"state": "ENABLED",
"etag": "\"1621457b3c1459\""
}
停用已排定刪除作業的密鑰版本
如要停用排定刪除的密鑰版本,請使用下列任一方法:
控制台
-
前往 Cloud de Confiance 控制台的「Secret Manager」頁面。
-
在「Secret Manager」頁面中,按一下「Regional secrets」分頁標籤,然後按一下密鑰即可存取其版本。
-
在密鑰詳細資料頁面的「版本」分頁中,選取預計要銷毀的密鑰版本。
-
依序點選 「Actions」(動作) 和「Disable」(停用)。
-
在隨即顯示的確認對話方塊中,按一下「停用所選版本」。
gcloud
使用下列任何指令資料前,請先替換以下項目:
- SECRET_VERSION_ID:版本 ID 或完整 ID
- SECRET_ID:密鑰 ID
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
執行下列指令:
Linux、macOS 或 Cloud Shell
gcloud secrets versions disable SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
Windows (PowerShell)
gcloud secrets versions disable SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
Windows (cmd.exe)
gcloud secrets versions disable SECRET_VERSION_ID --secret=SECRET_ID --location=LOCATION
回應中包含已停用的密鑰版本。
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION:Secret 的 Cloud de Confiance by S3NS 位置
- PROJECT_ID: Cloud de Confiance by S3NS 專案 ID
- SECRET_ID:密鑰 ID
- VERSION_ID:版本 ID 或完整 ID
HTTP 方法和網址:
POST https://secretmanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/secrets/SECRET_ID/versions/VERSION_ID:disable
JSON 要求內文:
{}
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
curl -X POST \
-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/versions/VERSION_ID:disable"
PowerShell
將要求主體儲存在名為 request.json 的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-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/versions/VERSION_ID:disable" | Select-Object -Expand Content
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_ID/secrets/SECRET_ID/versions/VERSION_ID",
"createTime": "2024-09-04T06:41:57.859674Z",
"state": "DISABLED",
"etag": "\"1621457b3c1459\""
}