01 Before you can create your own Customer-Managed Encryption Key (CMEK), you have to provision a key ring. A Cloud KMS key ring is a grouping of cryptographic keys made available for organizational purposes in a specific Google Cloud location. Run kms keyrings create command (Windows/macOS/Linux) to create a new Cloud KMS key ring in the specified location. If the keys deployed later within this key ring will be used to encrypt resources in a given region, select that region as the key ring location:
gcloud kms keyrings create tm-cloud-run-key-ring
--location=us
--project=cc-bigdata-project-123123
--format="table(name)"
02 The command output should return the resource name of the newly created key ring:
NAME
projects/cc-bigdata-project-123123/locations/us/keyRings/tm-cloud-run-key-ring
03 Run kms keys create command (Windows/macOS/Linux) to create a new Customer-Managed Encryption Key (CMEK) within the Cloud KMS key ring created at the previous steps:
gcloud kms keys create tm-cloud-service-kms-key
--location=us
--keyring=tm-cloud-run-key-ring
--purpose=encryption
--protection-level=software
--rotation-period=90d
--next-rotation-time=2024-11-25T10:00:00.0000Z
--format="table(name)"
04 The command output should return the resource name of the new Customer-Managed Encryption Key:
NAME
projects/cc-bigdata-project-123123/locations/us/keyRings/tm-cloud-run-key-ring/cryptoKeys/tm-cloud-service-kms-key
05 Run kms keys add-iam-policy-binding command (Windows/macOS/Linux) to assign the Cloud KMS CryptoKey Encrypter/Decrypter role to the required service accounts:
gcloud kms keys add-iam-policy-binding tm-cloud-service-kms-key
--keyring tm-cloud-run-key-ring
--location us-central1
--member='serviceAccount:<project-number>-compute@developer.gserviceaccount.com'
--role roles/cloudkms.cryptoKeyEncrypterDecrypter
06 The command output should return the updated IAM policy (YAML format):
Updated IAM policy for key [tm-new-service-kms-key].
bindings:
- members:
- serviceAccount:<project-number>-compute@developer.gserviceaccount.com
- serviceAccount:service-<project-number>@gcf-admin-robot.iam.gserviceaccount.com
- serviceAccount:service-<project-number>@gs-project-accounts.iam.gserviceaccount.com
- serviceAccount:service-<project-number>@serverless-robot-prod.iam.gserviceaccount.com
role: roles/cloudkms.cryptoKeyEncrypterDecrypter
etag: ABCD1234ABCD1234
version: 1
07 Run the deploy command (Windows/macOS/Linux) with the name of the Cloud Run service that you want to configure as the identifier parameter, to enable encryption at rest using Cloud KMS Customer-Managed Encryption Keys (CMEKs). Use the --key parameter to specify your own Customer-Managed Encryption Key:
gcloud run deploy cc-project5-service
--region=us-central1
--image=gcr.io/serverless-runtimes/google-22/runtimes/nodejs20
--key=projects/cc-bigdata-project-123123/locations/us/keyRings/tm-cloud-run-key-ring/cryptoKeys/tm-cloud-service-kms-key
--post-key-revocation-action-type prevent-new
08 The command output should return the build information available for the redeployed service:
Building using Buildpacks and deploying container to Cloud Run service [cc-project5-service] in project [cc-bigdata-project-123123] region [us-central1]
OK Building and deploying... Done.
OK Uploading sources...
OK Building Container...
Logs are available at [https://console.cloud.google.com/cloud-build/builds...].
OK Creating Revision...
Done.
Service [cc-project5-service] revision [cc-project5-service-00003-abc] has been deployed and is serving 100 percent of traffic.
09 Repeat steps no. 1 - 8 for each Cloud Run service that you want to configure, available in the selected project.
10 Repeat steps no. 1 – 9 for each GCP project deployed in your Google Cloud account.