By default, Cloud Data Fusion encrypts customer content at rest. Cloud Data Fusion handles encryption for you without any additional actions on your part. This option is called Google default encryption.
If you want to control your encryption keys, then you can use customer-managed encryption keys (CMEKs) in Cloud KMS with CMEK-integrated services including Cloud Data Fusion. Using Cloud KMS keys gives you control over their protection level, location, rotation schedule, usage and access permissions, and cryptographic boundaries. Using Cloud KMS also lets you track key usage, view audit logs, and control key lifecycles. Instead of Google owning and managing the symmetric key encryption keys (KEKs) that protect your data, you control and manage these keys in Cloud KMS.
After you set up your resources with CMEKs, the experience of accessing your Cloud Data Fusion resources is similar to using Google default encryption. For more information about your encryption options, see Customer-managed encryption keys (CMEK).
Cloud Data Fusion supports Cloud KMS key usage tracking for the Instance resource.
CMEK lets you control the data written to Google internal resources in tenant projects and data written by Cloud Data Fusion pipelines, including pipeline logs and metadata, Managed Service for Apache Spark cluster metadata, and Cloud Storage, BigQuery, Pub/Sub, and Spanner data sinks, actions, and sources.
CMEK with Cloud KMS Autokey
You can either create CMEKs manually to protect your Cloud Data Fusion instances or use Cloud KMS Autokey. With Autokey, key rings and keys are generated on demand to support resource creation in Cloud Data Fusion. Service agents that use the keys for encrypt and decrypt operations are created if they don't already exist and are granted the required Identity and Access Management (IAM) roles. For more information, see Autokey overview.
Cloud Data Fusion is compatible with Cloud KMS Autokey only when you create instances by using Terraform or the REST API.
To set up CMEK manually, see Set up CMEK in this document. To set up CMEK by using Cloud KMS Autokey, see Use Cloud KMS Autokey in this document.
Cloud Data Fusion resources
For a list of Cloud Data Fusion plugins that support CMEK, see the supported plugins.
Cloud Data Fusion supports CMEK for Managed Service for Apache Spark clusters. Cloud Data Fusion creates a temporary Managed Service for Apache Spark cluster for use in the pipeline, and then deletes the cluster when the pipeline completes. CMEK protects the cluster metadata written to the following:
- Persistent disks (PD) attached to cluster VMs
- Job driver output and other metadata written to the auto-created or user-created Managed Service for Apache Spark staging bucket
Set up CMEK
Create a Cloud KMS key
Create a Cloud KMS key in the Google Cloud project that contains the Cloud Data Fusion instance or in a separate user project. The Cloud KMS key ring location must match the region where you create the instance. A multi-region or global region key isn't allowed at the instance level because Cloud Data Fusion is always associated with a particular region.
Get the resource name for the key
REST API
Get the resource name of the key that you created with the following command:
projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME
Replace the following:
- PROJECT_ID: the customer project that hosts the Cloud Data Fusion instance
- REGION: a Google Cloud region
that's close to your location—for example,
us-east1 - KEY_RING_NAME: the name of the key ring that groups the cryptographic keys together
- KEY_NAME: the Cloud KMS key name
Console
Go to the Key management page.
Next to your key, click More .
Select Copy Resource Name to copy the resource name to the clipboard.
Update your project's service accounts to use the key
To set up your project's service accounts to use your key:
Required: Grant the Cloud KMS CryptoKey Encrypter/Decrypter role (
roles/cloudkms.cryptoKeyEncrypterDecrypter) to the Cloud Data Fusion service agent (see Granting roles to a service account for specific resources). This account is in the following format:service-PROJECT_NUMBER@gcp-sa-datafusion.iam.gserviceaccount.comGranting the Cloud KMS CryptoKey Encrypter/Decrypter role to the Cloud Data Fusion service agent enables Cloud Data Fusion to use CMEK to encrypt any customer data stored in tenant projects.
Required: Grant the Cloud KMS CryptoKey Encrypter/Decrypter role to the Compute Engine service agent (see Assigning a Cloud KMS key to a Cloud Storage service account). This account, which by default is granted the Compute Engine Service Agent role, is of the form:
service-PROJECT_NUMBER@compute-system.iam.gserviceaccount.comGranting the Cloud KMS CryptoKey Encrypter/Decrypter role to the Compute Engine service agent enables Cloud Data Fusion to use CMEK to encrypt persistent disk (PD) metadata written by the Managed Service for Apache Spark cluster running in your pipeline.
Required: Grant the Cloud KMS CryptoKey Encrypter/Decrypter role to the Cloud Storage service agent (see Assigning a Cloud KMS key to a Cloud Storage service agent). This service agent is of the form:
service-PROJECT_NUMBER@gs-project-accounts.iam.gserviceaccount.comGranting this role to the Cloud Storage service agent enables Cloud Data Fusion to use CMEK to encrypt the Cloud Storage bucket that stores and caches pipeline information and data written to the Managed Service for Apache Spark cluster staging bucket and any other Cloud Storage buckets in your project used by your pipeline.
Required: Grant the Cloud KMS CryptoKey Encrypter/Decrypter role to the Google Cloud Dataproc Service Agent. This service agent is of the form:
service-PROJECT_NUMBER@dataproc-accounts.iam.gserviceaccount.comOptional: If your pipeline uses BigQuery resources, grant the Cloud KMS CryptoKey Encrypter/Decrypter role to the BigQuery service account (see Grant encryption and decryption permission). This account is of the form:
bq-PROJECT_NUMBER@bigquery-encryption.iam.gserviceaccount.comOptional: If your pipeline uses Pub/Sub resources, grant the Cloud KMS CryptoKey Encrypter/Decrypter role to the Pub/Sub service account (see Using customer-managed encryption keys). This account is of the form:
service-PROJECT_NUMBER@gcp-sa-pubsub.iam.gserviceaccount.comOptional: If your pipeline uses Spanner resources, grant the Cloud KMS CryptoKey Encrypter/Decrypter role to the Spanner service account. This account is of the form:
service-PROJECT_NUMBER@gcp-sa-spanner.iam.gserviceaccount.com
Use Cloud KMS Autokey
To request a key for an instance instead of creating the key manually, use Cloud KMS Autokey. Cloud KMS Autokey generates the key in the same region as the instance. If you use Cloud KMS Autokey, then you can skip the steps in Set up CMEK.
Cloud KMS Autokey grants the Cloud KMS CryptoKey Encrypter/Decrypter
role (roles/cloudkms.cryptoKeyEncrypterDecrypter) on the key to all service
agents listed in
Update your project's service accounts to use the key.
This list includes the BigQuery, Pub/Sub, and
Spanner service agents, which are optional when you set up CMEK
manually. If one of the listed service agents doesn't exist, then
Cloud KMS Autokey creates it.
Before you request a key, enable Cloud KMS Autokey for the folder or project where you create the instance.
To use Cloud KMS Autokey, create the instance by using Terraform or the REST API:
- Create a key handle in the same
region as the instance. For the resource type of the key handle, specify
datafusion.googleapis.com/Instance. For instructions, see Create protected resources using Cloud KMS Autokey. - Create the instance, and specify the key from the key handle as the CMEK.
Use the
crypto_key_config.key_referenceargument in the Terraformgoogle_data_fusion_instanceresource, or use thecryptoKeyConfig.keyReferencefield in the REST API.
Create a Cloud Data Fusion instance with CMEK
CMEK is available in all editions of Cloud Data Fusion version 6.5.0 and later.
REST API
To create an instance with a customer-managed encryption key, set the following environment variables:
export PROJECT=PROJECT_ID export LOCATION=REGION export INSTANCE=INSTANCE_ID export DATA_FUSION_API_NAME=datafusion.googleapis.com export KEY=KEY_NAMEReplace the following:
- PROJECT_ID: the customer project that hosts the Cloud Data Fusion instance
- REGION: a Google Cloud region that's
close
to your location—for example,
us-east1 - INSTANCE_ID: the name of the Cloud Data Fusion instance
- KEY_NAME: the full resource name of the CMEK key
Run the following command to create a Cloud Data Fusion instance:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" https://$DATA_FUSION_API_NAME/v1/projects/$PROJECT/locations/$LOCATION/instances?instance_id=INSTANCE -X POST -d '{"description": "CMEK-enabled CDF instance created through REST.", "type": "BASIC", "cryptoKeyConfig": {"key_reference": "$KEY"} }'
Console
Go to the Cloud Data Fusion page.
Click Instances, and then click Create an instance.
In the Advanced options, select Use a customer-managed encryption key (CMEK).
In the Select a customer-managed key field, select the resource name for the key.

After you enter all of the instance details, click Create. When the instance is ready to use, it appears on the Instances page.
Check if CMEK is enabled on an instance
Console
View the instance details:
In the Google Cloud console, go to the Cloud Data Fusion page.
Click Instances, and then click the instance's name to go to the Instance details page.
If CMEK is enabled, the Encryption key field is shown as Available.
If CMEK is disabled, the Encryption key field is shown as Not available.
Use CMEK with supported plugins
When you set the encryption key name, use the following form:
projects/PROJECT_ID/locations/REGION/keyRings/KEY_RING_NAME/cryptoKeys/KEY_NAME

The following table describes the behavior of the key in the Cloud Data Fusion plugins that support CMEK.
| Supported plugins | Behavior of key |
|---|---|
| Cloud Data Fusion sinks | |
| Cloud Storage | Encrypts data written to any bucket created by the plugin. If the bucket already exists, this value is ignored. |
| Cloud Storage multi-file | Encrypts data written to any bucket created by the plugin. |
| BigQuery | Encrypts data written to any bucket, dataset or table created by the plugin. |
| BigQuery multi-table | Encrypts data written to any bucket, dataset or table created by the plugin. |
| Pub/Sub | Encrypts data written to any topic created by the plugin. If the topic already exists, this value is ignored. |
| Spanner | Encrypts data written to any database created by the plugin. If the database already exists, this value is ignored. |
| Cloud Data Fusion actions | |
|
Cloud Storage Create Cloud Storage Copy Cloud Storage Move Cloud Storage Done File Marker |
Encrypts data written to any bucket created by the plugin. If the bucket already exists, this value is ignored. |
| BigQuery Execute | Encrypts data written to the dataset or table that the plugin creates to store the query results. It's only applicable if you store the query results in a BigQuery table. |
| Cloud Data Fusion sources | |
| BigQuery source | Encrypts data written to any bucket created by the plugin. If the bucket already exists, this value is ignored. |
| Cloud Data Fusion SQL engine | |
| BigQuery Pushdown Engine | Encrypts data written to any bucket, dataset, or table created by the plugin. |
Use CMEK with Managed Service for Apache Spark cluster metadata
The pre-created compute profiles use the CMEK key provided during instance creation to encrypt the Persistent Disk (PD) and the staging bucket metadata written by the Managed Service for Apache Spark cluster running in your pipeline. You can modify to use another key by doing one of the following:
- Recommended: Create a new Managed Service for Apache Spark compute profile (Enterprise edition only).
- Edit an existing Managed Service for Apache Spark compute profile (Developer, Basic, or Enterprise editions).
Console
Open the Cloud Data Fusion instance:
In the Google Cloud console, go to the Cloud Data Fusion page.
To open the instance in the Cloud Data Fusion Studio, click Instances, and then click View instance.
Click System Admin > Configuration.
Click the System Compute Profiles drop-down.
Click Create New Profile, and select Managed Service for Apache Spark.
Enter a Profile label, Profile name, and Description.
By default, Managed Service for Apache Spark creates staging and temp buckets whenever an ephemeral cluster is created by Cloud Data Fusion. Cloud Data Fusion supports passing the Managed Service for Apache Spark staging bucket as an argument in the compute profile. To encrypt the staging bucket, create a CMEK-enabled bucket and pass it as an argument to Managed Service for Apache Spark in the compute profile.
By default, Cloud Data Fusion auto-creates a Cloud Storage bucket to stage dependencies used by Managed Service for Apache Spark. If you prefer to use a Cloud Storage bucket that already exists in your project, follow these steps:
In the General Settings section, enter your existing Cloud Storage bucket in the Cloud Storage Bucket field.
Get the resource ID of your Cloud KMS key. In the General Settings section, enter your resource ID in the Encryption Key Name field.
Click Create.
If more than one profile is listed in the System Compute Profiles section of the Configuration tab, make the new Managed Service for Apache Spark profile the default profile by holding the pointer over the profile name field and clicking the star that appears.
Use CMEK with other resources
The provided CMEK key is set to the system preference during Cloud Data Fusion instance creation. It is used to encrypt data written to newly created resources by pipeline sinks such as Cloud Storage, BigQuery, Pub/Sub, or Spanner sinks.
This key only applies to newly created resources. If the resource already exists before pipeline execution, you should manually apply the CMEK key to those existing resources.
You can change the CMEK key by doing one of the following:
- Use a runtime argument.
- Set a Cloud Data Fusion system preference.
Runtime argument
- In the Cloud Data Fusion Pipeline Studio page, click the drop-down arrow to the right of the Run button.
- In the Name field, enter
gcp.cmek.key.name. - In the Value field, enter your key's resource ID.
Click Save.
The runtime argument you set here applies only to runs of the current pipeline.
Preference
- In the Cloud Data Fusion UI, click SYSTEM ADMIN.
- Click the Configuration tab.
- Click the System Preferences drop-down.
- Click Edit System Preferences.
- In the Key field, enter
gcp.cmek.key.name. - In the Value field, enter your key's resource ID.
- Click Save & Close.