By default, Cloud Tasks encrypts customer content at rest. Cloud Tasks 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 Tasks. 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 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 Tasks resources is similar to using Google default encryption. For more information about your encryption options, see Customer-managed encryption keys (CMEK).
What is protected with CMEK
When you enable CMEK in Cloud Tasks, you enable it for a region. When enabled, the body and header of tasks created in that region are protected with your key when at rest. If a task was created while CMEK was enabled, and the key is later made inactive (by disabling or deleting the key, or by disabling CMEK) the task is encrypted with your key but cannot be executed.
Tasks are not protected with CMEK in the following cases:
- Task was created before enabling CMEK
- Task is not in the region for which CMEK is enabled
- Task is affected by a compatibility limitation
Compatibility limitations
The Cloud Tasks integration with CMEK does not support the following:
google-gaxversions below4.0.0: The NPM packagegoogle-gaxfor Node.js has limited support at versions earlier than4.0.0. For these versions, CMEK is only supported in the regionus-central1. Even if you only have tasks in that region, it is recommended that you upgrade to version4.0.0or later.App Engine built-in Taskqueue service: Tasks created using the App Engine built-in Taskqueue service are not protected by CMEK, even if they are in a region for which it is enabled. Enabling CMEK does not prevent the creation or operation (for example, execution or deletion) of these tasks.
Pull queues: If you enable CMEK, you can create and execute tasks on pull queues, but these tasks are not protected by CMEK. Pull queues are uncommon. To check if your queue is a pull queue, run the following gcloud CLI command in your terminal:
gcloud tasks queues describe QUEUE_NAME
Replace
QUEUE_NAMEwith the name of your queue.If the
typelisted ispull, your queue is a pull queue. If thetypelisted ispush, this limitation does not affect tasks on your queue.Queue-level routing: When CMEK is enabled, you cannot apply queue-level routing. And if queue-level routing is enabled, you cannot enable CMEK. To check if you have queue-level routing enabled, do the following:
Run the following gcloud CLI command in your terminal:
Replacegcloud tasks queues describe QUEUE_NAME
QUEUE_NAMEwith the name of your queue.In the output, look for the field
httpTargetand check if theuriOverridehas been set. If ahostis specified, your queue has queue-level routing enabled and is not compatible with CMEK. To remove queue-level routing, see Update or remove queue-level routing. If the output does not showuriOverridewith ahostspecified, your queue does not use queue-level routing.
Task TTL: When CMEK is enabled, you cannot set
task_ttlto greater than 60 days. And if you have atask_ttlset to greater than 60 days, you cannot enable CMEK.
Before you begin
Before using CMEK in Cloud Tasks, complete the following steps:
Enable the APIs.
Console
-
Enable the Cloud KMS and Cloud Tasks APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.
gcloud
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Set your default project. This should be the project that contains the Cloud Tasks resources that you want to protect with CMEK. If you need to run a command in a different project, such as the project containing your Cloud KMS resources, this page will include the
--projectflag in the gcloud CLI command and tell you which project to specify.gcloud config set project PROJECT_ID
Replace
PROJECT_IDwith the ID of the project that contains your Cloud Tasks resources.Update
gcloudcomponents.gcloud components update
Enable the Cloud KMS and Cloud Tasks APIs for the project that will store your encryption keys.
gcloud services enable cloudkms.googleapis.com cloudtasks.googleapis.com \ --project=PROJECT_ID
Replace
PROJECT_IDwith the ID of the project that will store your encryption keys. This could be the same project as your Cloud Tasks resources, but to limit access to your Cloud KMS keys, consider Setting up Cloud KMS in a separate project.
-
Cloud KMS produces Cloud Audit Logs when keys are enabled, disabled, or used by Cloud Tasks resources to encrypt and decrypt data. Make sure that logging is enabled for the Cloud KMS API in your project, and that you have decided which logging-specific permissions and roles apply to your use case. For more information, see Cloud KMS audit logging information.
Get Identity and Access Management roles.
To get the permissions that you need to use CMEK with Cloud Tasks, ask your administrator to grant you the following IAM roles on your project:
-
Enable or disable CMEK:
roles/cloudtasks.admin -
View the key in use:
roles/cloudtasks.viewer
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
-
Enable or disable CMEK:
Create a Cloud KMS key ring and key
If you already have a key ring in the same region as your Cloud Tasks resources and you want to use that key and key ring, skip this section. If not, use these instructions to create your Cloud KMS key and key ring.
-
The key ring must be in the region that contains the Cloud Tasks resources that you want to protect. For more information, see Cloud KMS locations and Cloud Tasks locations.
The key ring and the CMEK-protected Cloud Tasks resources can be in the same project, but to limit access to your Cloud KMS keys, consider setting up Cloud KMS in a separate project.
Retrieve the ID for a Cloud KMS key
The resource ID for a Cloud KMS key is required when you enable CMEK for Cloud Tasks.
Console
In the Google Cloud console, go to the Key management page and select the Key inventory tab.
For the key whose resource ID you are retrieving, click more_vert Actions.
Click Copy resource name.
The resource ID for the key is copied to your clipboard. Its format is similar to the following: