Using customer managed encryption keys
Stay organized with collections
Save and categorize content based on your preferences.
By default, Cloud Run encrypts customer content at
rest. Cloud Run 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 Run. 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 Run resources is similar to using Google default encryption.
For more information about your encryption
options, see Customer-managed encryption keys (CMEK).
File metadata, such as the path, is not encrypted.
Metadata of the Cloud Run service or worker pool, such as name or environment
variables, is not encrypted using the provided key but with a Google-owned and Google-managed encryption key.
At runtime, the memory and file content are not encrypted.
If a CMEK is disabled, new instances of existing
Cloud Run revisions using the key won't start.
If a CMEK is disabled, deploying a new Cloud Run revision
will fail unless a new valid key is used.
CMEK with Cloud KMS Autokey
You can either create CMEKs manually to protect your Cloud Run
resources or use Cloud KMS Autokey. With Autokey, key rings and keys are generated on demand to
support resource creation in Cloud Run.
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.
To set up CMEK manually, follow the instructions to configure CMEK for a service or a worker pool.
To set up CMEK using Autokey, follow the instructions to configure Autokeys for a service or a worker pool.
You can set your CMEK to one of the available protection levels to indicate how cryptographic operations are performed. When you use CMEK in Cloud Run,
your projects can consume Cloud KMS cryptographic requests
quotas. For example, CMEK-encrypted repositories can consume these quotas for each upload or download.
Encryption and decryption operations
using CMEK keys affect Cloud KMS quotas in these ways:
For software CMEK keys generated in Cloud KMS, no
Cloud KMS quota is consumed.
For hardware CMEK keys—sometimes called Cloud HSM
keys—encryption and decryption operations count against
Cloud HSM quotas in the project that
contains the key.
For external CMEK keys—sometimes called Cloud EKM
keys—encryption and decryption operations count against
Cloud EKM quotas in the project that
contains the key.
The expected autoscaling for your
Cloud Run service can be impacted when you use customer managed
encryption keys. For example, latency for starting new instances can increase
due to delays in contacting external key management systems during key
operations.
The following table shows the possible changes in behavior due to use of CMEK:
CMEK-related operation
Autoscaling behavior
Key disabled/destroyed/revoked
New instances won't start.
External key manager cannot be contacted
If the key request can be retried, no instances are shutdown during the retries and no new instances will start. Scale-out can appear slower than expected. If the key request cannot be retried, no new instances are started, and running instances are shut down after a waiting period.
KMS quota exceeded
If this quota is exceeded, RESOURCE_EXHAUSTED errors are logged, and new instances won't start. You can request additional quota to fix this.
You need permission to administer Cloud KMS resources in the
Google Cloud project to grant the IAM role
roles/cloudkms.cryptoKeyEncrypterDecrypter. Only IAM members
with Owner (roles/owner) or Cloud KMS Admin (roles/cloudkms.admin)
roles can grant or revoke access to Cloud KMS resources.
Configure CMEK for a service
Any configuration change leads to the
creation of a new revision. Subsequent revisions will also automatically get
this configuration setting unless you make explicit updates to change it.
Select Services from the Cloud Run navigation menu, and click
Deploy container to configure a new service.
If you are configuring an existing service, click the
service, then click Edit and deploy new revision.
If you are configuring a new service, fill out the initial service
settings page, then click Containers, Networking, Security to expand the
service configuration page.
Click the Security tab.
Under Encryption:
Select Cloud KMS key.
For Key type, select Cloud KMS.
From the Select a Cloud KMS key menu, choose one of the
following options:
Select Enter key manually to enter the secret from a project,
using the following format: projects/PROJECT_NAME/locations/LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY_NAME.
To copy and paste the resource name from another project that you have
access to:
IMAGE_URL: a reference to the container image, for
example, us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry,
the repositoryREPO_NAME must
already be created. The URL follows the format of LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG
.
KEY: the fully qualified key name in the following
format: projects/PROJECT_NAME/locations/LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY_NAME.
Any configuration change leads to the
creation of a new revision. Subsequent revisions will also automatically get
this configuration setting unless you make explicit updates to change it.
Select Services from the Cloud Run navigation menu, and click
Deploy container to configure a new service.
If you are configuring an existing service, click the
service, then click Edit and deploy new revision.
If you are configuring a new service, fill out the initial service
settings page, then click Containers, Networking, Security to expand the
service configuration page.
Click the Security tab.
Under Encryption:
From the Key type menu, select Cloud KMS with Autokey.
Click Request a key.
Click Create.
The key's details are shown after resource creation.
From the Key revocation action menu, choose one of the
following options:
Prevent new container instance: no new instances start after CMEK
revocation.
Shutdown as soon as possible: no new instances start and existing
instances shut down after CMEK revocation.
Custom shutdown delay: specify the number of hours before the
service shuts down.
Click Create or Deploy.
View security settings for services
To view the security settings for your
Cloud Run service:
Create your own CMEK-encrypted Cloud Storage bucket. For details, refer to
the CMEK documentation for Cloud Storage.
Upload your source code to the CMEK-encrypted storage bucket as a zipped
archive file.
Create your own CMEK-encrypted Artifact Registry repository. For details, refer to
the CMEK documentation for Artifact Registry. This
repository stores artifacts produced by the build process.
Deploy the function, passing the build resources by using the --source
and --image flags.
gcloud run deploy FUNCTION \
--key KEY \
--source CUSTOM_BUCKET_WITH_SOURCE_CODE \
--image CUSTOM_AR_REPOSITORY \
--function FUNCTION_ENTRYPOINT \
--base-image BASE_IMAGE \
--region REGION
Replace the following:
FUNCTION: the name of the function you are
deploying. You can omit this parameter entirely,
but you will be prompted for the name if you omit it.
KEY: the fully qualified key name in the following
format: projects/PROJECT_NAME/locations/LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY_NAME.
CUSTOM_BUCKET_WITH_SOURCE_CODE: the URI of a
Cloud Storage location where the source code is stored. Use the
following format: gs://BUCKET_NAME/PATH_TO_SOURCE.
CUSTOM_AR_REPOSITORY: the URI of an Artifact Registry repository in
the format
REGION-docker.pkg.dev/PROJECT_ID/REPOSITORY_NAME/PACKAGE_NAME.
FUNCTION_ENTRYPOINT: the entry point to your function in
your source code. This is the code Cloud Run executes when your
function runs. The value of this flag must be a function name or
fully-qualified class name that exists in your source code.
BASE_IMAGE: the base image environment for your
function. For more details about base images and the packages included
in each image, see Runtimes base images.
REGION: the Google Cloud
region where you want to deploy
your function. For example, europe-west1.
Additionally, if you use
Eventarc for triggering your
functions, familiarize yourself with the CMEK configuration for Eventarc.
In particular, full compliance in such cases requires encrypting
channels corresponding to the event types being used.
Test CMEK revocation for services
To verify that CMEK protection is working, you can disable the key you used to
enable CMEK for a service, then try to invoke your service:
Run the following command to confirm the service is accessible:
curlSERVICE_URL
Replace SERVICE_URL with the service URL. You can find this in
the console UI after deployment: the container URL is displayed
next to the text URL:.
Wait the number of SHUTDOWN_HOURS you specified. If you did not
specify the number of shutdown hours,
re-enable your key and edit or
redeploy your service with the value set to the minimum of one hour.
If you deployed source code, attempt to view the source code. The attempt
should fail.
After waiting the SHUTDOWN_HOURS duration you set re-run the
following command and confirm the service is no longer accessible:
curlSERVICE_URL
After you have verified that the key version is disabled,
enable the key.
Configure CMEK for a worker pool
Any configuration change leads to the
creation of a new revision. Subsequent revisions will also automatically get
this configuration setting unless you make explicit updates to change it.
Select Worker pools from the menu, and click Deploy container to
configure a new worker pool.
If you are configuring an existing worker pool, click the
worker pool, then click Edit and deploy new revision.
If you are configuring a new worker pool, fill out the initial worker
pool page, then click Containers, Networking, Security to expand the
worker pools configuration page.
Click the Security tab.
Under Encryption:
Select Cloud KMS key.
For Key type, select Cloud KMS.
From the Select a Cloud KMS key menu, choose one of the
following options:
Select Enter key manually to enter the secret from a project,
using the following format: projects/PROJECT_NAME/locations/LOCATION/keyRings/KEYRING_NAME/cryptoKeys/KEY_NAME.
To copy and paste the resource name from another project that you have
access to:
Any configuration change leads to the
creation of a new revision. Subsequent revisions will also automatically get
this configuration setting unless you make explicit updates to change it.
Select Worker pools from the menu, and click Deploy container to
configure a new worker pool.
If you are configuring an existing worker pool, click the
worker pool, then click Edit and deploy new revision.
If you are configuring a new worker pool, fill out the initial worker
pool page, then click Containers, Networking, Security to expand the
worker pools configuration page.
Click the Security tab.
Under Encryption:
From the Key type menu, select Cloud KMS with Autokey.
Click Request a key.
Click Create.
The key's details are shown after resource creation.
From the Key revocation action menu, choose one of the
following options:
Prevent new container instance: no new instances start after CMEK
revocation.
Shutdown as soon as possible: no new instances start and existing
instances shut down after CMEK revocation.
Custom shutdown delay: specify the number of hours before the
service shuts down.
Click Create or Deploy.
View security settings for worker pools
To view the security settings for your
Cloud Run worker pool:
If you are responsible for monitoring audit logs, one of your tasks might be to
verify CMEK operations in your Cloud Run service or worker pool. In this case, you
need to understand the related audit logs.
If you are responsible for addressing and fixing runtime errors for your
Cloud Run service or worker pool, you might need to troubleshoot CMEK-related errors
logged during the operation of the Cloud Run resource.
The following sections provide information needed for the preceding tasks.
Audit logs
KMS audit logs provide an audit trail for every
operation performed with a key. For CMEK-enabled Cloud Run resources,
Cloud Run adds Cloud Run-specific caller context that
details why the customer key was accessed by the system. The following table
lists the contexts you might see in the audit logs:
Reason for key access
Description
Decrypting CMEK-encrypted layer during container clone start.
Logged whenever a new instance is started.
Encrypting a newly created data-encryption-key w/ the customer-managed-encryption-key.
Logged during deployment of a CMEK-enabled service or worker pool, where the data encryption key is wrapped by the CMEK.
Decrypting an existing encrypted data-encryption-key, under the same customer-managed-encryption-key, to be used to encrypt container contents.
Logged when a new instance starts up, which requires decryption of the image.
Performing an encrypt operation on dummy data to check the customer-managed-encryption-key status and access.
Logged whenever there is a validation check on the key, which is done periodically.
Performing a decrypt operation on dummy data to check the customer-managed-encryption-key status and access.
Logged whenever there is a validation check on the key, which is done periodically.
For specifics about audit log format and content, refer to the
KMS audit logging page.
Error messages
Note that error messages provided by an external key manager are directly passed
through to the Cloud Run logs for your service.
The following table lists the CMEK-related error messages you might see, along
with descriptions and possible remedies.
Message
Description
User's service account does not have CMEK decrypter permission. Service account: %s
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-06-09 UTC."],[],[]]