我正在做一个 PII 去识别项目并使用谷歌云的数据丢失防护 api。
用例:使用云 KMS 密钥加密字段。
- 创建了一个 dlp-deidentification 模板,这里是片段:
{
"deidentify_template":{
"display_name":"deidentification_encryption",
"description":"deidentification_encryption",
"deidentify_config":{
"record_transformations":{
"field_transformations":[
{
"fields":[
{
"name":"password"
}
],
"primitive_transformation":{
"crypto_hash_config": {
"crypto_key": {
"kms_wrapped": {
"wrapped_key": "[base64 encoded]",
"crypto_key_name": "kms-key-resource-name"
}
}
}
}
将模板保存为 JSON 文件。
当我尝试使用 构建模板
python Api
时,出现以下错误:
TypeError: Cannot set google.privacy.dlp.v2.KmsWrappedCryptoKey.wrapped_key [base64-encoded]: [base64-encoded] has type <class 'str'>, but expected one of: (<class 'bytes'>,) for field KmsWrappedCryptoKey
我们如何在 json 中写入字节?不确定可行性
我使用的解决方法:
- 使用临时加密密钥创建了一个模板:
"cryptoKey": {
"transient": {
"name": "ola-32"
}
}
}
- 在 DLP UI 中修改了模板配置。
- 将密码字段的转换更改为 KMS 包装的加密密钥。
- 添加了资源名称和 KMS 生成的密钥。
- 它工作正常,测试了模板。
补充观察:
- 我做了一个 API 调用来检查配置,在我使用 UI 添加 KMS 密钥后,我看到了这样的包装密钥:
据我所知,它不可能在 json 中使用这种格式的包装密钥。
有没有办法使用保存为 json 的模板来使用 KMS 密钥?