Good day, today a policy was applied to make mandatory the use of KMS keys for everything including queries. I have succesfully managed to apply kms key to my dataflow jobs queries in apache beam thanks to the .withKmsKey(String kmsKey) function, but for dataform I have not been able to solve this error, let me share all what I have tried first:
Tried without success:
Creating from 0 the dataform repo using the same kms key that is used at the bigquery datasets that sqlx script is trying to query.
Tried to give the Service account used at my dataform workflows the encrypt/decrypt role to the key that is used at the bigquery dataset we are trying to query.
Finally in the documentation I found the flag to setup the kms_key_name at the sqlx scrypt config block, but this did also not work, here is the documentation I found about this:
The core issue is that a new policy in your project mandates the use of CMEK for all BigQuery operations, including the queries Dataform executes. While you’ve successfully handled this in Dataflow, Dataform requires a slightly different configuration.
Troubleshooting Steps
Verify KMS Key Permissions:
Service Account: Ensure the service account used by your Dataform workflows has the following roles on the KMS key:
roles/cloudkms.cryptoKeyEncrypterDecrypter
roles/bigquery.dataOwner (or a custom role with equivalent BigQuery permissions)
Project Level: Double-check that the KMS key is enabled for BigQuery encryption at the project level. Go to the BigQuery settings in the Google Cloud Console and verify this.
Dataform Configuration (SQLX files):
kms_key_name: Confirm the correct usage of the kms_key_name option within your SQLX file configuration blocks:
Replace Placeholders: Make absolutely sure to replace your-project-id, your-key-location, your-key-ring, and your-key-name with the actual values for your KMS key.
Dataform Compilation and Deployment:
Recompile: After making configuration changes, recompile your Dataform project.
Redeploy: If you are using Dataform’s Git-based deployment, commit your changes and redeploy to ensure the updated configurations are picked up.
Alternative Syntax (Optional):
Environment Variable: If directly specifying the KMS key in the SQLX file doesn’t work, try setting an environment variable in your Dataform execution environment:
If none of these steps resolve the issue, consider reaching out to Google Cloud support with details of your configuration and the error message you are encountering. They might be able to provide more specific guidance based on your project’s setup.
There is a restriction there that says policies are not supported, and what I understand is that if we setup policies like the one causing this issue, it wont be supported by dataform? Resulting in no way to fix this