I am working on a PII de-identification project and using google cloud's data loss prevention api.
Use case: To encrypt a field with cloud KMS key.
- Created a dlp-deidentification template, here is the snippet:
{
"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"
}
}
}
}
Saved the template as JSON file.
When I am trying to built the template using
python Api
, I am getting following error:
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
How we can write bytes in json? Not sure about the feasibility
Workaround I used:
- Created a template with transient crypto key:
"cryptoKey": {
"transient": {
"name": "ola-32"
}
}
}
- In the DLP UI modified the template configuration.
- Changed the transformation for password field to KMS wrapped crypto key.
- Added the resource name and the KMS generated key.
- Its working fine, tested the template.
Additional observation:
- I did a API call to check the configuration, after i added the KMS keys using UI, i saw the wrapped key like this:
Its not possible to use wrapped key in this format in json as per my knowledge.
Is there a way to use KMS keys using templates saved as json?