下面介绍了如何发送加密数据。
设置 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"如需了解详情,请参阅创建密钥。
创建工作负载身份池提供方
本部分简要介绍了工作负载身份联合。如需了解详情,请参阅工作负载身份联合。
创建工作负载身份池 (WIP)。池的
location必须为global。gcloud iam workload-identity-pools create WIP_ID \ --location=global \ --display-name="WIP_DISPLAY_NAME" \ --description="WIP_DESCRIPTION"如需了解详情,请参阅管理工作负载身份池和提供方。
创建工作负载身份池提供方。
--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"
加密数据
在 Data Manager API 中进行加密需要数据加密密钥 (DEK)。DEK 是一种对称密钥,可用于加密数据。您的 DEK 使用 Google Cloud KMS 密钥进行加密。您可以在请求中发送加密的 DEK。
如需准备请求中的数据以进行加密,请遵循与未加密数据相同的格式设置和哈希处理准则。
请勿加密未哈希处理的值。例如,AddressInfo 的 region_code 或 postal_code。
对每个字段的数据进行格式设置和哈希处理后,请按照以下步骤对哈希处理后的值进行加密:
- 使用 Base64 编码对哈希字节进行编码。
- 使用您的 DEK 对经过 Base64 编码的哈希进行加密。
- 使用十六进制或 Base64 编码对加密过程的输出进行编码。
- 使用相应字段的编码值。
- 在请求中设置
encryption_info和encoding。
若要完成最后一步,请修改 IngestAudienceMembersRequest 或 IngestEventsRequest,以表明您已加密数据:
- 设置
encryption_info字段。 - 将
encoding字段设置为用于对加密字段值进行编码的编码。
以下代码段展示了设置了加密和编码字段的请求:
{
...
"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 库和实用程序来构建和发送请求,请参阅 IngestAudienceMembersWithEncryption Java 代码示例或 ingest_audience_members_with_encryption Python 代码示例。