根據預設,Eventarc 會加密靜態儲存的客戶內容。Eventarc 會為您處理加密作業,您不必採取其他動作。這個選項稱為「Google 預設加密機制」。
如要控管加密金鑰,您可以在 Cloud KMS 中使用客戶自行管理的加密金鑰 (CMEK),並搭配整合 CMEK 的服務 (包括 Eventarc)。使用 Cloud KMS 金鑰,即可控管金鑰的保護等級、位置、輪替時間表、使用權限和存取權,以及加密範圍。使用 Cloud KMS 還能查看稽核記錄及控管金鑰生命週期。您可以在 Cloud KMS 中控管及管理用於保護資料的對稱金鑰加密金鑰 (KEK),而非由 Google 擁有及管理。
使用 CMEK 設定資源後,存取 Eventarc 資源的體驗與使用 Google 預設加密機制類似。如要進一步瞭解加密選項,請參閱「客戶自行管理的加密金鑰 (CMEK)」。
客戶自行管理的加密金鑰會儲存為軟體金鑰、儲存在 Cloud HSM 叢集內,或使用 Cloud External Key Manager 儲存在外部。
CMEK 保護的內容
您可以設定 CMEK,加密通過下列 Eventarc Advanced 資源的事件訊息:
MessageBus:Eventarc Advanced 匯流排Pipeline:Eventarc Advanced 管道GoogleApiSource:Eventarc Advanced 資源,代表特定匯流排的 Google API 事件訂閱項目
詳情請參閱「Eventarc Advanced 總覽」。
為資源啟用 CMEK 後,系統會使用只有您能存取的加密金鑰,保護該區域中與資源相關聯的資料。
Cloud KMS 和 Eventarc 是區域性服務。Cloud KMS 金鑰和受保護的 Eventarc Advanced 資源必須位於相同區域。
事前準備
在 Eventarc 中使用這項功能前,請務必執行下列操作:
控制台
-
啟用 Cloud KMS 和 Eventarc API (如果尚未啟用)。
啟用 API 所需的角色
如要啟用 API,您必須具備
serviceusage.services.enable權限。如果您建立了專案,可能已透過擁有者角色 (roles/owner) 取得這項權限。否則,您可以透過 Service Usage 管理員角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色。 - 建立金鑰環。
- 為指定金鑰環建立金鑰。
gcloud
- 更新
gcloud元件。gcloud components update
- 為要儲存加密金鑰的專案啟用 Cloud KMS 和 Eventarc API。
gcloud services enable cloudkms.googleapis.com eventarc.googleapis.com
- 建立金鑰環。
- 為指定金鑰環建立金鑰。
如要瞭解所有旗標和可能的值,請執行含有 --help 旗標的指令。
Terraform
設定
google_project_service資源,為要儲存加密金鑰的專案啟用 Cloud KMS 和 Eventarc API:設定
google_kms_key_ring和google_kms_crypto_key資源,建立金鑰環和金鑰。例如:
如要進一步瞭解如何使用 Terraform,請參閱 Terraform on Google Cloud 說明文件。
授予 Eventarc 服務帳戶金鑰存取權
如要將 Cloud KMS 金鑰的存取權授予 Eventarc 服務帳戶,請將服務帳戶新增為金鑰的主體,並授予 Cloud KMS CryptoKey 加密者/解密者角色:
控制台
使用 Google Cloud 控制台為匯流排或管道啟用 CMEK 時,系統會提示您將 Cloud KMS CryptoKey 加密者/解密者角色授予服務帳戶。詳情請參閱本文的「為匯流排啟用 CMEK」或「為管道啟用 CMEK」一節。
gcloud
gcloud kms keys add-iam-policy-binding KEY_NAME \ --keyring KEY_RING \ --location REGION \ --member serviceAccount:SERVICE_AGENT_EMAIL \ --role roles/cloudkms.cryptoKeyEncrypterDecrypter
更改下列內容:
KEY_NAME:金鑰名稱,例如my-keyKEY_RING:金鑰環的名稱,例如my-keyringREGION:金鑰的位置,例如us-central1SERVICE_AGENT_EMAIL:具有eventarc.serviceAgent角色的服務帳戶電子郵件地址例如:
service-PROJECT_NUMBER@gcp-sa-eventarc.iam.gserviceaccount.com。詳情請參閱「服務代理」。
Terraform
設定
google_project_service_identity資源,為 Eventarc 服務產生服務身分:設定
google_kms_crypto_key_iam_member資源,將 Cloud KMS 角色授予 Eventarc 服務帳戶:
請注意,time_sleep 資源會增加延遲時間,以便服務代理和 IAM 權限傳播。
為匯流排啟用 CMEK
為 Eventarc Advanced 匯流排啟用 CMEK 後,所有通過匯流排的訊息都會以該 CMEK 金鑰完整加密。
控制台
在 Google Cloud 控制台中,依序前往「Eventarc」>「Bus」頁面。
您可以建立匯流排,或點選匯流排名稱來更新匯流排。
在「Bus details」(匯流排詳細資料) 頁面中,按一下 「Edit」(編輯)。
在「Edit bus」(編輯匯流排) 頁面的「Encryption」(加密) 部分,選取「Cloud KMS key」(Cloud KMS 金鑰)。
在「Key type」(金鑰類型) 清單中,選取金鑰管理方法。
您可以手動管理金鑰,也可以使用 Autokey 隨選產生金鑰環和金鑰。如果 Autokey 選項停用,表示尚未與目前的資源類型整合。
在「Select a Cloud KMS key」(選取 Cloud KMS 金鑰) 清單中,選取金鑰。
選用:如要手動輸入金鑰的資源名稱,請在「Select a Cloud KMS key」(選取 Cloud KMS 金鑰) 清單中,按一下「Enter key manually」(手動輸入金鑰),然後以指定格式輸入金鑰名稱。
如果出現提示,請將
cloudkms.cryptoKeyEncrypterDecrypter角色授予 Eventarc 服務代理。按一下「儲存」。
gcloud
使用 gcloud eventarc message-buses update 指令,為匯流排啟用 CMEK:
gcloud eventarc message-buses update BUS_NAME \ --location=REGION \ --crypto-key=KEY
更改下列內容:
BUS_NAME:匯流排的 ID 或完整 IDREGION:支援的 Eventarc Advanced 位置KEY:完整 Cloud KMS 金鑰名稱,格式為projects/PROJECT_NAME/locations/REGION/keyRings/RING_NAME/cryptoKeys/KEY_NAME金鑰的
REGION必須與要保護的匯流排位置相符。
Terraform
設定 google_eventarc_message_bus 資源,為匯流排啟用 CMEK。例如:
驗證 Cloud KMS 用量
確認匯流排現在符合 CMEK 規範。
控制台
在 Google Cloud 控制台中,依序前往「Eventarc」>「Bus」頁面。
按一下您使用 CMEK 保護的匯流排名稱。
在「Bus details」(匯流排詳細資料) 頁面中,「Encryption」(加密) 狀態會指出使用中的 CMEK。您可以點選金鑰,在 Security Command Center 中前往該金鑰。
否則,狀態訊息會是
Event messages encrypted using Google-managed encryption keys。
gcloud
使用 gcloud eventarc message-buses describe 指令說明匯流排:
gcloud eventarc message-buses describe BUS_NAME \ --location=REGION
畫面會顯示如下的輸出內容:
cryptoKeyName: projects/PROJECT_ID/locations/REGION/keyRings/RING_NAME/cryptoKeys/KEY_NAME name: projects/PROJECT_ID/locations/REGION/messageBuses/BUS_NAME updateTime: '2022-06-28T17:24:56.365866104Z'
cryptoKeyName 值會顯示用於匯流排的 Cloud KMS 金鑰。
Terraform
如要確認 CMEK 金鑰,可以使用 Terraform state show 指令。
terraform state show google_eventarc_message_bus.default
畫面會顯示如下的輸出內容:
resource "google_eventarc_message_bus" "default" { create_time = "2026-03-02T21:24:11.493277339Z" crypto_key_name = "projects/PROJECT_ID/locations/us-central1/keyRings/adffca5e8fbc2cca-example-keyring/cryptoKeys/example-key" effective_annotations = {} effective_labels = { "goog-terraform-provisioned" = "true" } id = "projects/PROJECT_ID/locations/us-central1/messageBuses/example-bus" location = "us-central1" message_bus_id = "example-bus" name = "projects/PROJECT_ID/locations/us-central1/messageBuses/example-bus" project = "PROJECT_ID" terraform_labels = { "goog-terraform-provisioned" = "true" } uid = "771501be-36ac-4336-93e3-f04604e2523e" update_time = "2026-03-02T21:24:29.933105970Z" logging_config { log_severity = "NONE" } }
停用匯流排的 CMEK
您可以停用與匯流排相關聯的 CMEK 保護機制。透過匯流排傳送的事件仍受 Google-owned and Google-managed encryption keys 保護。
控制台
在 Google Cloud 控制台中,依序前往「Eventarc」>「Bus」頁面。
按一下匯流排名稱。
在「Bus details」(匯流排詳細資料) 頁面中,按一下 「Edit」(編輯)。
在「Edit bus」(編輯匯流排) 頁面的「Encryption」(加密) 部分,選取「Google-managed encryption key」(Google 代管的加密金鑰)。
按一下「儲存」。
gcloud
使用 gcloud eventarc message-buses update 指令停用匯流排的 CMEK:
gcloud eventarc message-buses update BUS_NAME \ --location=REGION \ --clear-crypto-key
Terraform
如要就地更新匯流排,請清除 crypto_key_name 值,且不要在 Terraform 設定檔中指定該值。例如:
# Disable CMEK for an Eventarc Advanced bus
resource "google_eventarc_message_bus" "default" {
location = "us-central1"
message_bus_id = "example-bus"
}
為管道啟用 CMEK
為 Eventarc Advanced 管道啟用 CMEK 後,通過管道的所有訊息都會使用該 CMEK 金鑰完整加密。
控制台
在 Google Cloud 控制台,依序前往「Eventarc」>「Pipelines」頁面。
您可以建立管道,或點選要更新的管道名稱。
在「Pipeline details」(管道詳細資料) 頁面中,按一下 「Edit」(編輯)。
在「Edit pipeline」(編輯管道) 頁面中,選取「Encryption」(加密) 專用的「Cloud KMS key」(Cloud KMS 金鑰)。
在「Key type」(金鑰類型) 清單中,選取金鑰管理方法。
您可以手動管理金鑰,也可以使用 Autokey 隨選產生金鑰環和金鑰。如果 Autokey 選項已停用,表示尚未與目前的資源類型整合。
在「Select a Cloud KMS key」(選取 Cloud KMS 金鑰) 清單中,選取金鑰。
選用:如要手動輸入金鑰的資源名稱,請在「Select a Cloud KMS key」(選取 Cloud KMS 金鑰) 清單中,按一下「Enter key manually」(手動輸入金鑰),然後以指定格式輸入金鑰名稱。
如果出現提示,請將
cloudkms.cryptoKeyEncrypterDecrypter角色授予 Eventarc 服務代理。按一下「儲存」。
gcloud
使用 gcloud eventarc pipelines update 指令,為管道啟用 CMEK:
gcloud eventarc pipelines update PIPELINE_NAME \ --location=REGION \ --crypto-key=KEY
更改下列內容:
PIPELINE_NAME:管道的 ID 或完整 IDREGION:支援的 Eventarc Advanced 位置KEY:完整 Cloud KMS 金鑰名稱,格式為projects/PROJECT_NAME/locations/REGION/keyRings/RING_NAME/cryptoKeys/KEY_NAME金鑰的
REGION必須與要保護的管道位置相符。
Terraform
設定 google_eventarc_pipeline 資源,為管道啟用 CMEK。例如:
驗證 Cloud KMS 用量
確認管道現在符合 CMEK 規範。
控制台
在 Google Cloud 控制台,依序前往「Eventarc」>「Pipelines」頁面。
按一下您使用 CMEK 保護的管道名稱。
在「Pipeline details」(管道詳細資料) 頁面中,「Encryption」(加密) 狀態會指出使用中的客戶自行管理的加密金鑰。您可以點選金鑰,在 Security Command Center 中前往該金鑰。
否則,狀態訊息會是
Event messages encrypted using Google-managed encryption keys。
gcloud
使用 gcloud eventarc pipelines describe 指令,驗證管道的 CMEK:
gcloud eventarc pipelines describe PIPELINE_NAME \ --location=REGION
畫面會顯示如下的輸出內容:
createTime: '2022-06-28T18:05:52.403999904Z' cryptoKeyName: projects/PROJECT_ID/locations/REGION/keyRings/RING_NAME/cryptoKeys/KEY_NAME destinations: ... name: projects/PROJECT_ID/locations/REGION/pipelines/PIPELINE_NAME uid: 5ea277f9-b4b7-4e7f-a8e0-6ca9d7204fa3 updateTime: '2022-06-28T18:09:18.650727516Z'
cryptoKeyName 值會顯示用於管道的 Cloud KMS 金鑰。
Terraform
如要確認 CMEK 金鑰,可以使用 Terraform state show 指令。
terraform state show google_eventarc_pipeline.default
畫面會顯示如下的輸出內容:
resource "google_eventarc_pipeline" "default" { create_time = "2026-03-02T21:24:32.651373287Z" crypto_key_name = "projects/PROJECT_ID/locations/us-central1/keyRings/adffca5e8fbc2cca-example-keyring/cryptoKeys/example-key" effective_annotations = {} effective_labels = { "goog-terraform-provisioned" = "true" } id = "projects/PROJECT_ID/locations/us-central1/pipelines/example-pipeline" location = "us-central1" name = "projects/PROJECT_ID/locations/us-central1/pipelines/example-pipeline" pipeline_id = "example-pipeline" project = "PROJECT_ID" terraform_labels = { "goog-terraform-provisioned" = "true" } uid = "124e444d-55ca-4c99-8529-395bda80c82b" update_time = "2026-03-02T21:28:26.699657974Z" destinations { authentication_config { google_oidc { service_account = "eventarc-advanced-sa@PROJECT_ID.iam.gserviceaccount.com" } } http_endpoint { uri = "https://example-service-hk27nrrura-uc.a.run.app" } } retry_policy { max_attempts = 5 max_retry_delay = "60s" min_retry_delay = "1s" } }
停用管道的 CMEK
您可以停用與管道相關聯的 CMEK 保護機制。透過管道傳送的事件仍受 Google-owned and Google-managed encryption keys 保護。
控制台
在 Google Cloud 控制台,依序前往「Eventarc」>「Pipelines」頁面。
按一下管道名稱。
在「Pipeline details」(管道詳細資料) 頁面中,按一下 「Edit」(編輯)。
在「Edit pipeline」(編輯管道) 頁面的「Encryption」(加密) 部分,選取「Google-managed encryption key」(Google 代管的加密金鑰)。
按一下「儲存」。
gcloud
使用 gcloud eventarc pipelines update 指令停用管道的 CMEK:
gcloud eventarc pipelines update PIPELINE_NAME \ --location=REGION \ --clear-crypto-key
Terraform
您可以清除 crypto_key_name 值,且不在 Terraform 設定檔中指定該值,藉此就地更新管道。例如:
# Disable CMEK for an Eventarc Advanced pipeline
resource "google_eventarc_pipeline" "default" {
location = "us-central1"
pipeline_id = "example-pipeline"
destinations {
http_endpoint {
uri = google_cloud_run_v2_service.default.uri
}
authentication_config {
google_oidc {
service_account = google_service_account.default.email
}
}
}
}
為 Google API 來源啟用 CMEK
為 GoogleApiSource 資源啟用 CMEK 後,系統會使用 CMEK 金鑰,完整加密為該資源收集的所有訊息。
控制台
在 Google Cloud 控制台中,依序前往「Eventarc」>「Bus」頁面。
您可以建立匯流排,或點選匯流排名稱來更新匯流排。
在「Bus details」(匯流排詳細資料) 頁面中,按一下 「Edit」(編輯)。
如要新增訊息來源,請按一下 「Add source」(新增來源)。
如果訊息來源已存在,您必須先刪除該來源,然後新增訊息來源。
在「Add message source」(新增訊息來源) 窗格中,接受 Google API 訊息供應商的預設值
google-api-source。在「Encryption」(加密) 部分,選取「Cloud KMS key」(Cloud KMS 金鑰),然後執行下列操作:
在「Key type」(金鑰類型) 清單中,選取金鑰管理方法。
您可以手動管理金鑰,也可以使用 Autokey 隨選產生金鑰環和金鑰。如果 Autokey 選項已停用,表示尚未與目前的資源類型整合。
在「Select a Cloud KMS key」(選取 Cloud KMS 金鑰) 中,選取金鑰。
必須先選取區域,才能查看客戶自行管理的金鑰。
選用:如要手動輸入金鑰的資源名稱,請在「Select a Cloud KMS key」(選取 Cloud KMS 金鑰) 清單中,按一下「Enter key manually」(手動輸入金鑰),然後以指定格式輸入金鑰名稱。
如果出現提示,請將
cloudkms.cryptoKeyEncrypterDecrypter角色授予 Eventarc 服務代理。
點選「建立」。
這樣一來,系統就會自動收集直接來自 Google 來源的事件,且所有事件訊息都會使用 CMEK 金鑰完整加密。
系統只會發布與
GoogleApiSource位於相同 Google Cloud 專案的資源事件。詳情請參閱「發布 Google 來源的事件」。按一下「儲存」。
gcloud
使用 gcloud eventarc google-api-sources update 指令,為 GoogleApiSource 資源啟用 CMEK:
gcloud eventarc google-api-sources update GOOGLE_API_SOURCE_NAME \ --location=REGION \ --crypto-key=KEY
更改下列內容:
GOOGLE_API_SOURCE_NAME:GoogleApiSource資源的 ID 或完整 IDREGION:支援的 Eventarc Advanced 位置KEY:完整 Cloud KMS 金鑰名稱,格式為projects/PROJECT_NAME/locations/REGION/keyRings/RING_NAME/cryptoKeys/KEY_NAME金鑰的
REGION必須與要保護的資源位置相符。
Terraform
設定 google_eventarc_google_api_source 資源,為 Google API 來源啟用 CMEK。例如:
驗證 Cloud KMS 用量
確認資源現在符合 CMEK 規定。
控制台
在 Google Cloud 控制台中,依序前往「Eventarc」>「Bus」頁面。
按一下匯流排名稱,其訊息來源已使用 Cloud KMS 金鑰保護。
在「Bus details」(匯流排詳細資料) 頁面中,按一下 「Edit」(編輯)。
系統應會列出加密郵件來源的金鑰。您可以點選金鑰,在 Security Command Center 中前往該金鑰。
否則,「Encryption」(加密) 狀態訊息會是
Event messages encrypted using Google-managed encryption keys。
gcloud
使用 gcloud eventarc google-api-sources describe 指令,驗證 GoogleApiSource 資源的 CMEK:
gcloud eventarc google-api-sources describe GOOGLE_API_SOURCE_NAME \ --location=REGION
畫面會顯示如下的輸出內容:
createTime: '2022-06-28T18:05:52.403999904Z' cryptoKeyName: projects/PROJECT_ID/locations/REGION/keyRings/RING_NAME/cryptoKeys/KEY_NAME destination: projects/PROJECT_ID/locations/REGION/messageBuses/BUS_NAME name: projects/PROJECT_ID/locations/REGION/googleApiSources/GOOGLE_API_SOURCE_NAME uid: 5ea277f9-b4b7-4e7f-a8e0-6ca9d7204fa3 updateTime: '2022-06-28T18:09:18.650727516Z'
cryptoKeyName 值會顯示用於資源的 Cloud KMS 金鑰。
Terraform
如要確認 CMEK 金鑰,可以使用 Terraform state show 指令。
terraform state show google_eventarc_google_api_source.default
畫面會顯示如下的輸出內容:
resource "google_eventarc_google_api_source" "default" { create_time = "2026-03-02T21:24:32.019246933Z" crypto_key_name = "projects/PROJECT_ID/locations/us-central1/keyRings/adffca5e8fbc2cca-example-keyring/cryptoKeys/example-key" destination = "projects/PROJECT_ID/locations/us-central1/messageBuses/example-bus" effective_annotations = {} effective_labels = { "goog-terraform-provisioned" = "true" } google_api_source_id = "example-google-api-source" id = "projects/PROJECT_ID/locations/us-central1/googleApiSources/example-google-api-source" location = "us-central1" name = "projects/PROJECT_ID/locations/us-central1/googleApiSources/example-google-api-source" project = "PROJECT_ID" terraform_labels = { "goog-terraform-provisioned" = "true" } uid = "5c79b6e1-8377-48bd-b5d1-61f04ec07e29" update_time = "2026-03-02T21:24:38.051947964Z" logging_config { log_severity = "NONE" } }
停用 Google API 來源的 CMEK
您可以停用與 Google API 來源相關聯的 CMEK 保護機制。透過 GoogleApiSource 資源收集的事件仍受 Google-owned and Google-managed encryption keys 保護。
控制台
在 Google Cloud 控制台中,依序前往「Eventarc」>「Bus」頁面。
按一下匯流排的名稱,其訊息來源已使用 CMEK 保護。
在「Bus details」(匯流排詳細資料) 頁面中,按一下 「Edit」(編輯)。
如要刪除由 Cloud KMS 金鑰加密的訊息來源,請按一下 「Delete resource」(刪除資源)。
視需要重新新增訊息來源。
gcloud
使用 gcloud eventarc google-api-sources update 指令,停用 GoogleApiSource 資源的 CMEK:
gcloud eventarc google-api-sources update GOOGLE_API_SOURCE_NAME \ --location=REGION \ --clear-crypto-key
Terraform
您可以清除 crypto_key_name 值,且不在 Terraform 設定檔中指定該值,藉此就地更新 GoogleApiSource 資源。例如:
# Disable CMEK for Google API sources
resource "google_eventarc_google_api_source" "default" {
location = "us-central1"
google_api_source_id = "example-google-api-source"
destination = google_eventarc_message_bus.default.id
}
套用 CMEK 組織政策
Eventarc 整合了兩項組織政策限制,有助於確保整個組織都使用 CMEK:
constraints/gcp.restrictNonCmekServices用於要求 CMEK 保護。constraints/gcp.restrictCmekCryptoKeyProjects可限制用於 CMEK 保護措施的 Cloud KMS 金鑰。
這項整合功能可讓您為組織中的 Eventarc 資源指定下列加密法規遵循需求:
套用組織政策時的注意事項
套用任何 CMEK 組織政策前,請注意下列事項。
為傳播延遲做好準備
設定或更新組織政策後,新政策最多可能需要 15 分鐘才會生效。
考量現有資源
現有資源不受新建立的組織政策影響。舉例來說,組織政策不會回溯套用至現有管道。即使沒有 CMEK,您仍可存取這些資源,且在適用情況下,這些資源仍會以現有金鑰加密。
確認設定組織政策所需的權限
基於測試目的,可能難以取得設定或更新組織政策的權限。您必須具備組織政策管理員角色,這個角色只能在組織層級授予 (而非專案或資料夾層級)。
雖然必須在組織層級授予角色,但仍可指定僅適用於特定專案或資料夾的政策。
要求新的 Eventarc 資源使用 CMEK
您可以使用 constraints/gcp.restrictNonCmekServices 限制,要求使用 CMEK 保護組織中的新 Eventarc 資源。
設定這項組織政策後,如果建立資源的要求未指定 Cloud KMS 金鑰,就會失敗。
設定這項政策後,只會套用至專案中的新資源。任何未套用 Cloud KMS 金鑰的現有資源仍會存在,且可正常存取。
控制台
前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。
使用「篩選器」搜尋下列限制:
constraints/gcp.restrictNonCmekServices在「Name」(名稱) 欄中,按一下「Restrict which services may create resources without CMEK」(限制哪些服務可以在沒有 CMEK 的情況下建立資源)。
按一下「 Manage Policy」(管理政策)。
在「Edit policy」(編輯政策) 頁面的「Policy source」(政策來源) 下方,選取「Override parent's policy」(覆寫上層政策)。
在「規則」下方,按一下「新增規則」。
在「Policy values」(政策值) 清單中,選取「Custom」(自訂)。
在「Policy type」(政策類型) 清單中,選取「Deny」(拒絕)。
在「Custom values」(自訂值) 欄位中輸入以下內容:
is:eventarc.googleapis.com依序點選「完成」和「設定政策」。
gcloud
建立暫存檔案
/tmp/policy.yaml來儲存政策:name: projects/PROJECT_ID/policies/gcp.restrictNonCmekServices spec: rules: - values: deniedValues: - is:eventarc.googleapis.com
將
PROJECT_ID替換為要套用這項限制的專案 ID。請執行
org-policies set-policy指令。gcloud org-policies set-policy /tmp/policy.yaml
如要確認政策是否成功套用,請嘗試在專案中建立 Eventarc Advanced 管道。除非指定 Cloud KMS 金鑰,否則程序會失敗。
限制 Eventarc 專案的 Cloud KMS 金鑰
您可以使用 constraints/gcp.restrictCmekCryptoKeyProjects 限制,限制可用於保護 Eventarc 專案中資源的 Cloud KMS 金鑰。
舉例來說,您可以指定類似以下的規則:「對於 projects/my-company-data-project 中適用的 Eventarc 資源,這項專案中使用的 Cloud KMS 金鑰必須來自 projects/my-company-central-keys 或 projects/team-specific-keys。」
控制台
前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。
使用「篩選器」搜尋下列限制:
constraints/gcp.restrictCmekCryptoKeyProjects在「Name」(名稱) 欄中,按一下「Restrict which projects may supply KMS CryptoKeys for CMEK」(限制哪些專案可提供 CMEK 的 KMS CryptoKey)。
按一下「 Manage Policy」(管理政策)。
在「Edit policy」(編輯政策) 頁面的「Policy source」(政策來源) 下方,選取「Override parent's policy」(覆寫上層政策)。
在「規則」下方,按一下「新增規則」。
在「Policy values」(政策值) 清單中,選取「Custom」(自訂)。
在「Policy type」(政策類型) 清單中,選取「Allow」(允許)。
在「Custom values」(自訂值) 欄位中輸入以下內容:
under:projects/KMS_PROJECT_ID將
KMS_PROJECT_ID替換為要使用的 Cloud KMS 金鑰所在專案 ID。例如
under:projects/my-kms-project。依序點選「完成」和「設定政策」。
gcloud
建立暫存檔案
/tmp/policy.yaml來儲存政策:name: projects/PROJECT_ID/policies/gcp.restrictCmekCryptoKeyProjects spec: rules: - values: allowedValues: - under:projects/KMS_PROJECT_ID
替換下列內容
PROJECT_ID:要套用這項限制的專案 ID。KMS_PROJECT_ID:要使用的 Cloud KMS 金鑰所在專案的 ID。
請執行
org-policies set-policy指令。gcloud org-policies set-policy /tmp/policy.yaml
如要確認政策是否已成功套用,請嘗試使用其他專案的 Cloud KMS 金鑰,建立 Eventarc Advanced 管道。程序會失敗。
停用及啟用 Cloud KMS 金鑰
金鑰版本會儲存加密編譯金鑰內容,用於加密、解密、簽署及驗證資料。您可以停用這個金鑰版本,這樣一來,就無法存取以該金鑰加密的資料。
如果 Eventarc 無法存取 Cloud KMS 金鑰,事件轉送作業會失敗並顯示 FAILED_PRECONDITION 錯誤,事件傳送作業也會停止。您可以啟用處於「Disabled」(已停用) 狀態的金鑰,以便再次存取加密資料。
停用 Cloud KMS 金鑰
如要防止 Eventarc 使用金鑰加密或解密事件資料,請執行下列任一操作:
- 建議您停用為匯流排或管道設定的金鑰版本。這只會影響與特定金鑰相關聯的 Eventarc Advanced 匯流排或管道。
- 選用:撤銷 Eventarc 服務帳戶的
cloudkms.cryptoKeyEncrypterDecrypter角色。這會影響專案中所有支援 CMEK 加密事件的 Eventarc 資源。
雖然這兩種作業都無法保證能立即撤銷存取權,但 Identity and Access Management (IAM) 變更的傳播速度通常較快。詳情請參閱「Cloud KMS 資源一致性」和「存取權變更傳播」。
重新啟用 Cloud KMS 金鑰
如要繼續傳送及轉送事件,請還原 Cloud KMS 存取權。
稽核記錄和疑難排解
啟用、停用金鑰,或 Eventarc Advanced 資源使用金鑰加密及解密訊息時,Cloud KMS 會產生稽核記錄。詳情請參閱 Cloud KMS 稽核記錄資訊。
如要解決搭配使用 Cloud KMS 與 Eventarc 時可能遇到的問題,請參閱「排解問題」。
如要解決透過 Cloud External Key Manager (Cloud EKM) 使用外部代管金鑰時可能遇到的問題,請參閱「Cloud EKM 錯誤參考資料」。
定價
匯流排整合不會產生額外費用,只有金鑰作業會計入 Google Cloud 專案。如果對管道使用 CMEK,則會根據 Pub/Sub 定價,產生 Cloud KMS 服務的存取費用。
如要進一步瞭解最新定價資訊,請參閱「Cloud KMS 定價」。