Skip to content

09DataService 9 of 13

Cloud KMSsecurity hardening

Harden Cloud KMS and CMEK: key project layout, separation of duties, rotation, destruction safeguards, Autokey, org policies requiring CMEK, and key monitoring.

Baseline
10 controls
Category
Data
Updated
Reading
9 min read

Cloud KMS holds the keys behind customer-managed encryption keys (CMEK) for Cloud Storage, BigQuery, Compute Engine disks, Cloud SQL and GKE secrets, plus signing and asymmetric keys for applications. Google already encrypts everything at rest with keys it manages, so CMEK is only worth having when it gives you something extra: a key lifecycle you control, the ability to make data unreadable by disabling a key, an audit trail of every use, and a separation between the people who run a system and the people who hold its keys. Left at defaults, those benefits disappear quietly. Keys sit in the same project as the data, so the application team's Owner role can both administer and use them. Rotation is never configured. A key version is destroyed during a cleanup and the data it protected is gone for good. This page covers key layout, IAM, rotation, destruction safeguards, Autokey, organization policies that require CMEK, and the logs that make key use visible.

Baseline controls

Apply these to every project that holds Cloud KMS keys. CIS IDs refer to the CIS GCP Foundations Benchmark v5.0.1.

ControlWhyHow to checkCIS / SCC
Keep keys in dedicated KMS projectsData owners do not control keysNo Owner grants on KMS projectsKMS_PROJECT_HAS_OWNER
Never grant key access to allUsersPublic keys can be used by anyonegcloud kms keys get-iam-policyCIS 1.10, KMS_PUBLIC_KEY
Rotate symmetric keys within 90 daysLimits data per key versionKey rotationPeriodCIS 1.11, KMS_KEY_NOT_ROTATED
Separate key admins from key usersNobody both manages and uses keysAsset search for roles/cloudkms.adminCIS 1.12, KMS_ROLE_SEPARATION
Grant key use to service agents onlyFew, known key usersKey IAM policy membersTOO_MANY_KMS_USERS
Lengthen the destroy waiting periodTime to catch a mistaken destroycloudkms.minimumDestroyScheduledDurationn/a
Destroy only disabled key versionsDisabling first surfaces breakagecloudkms.disableBeforeDestroyn/a
Require CMEK for sensitive servicesNo unencrypted-by-you resourcesgcp.restrictNonCmekServicesn/a
Restrict which projects supply keysKeys come from controlled projectsgcp.restrictCmekCryptoKeyProjectsn/a
Log key use and alert on destructionAudit trail and early warningData Access logs for cloudkms.googleapis.comn/a

Choose the right level of control

OptionWho holds the keyWhen to use
Google default encryptionGoogleDefault for everything; no action needed
CMEK, software keysCloud KMS in your projectControl over lifecycle and access, logged key use
CMEK, Cloud HSM keys (--protection-level=hsm)FIPS 140-2 Level 3 certified HSMs operated by GoogleRegulatory requirement for hardware-protected keys
Cloud External Key Manager (EKM)An external key manager you operateKey material must never reside in Google Cloud
Customer-supplied encryption keys (CSEK)You, supplied per requestA few services only; CMEK is usually better

Most organizations use software or HSM CMEK for sensitive data and leave the rest on default encryption. Restrict which protection levels can be created with the cloudkms.allowedProtectionLevels constraint (values include SOFTWARE, HSM, HSM_SINGLE_TENANT, EXTERNAL, EXTERNAL_VPC).

Key projects and key rings

Key rings and keys cannot be deleted (only key versions can be destroyed), so names are permanent. Plan before you create anything.

  • Dedicated KMS projects, separate from the projects whose data they protect, in a common folder: prj-c-kms-prod, prj-c-kms-nonprod. Protect them with a project lien so they cannot be deleted by accident.
  • One key ring per location and purpose, for example kr-storage-europe-west1. The key location must match the resource: a bucket in EU needs a key in europe, a BigQuery dataset in europe-west1 needs a key in europe-west1.
  • One key per data domain or application, so disabling a key affects a known, limited set of data.
gcloud kms keyrings create kr-storage-europe-west1 \
  --project=prj-c-kms-prod --location=europe-west1

gcloud kms keys create k-website-data \
  --project=prj-c-kms-prod --location=europe-west1 \
  --keyring=kr-storage-europe-west1 \
  --purpose=encryption \
  --protection-level=hsm \
  --rotation-period=90d \
  --next-rotation-time=$(date -u -d "+90 days" +%Y-%m-%dT%H:%M:%SZ) \
  --destroy-scheduled-duration=60d

gcloud alpha resource-manager liens create \
  --project=prj-c-kms-prod --restrictions=resourcemanager.projects.delete \
  --reason="Holds production encryption keys"

On macOS, use date -u -v+90d +%Y-%m-%dT%H:%M:%SZ for the next rotation time.

Console: Security > Key Management.

Separation of duties and key access

The value of CMEK depends on key administrators being different people from data owners. Cloud KMS splits the roles:

RoleGrantsGrant to
roles/cloudkms.adminCreate keys, change IAM on keys, schedule destruction. No encrypt or decrypt.Key administrators group, on the KMS project
roles/cloudkms.cryptoKeyEncrypterDecrypterUse the keyThe service agent of the service using it, on the specific key
roles/cloudkms.viewerRead key metadataAuditors

Never grant Owner on a KMS project to application teams: Owner includes both administration and use. CIS 1.12 asks that no principal holds roles/cloudkms.admin together with an encrypter or decrypter role, and CIS 1.10 that no key is reachable by allUsers or allAuthenticatedUsers.

Find who holds which role:

gcloud asset search-all-iam-policies \
  --scope=organizations/ORG_ID \
  --query="policy:(roles/cloudkms.admin OR roles/cloudkms.cryptoKeyEncrypterDecrypter OR roles/owner)" \
  --asset-types=cloudkms.googleapis.com/CryptoKey,cloudkms.googleapis.com/KeyRing,cloudresourcemanager.googleapis.com/Project \
  --format="table(resource,policy.bindings.role,policy.bindings.members)"

gcloud kms keys get-iam-policy k-website-data \
  --project=prj-c-kms-prod --location=europe-west1 --keyring=kr-storage-europe-west1

Block public principals org-wide with the domain restricted sharing constraint (iam.allowedPolicyMemberDomains or the managed iam.managed.allowedPolicyMembers), covered on the Organization Policy page.

Connect a service to the key

CMEK-integrated services call KMS with a Google-managed service agent in the project that owns the resource, not with your identity. For Cloud Storage:

gcloud storage service-agent --project=prj-website-prod

gcloud kms keys add-iam-policy-binding k-website-data \
  --project=prj-c-kms-prod --location=europe-west1 \
  --keyring=kr-storage-europe-west1 \
  --member="serviceAccount:service-PROJECT_NUMBER@gs-project-accounts.iam.gserviceaccount.com" \
  --role="roles/cloudkms.cryptoKeyEncrypterDecrypter"

Then point the resource at the key: a bucket default key (see Cloud Storage), a BigQuery dataset default key, a disk created with --kms-key (see Compute Engine), or GKE application-layer secrets encryption (see GKE). Service agent names differ per product; each product's CMEK page lists them.

Autokey

Cloud KMS Autokey automates the steps above. You enable it on a folder and designate a key project. When a developer creates a supported resource (Cloud Storage bucket, BigQuery dataset, Compute Engine disk, Cloud SQL instance and others) and requests a key, Autokey creates a key ring and key in the matching location with rotation configured, and grants the service agent access. Developers never need KMS permissions.

# autokey-config.yaml
name: folders/FOLDER_ID/autokeyConfig
keyProjectResolutionMode: DEDICATED_KEY_PROJECT
keyProject: projects/prj-c-kms-prod
gcloud kms autokey-config update autokey-config.yaml

Developers then request keys through a KeyHandle (in the console when creating the resource, or with the Terraform google_kms_key_handle resource). Autokey removes the most common CMEK mistakes: wrong location, missing service agent binding, and one key shared by unrelated data. Same-project mode (RESOURCE_PROJECT) exists for single projects, but it puts keys back next to the data, so prefer a dedicated key project in production.

Rotation

Rotation creates a new primary key version. New data is encrypted with it; existing data stays encrypted under the version that was primary when it was written, and older versions remain available for decryption. CIS 1.11 asks for rotation at least every 90 days on symmetric keys.

gcloud kms keys update k-website-data \
  --project=prj-c-kms-prod --location=europe-west1 \
  --keyring=kr-storage-europe-west1 \
  --rotation-period=90d \
  --next-rotation-time=2027-02-01T00:00:00Z

gcloud kms keys list \
  --project=prj-c-kms-prod --location=europe-west1 --keyring=kr-storage-europe-west1 \
  --format="table(name.basename(),purpose,rotationPeriod,nextRotationTime)"

Rotation does not re-encrypt existing data. After a suspected compromise of a version, rewrite the data (for Cloud Storage, rewrite the objects) before disabling the old version. Asymmetric keys do not support automatic rotation; rotate them manually with your application's key distribution. NIST SP 800-57 covers cryptoperiods in detail.

Destruction safeguards

Destroying a key version makes every piece of data encrypted with it unrecoverable. Cloud KMS schedules destruction rather than doing it immediately: the default waiting period is 30 days, during which the version can be restored. Set a longer period at creation time with --destroy-scheduled-duration, and enforce safeguards org-wide:

# kms-min-destroy.yaml
name: organizations/ORG_ID/policies/cloudkms.minimumDestroyScheduledDuration
spec:
  rules:
    - values:
        allowedValues:
          - in:60d
---
# kms-disable-before-destroy.yaml
name: organizations/ORG_ID/policies/cloudkms.disableBeforeDestroy
spec:
  rules:
    - enforce: true
gcloud org-policies set-policy kms-min-destroy.yaml
gcloud org-policies set-policy kms-disable-before-destroy.yaml

With cloudkms.disableBeforeDestroy, a version must be disabled first. Disabling breaks anything still using the key, which surfaces forgotten dependencies before the data is lost. Check the key usage tracking view (Key Management > key > Key usage) or Cloud Asset Inventory to see which resources a key protects before you disable it. Restore a scheduled version with gcloud kms keys versions restore.

Require CMEK with organization policy

Two list constraints make CMEK mandatory and keep keys in approved projects:

  • gcp.restrictNonCmekServices: listed services cannot create resources without a CMEK key.
  • gcp.restrictCmekCryptoKeyProjects: CMEK keys must come from listed projects or folders.
# require-cmek.yaml
name: folders/FOLDER_ID/policies/gcp.restrictNonCmekServices
spec:
  rules:
    - values:
        deniedValues:
          - storage.googleapis.com
          - bigquery.googleapis.com
          - compute.googleapis.com
          - sqladmin.googleapis.com
---
# cmek-key-projects.yaml
name: folders/FOLDER_ID/policies/gcp.restrictCmekCryptoKeyProjects
spec:
  rules:
    - values:
        allowedValues:
          - under:projects/prj-c-kms-prod

Apply them to the production folder first, using dry-run policies to see which creations would fail. Add cloudkms.googleapis.com to the restricted services of your VPC Service Controls perimeter so keys can only be used from inside it.

Logging and detection

Admin Activity logs record key creation, IAM changes, disabling and destruction, and are always on. Encrypt and decrypt calls are Data Access logs, off by default. Enable them on the KMS projects:

auditConfigs:
  - service: cloudkms.googleapis.com
    auditLogConfigs:
      - logType: DATA_READ
      - logType: DATA_WRITE

The volume is high for busy keys, but a record of every key use is often the reason CMEK was adopted in the first place. Route the logs to the central project described on the Cloud Logging page.

Alert on destruction, disabling and IAM changes:

protoPayload.serviceName="cloudkms.googleapis.com"
(protoPayload.methodName:"DestroyCryptoKeyVersion"
  OR protoPayload.methodName:"UpdateCryptoKeyVersion"
  OR protoPayload.methodName:"SetIamPolicy")
gcloud logging metrics create kms-key-destroy \
  --description="Cloud KMS key version destruction requests" \
  --log-filter='protoPayload.serviceName="cloudkms.googleapis.com" AND protoPayload.methodName:"DestroyCryptoKeyVersion"'

Also watch for decrypt calls from principals that are not the expected service agents, and for PERMISSION_DENIED decrypt attempts. In Security Command Center, KMS_PUBLIC_KEY, KMS_ROLE_SEPARATION and KMS_PROJECT_HAS_OWNER deserve an immediate notification. With Cloud EKM, Key Access Justifications add a reason to every request Google makes to your key, which your external key manager can approve or deny.

Common mistakes

  • Keys in the same project as the data. Whoever owns the project owns the keys, and CMEK adds cost without adding separation.
  • Granting Owner or roles/cloudkms.admin to application teams. Administration and use end up with the same people, which is exactly what CIS 1.12 warns about.
  • Destroying a key version without checking usage. The data is unrecoverable once the waiting period ends; disable first and wait.
  • Wrong key location. A key in europe-west1 cannot protect a bucket in EU; resource creation fails and teams fall back to default encryption.
  • Expecting rotation to re-encrypt data. Old data stays under old versions until it is rewritten.
  • One key for everything. Disabling it becomes impossible because it would break the whole platform.
  • Requiring CMEK without Autokey or a key request process. Developers get blocked by gcp.restrictNonCmekServices and ask for exceptions instead.

References

About the author

Security engineer writing practical, benchmark-aligned guides to hardening Google Cloud organizations, projects and workloads.

Related services

All services