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:
1) 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.
2) 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.
3) 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:
* dataform core general doc: https://cloud.google.com/dataform/docs/reference/dataform-core-reference then in the IBigQueryOptions:
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:
Dataform Configuration (SQLX files):
config {
type: "table",
...other options...
additionalOptions: {
kms_key_name: "projects/your-project-id/locations/your-key-location/keyRings/your-key-ring/cryptoKeys/your-key-name"
}
}
Dataform Compilation and Deployment:
Alternative Syntax (Optional):
export DATAFORM_BIGQUERY_KMS_KEY_NAME="projects/your-project-id/locations/your-key-location/keyRings/your-key-ring/cryptoKeys/your-key-name"
Important Considerations:
Example:
config {
type: "table",
...
additionalOptions: {
kms_key_name: "projects/your-project-id/locations/us-central1/keyRings/your-key-ring/cryptoKeys/your-key"
}
}
SELECT * FROM `your-project-id.your-dataset.your-table`
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.
Hi @ms4446 thanks for your reply, I tried what you mention but no success, only thing I could not try is the
export DATAFORM_BIGQUERY_KMS_KEY_NAME="projects/your-project-id/locations/your-key-location/keyRings/your-key-ring/cryptoKeys/your-key-name"
Because I could not do this in the js block of dataform, export was not allowed.
But reading again the documentation I think I found the reason there is no way to fix this: https://cloud.google.com/dataform/docs/cmek#restrictions
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
This may be coming too late, but I had the exact same issue today and we managed to solve it by adding the encryption key with the following syntax:
config {
type: "table",
schema: "stage",
description: "Table with two integer columns c1 and c2",
bigquery: {
additionalOptions: {
kms_key_name: "\"projects/PROJECT-ID/locations/REGION/keyRings/KEY-RING/cryptoKeys/KEY\""
}
}
}
SELECT
1 AS c1,
3 AS c2
Note the escaped double quotes around the key path - otherwise it will not work.