Data Manager API 支援使用下列金鑰管理服務加密資料:
部分用途的支援程度會因金鑰管理服務 (KMS) 而異:
| 類別 | 用途 | Google Cloud KMS | AWS KMS |
|---|---|---|---|
| 目標對象 | 傳送目標對象成員 | ||
| 事件 | 離線轉換或待開發客戶強化轉換 | ||
| 事件 | 傳送至 Google Ads 目的地做為額外資料來源的事件 | ||
| 事件 | 傳送至 Google Analytics 目的地的事件,做為額外資料來源 |
設定 Google Cloud KMS
以下是設定 Google Cloud KMS 資源以進行加密的步驟。
設定 Google Cloud 指令列介面
安裝並初始化 Google Cloud 指令列介面。
如要選取或建立新的 Google Cloud 專案,並啟用 Cloud Key Management Service,請按一下「啟用 Cloud KMS」。
啟用 Cloud KMS如要在環境中設定專案,請使用
gcloud config set指令。如要檢查專案是否已在環境中設定,請執行gcloud config list。如果未設定
project,或想為金鑰使用其他專案,請執行gcloud config set:gcloud config set project PROJECT_ID
建立金鑰
詳情請參閱 Cloud Key Management Service 總覽。
建立金鑰環。
gcloud kms keyrings create KEY_RING_NAME \ --location KEY_RING_LOCATION詳情請參閱建立金鑰環。
在金鑰環中建立金鑰。ROTATION_PERIOD 表示金鑰輪替間隔,NEXT_ROTATION_TIME 則表示首次輪替的日期和時間。
舉例來說,如要每 30 天輪替金鑰一次,並在 1 週內執行第一次輪替,請將 ROTATION_PERIOD 設為
30d,並將 NEXT_ROTATION_TIME 設為$(date --utc --date="next week" --iso-8601=seconds)。gcloud kms keys create KEY_NAME \ --keyring KEY_RING_NAME \ --location KEY_RING_LOCATION \ --purpose "encryption" \ --rotation-period ROTATION_PERIOD \ --next-rotation-time "NEXT_ROTATION_TIME"詳情請參閱「建立金鑰」一文。
建立 workload identity pool 提供者
本節簡要介紹 Workload Identity Federation。詳情請參閱「Workload Identity Federation」。
建立 workload identity pool (WIP)。集區的
location必須為global。gcloud iam workload-identity-pools create WIP_ID \ --location=global \ --display-name="WIP_DISPLAY_NAME" \ --description="WIP_DESCRIPTION"詳情請參閱「管理 workload identity pool 和提供者」。
建立 workload identity pool 提供者。
--attribute-condition引數會驗證呼叫者是否為機密比對服務帳戶。gcloud iam workload-identity-pools providers create-oidc PROVIDER_ID \ --location=global \ --workload-identity-pool=WIP_ID \ --display-name="PROVIDER_DISPLAY_NAME" \ --description="PROVIDER_DESCRIPTION" \ --attribute-mapping="google.subject=assertion.sub,google.groups=[\"PROVIDER_ID\"]" \ --attribute-condition="assertion.swname == 'CONFIDENTIAL_SPACE' && 'STABLE' in assertion.submods.confidential_space.support_attributes && ['cfm-services@admcloud-cfm-services.iam.gserviceaccount.com'].exists( a, a in assertion.google_service_accounts) && 'ECDSA_P256_SHA256:6b1f357b59e9407fb017ca0e3e783b2bd5acbfea6c83dd82971a4150df5b25f9' in assertion.submods.container.image_signatures.map(sig, sig.signature_algorithm+':'+sig.key_id)" \ --issuer-uri="https://confidentialcomputing.googleapis.com" \ --allowed-audiences="https://sts.googleapis.com"將金鑰解密者角色授予 WIP 提供者。
# Grants the role to the WIP provider. gcloud kms keys add-iam-policy-binding KEY_NAME \ --keyring KEY_RING_NAME \ --location KEY_RING_LOCATION \ --member "principalSet://iam.googleapis.com/projects/PROJECT_ID/locations/global/workloadIdentityPools/WIP_ID/group/PROVIDER_ID" \ --role "roles/cloudkms.cryptoKeyDecrypter"如要加密離線轉換和待開發客戶強化轉換的事件資料,請將金鑰解密者角色授予 Google 服務帳戶
datamanager-api@datamanager-ga.iam.gserviceaccount.com。# Grants the role to the Google service account. gcloud kms keys add-iam-policy-binding KEY_NAME \ --keyring KEY_RING_NAME \ --location KEY_RING_LOCATION \ --member "serviceAccount:datamanager-api@datamanager-ga.iam.gserviceaccount.com" \ --role "roles/cloudkms.cryptoKeyDecrypter"
設定 AWS KMS
以下是設定 AWS KMS 資源以進行加密的步驟。
設定 AWS 指令列介面
- 安裝 AWS 指令列介面。
執行下列指令來驗證安裝作業:
aws --version以下是安裝成功時的輸出內容片段:
aws-cli/2.31.12 Python/3.13.7 ...
設定 AWS 使用者並登入
- 完成使用 AWS 指令列介面的先決條件。
- 登入 IAM Identity Center 工作階段。
建立金鑰
-
aws kms create-key \ --key-usage ENCRYPT_DECRYPT \ --key-spec SYMMETRIC_DEFAULT \ --description "KEK for Confidential Matching Data Encryption"請注意輸出內容中
KeyMetadata下方的Arn。您會在其他步驟中用到這個 Amazon 資源名稱 (ARN)。AWS_KEY_ARN 選用:使用您選擇的別名名稱建立金鑰別名。
aws kms create-alias \ --alias-name "alias/AWS_KEY_ALIAS" \ --target-key-id AWS_KEY_ARN別名並非必要,但有助於建構 AWS Command Line Interface 指令。舉例來說,您可以使用別名擷取金鑰 ARN:
aws kms describe-key --key-id "alias/AWS_KEY_ALIAS" \ --query 'KeyMetadata.Arn' \ --output text
建立 OpenID Connect 識別資訊提供者
建立 OpenID Connect (OIDC) 識別資訊提供者。每個 AWS 帳戶只需要執行一次這個步驟。
aws iam create-open-id-connect-provider \
--url https://confidentialcomputing.googleapis.com \
--client-id-list AUDIENCE \
--thumbprint-list "08745487e891c19e3078c1f2a07e452950ef36f6"
請記下輸出內容中的 OIDC 供應商 ARN。後續步驟會用到這項資訊。
AWS_OIDC_PROVIDER_ARN
建立 IAM 政策
建立名為
kms-decrypt-policy.json的 JSON 檔案,並在當中加入下列內容:{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "kms:Decrypt", "Resource": "AWS_KEY_ARN" } ] }使用 JSON 檔案和您選擇的政策名稱建立 IAM 政策。
aws iam create-policy \ --policy-name "AWS_POLICY_NAME" \ --policy-document file://kms-decrypt-policy.json請注意輸出內容中的 IAM 政策 ARN。後續步驟會用到這項資訊。
AWS_IAM_POLICY_ARN
建立及附加 IAM 角色
建立名為
role-trust-policy.json的 JSON 檔案,並在當中加入下列內容和先前步驟中的 OIDC 供應商 ARN:{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "AWS_OIDC_PROVIDER_ARN" }, "Action": [ "sts:AssumeRoleWithWebIdentity", "sts:TagSession" ], "Condition": { "StringEquals": { "confidentialcomputing.googleapis.com:aud": "cfm-awsresource", "aws:RequestTag/swname": "CONFIDENTIAL_SPACE", "aws:RequestTag/container.signatures.key_ids": "6b1f357b59e9407fb017ca0e3e783b2bd5acbfea6c83dd82971a4150df5b25f9" }, "StringLike": { "aws:RequestTag/confidential_space.support_attributes": "*STABLE*" } } } ] }建立 IAM 角色,並選擇角色名稱。
aws iam create-role \ --role-name "AWS_IAM_ROLE_NAME" \ --assume-role-policy-document file://role-trust-policy.json將角色政策附加至 IAM 政策。
aws iam attach-role-policy \ --role-name "AWS_IAM_ROLE_NAME" \ --policy-arn "AWS_IAM_POLICY_ARN"
加密資料
Data Manager API 中的加密作業需要資料加密金鑰 (DEK)。DEK 是用來加密資料的對稱金鑰。您的 DEK 會使用 Google Cloud 或 AWS KMS 金鑰加密。您會在要求中傳送加密的 DEK。
如要準備要求中的資料以進行加密,請遵循與未加密資料相同的格式和雜湊處理規範。
請勿加密未經過雜湊處理的值。例如 AddressInfo 的 region_code 或 postal_code。
為每個欄位設定資料格式並雜湊處理後,請按照下列步驟加密雜湊值:
- 使用 Base64 編碼方式編碼雜湊位元組。
- 使用 DEK 加密 Base64 編碼的雜湊。
- 使用十六進位或 Base64 編碼,為加密程序的輸出內容編碼。
- 使用欄位的編碼值。
- 在要求中設定
encryption_info和encoding。
如要完成最後一個步驟,請修改 IngestAudienceMembersRequest 或 IngestEventsRequest,指出您已加密資料:
- 設定
encryption_info欄位。 - 將
encoding欄位設為用於編碼加密欄位值的編碼。
以下是使用 Google Cloud KMS 金鑰,並設定加密和編碼欄位的要求程式碼片段:
{
...
"encryptionInfo": {
"gcpWrappedKeyInfo": {
"kekUri": "gcp-kms://projects/PROJECT_ID/locations/KEY_RING_LOCATION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME",
"wipProvider": "projects/PROJECT_ID/locations/global/workloadIdentityPools/WIP_ID/providers/PROVIDER_ID",
"keyType": "XCHACHA20_POLY1305",
"encryptedDek": "ENCRYPTED_DEK"
}
},
"encoding": "ENCODING"
}
如要使用 Data Manager API 程式庫和公用程式建構及傳送要求,請參閱 Java 的 IngestAudienceMembersWithEncryption 程式碼範例或 Python 的 ingest_audience_members_with_encryption 程式碼範例。