Cloud/ Google Cloud / Identity & Security / Cloud KMS: Managing Encryption Keys on GCP Without Rolling Your Own Crypto

GCP Google Cloud Platform Guide 3 of 10 54 guides ยท updated 2026

Guides to BigQuery, Vertex AI, GKE, Dataflow, and the rest of Google's data- and AI-first cloud โ€” written for engineers shipping real workloads.

Cloud KMS: Managing Encryption Keys on GCP Without Rolling Your Own Crypto

โ€œJust encrypt itโ€ is easy advice and a genuinely hard engineering problem the moment you ask the follow-up questions: where does the key live, who can use it, how do you rotate it without breaking every service that depends on it, and what happens when you need to prove to an auditor that a specific key was never accessible to a specific team. Cloud Key Management Service (KMS) exists to answer these questions with infrastructure, not policy documents โ€” a managed service for creating, storing, rotating, and controlling access to the cryptographic keys that protect your data, without you ever needing to implement key storage or rotation logic yourself.

Nearly every GCP service that touches sensitive data โ€” Cloud Storage, BigQuery, Compute Engine disks, Cloud SQL โ€” already encrypts everything at rest by default using Google-managed keys. Cloud KMS is what you reach for when โ€œGoogle manages the keysโ€ isnโ€™t sufficient for your compliance posture, and you need to hold the keys yourself, control their lifecycle, and be able to revoke access to encrypted data by disabling a key you control.


The Key Hierarchy

Cloud KMS organizes keys in a simple but important hierarchy:

Project
โ”‚
โ–ผ
Key Ring (a named grouping, tied to a location)
โ”‚
โ–ผ
Crypto Key (the actual key โ€” has a purpose: encrypt/decrypt, sign/verify)
โ”‚
โ–ผ
Key Versions (each rotation creates a new version;
old versions remain for decrypting old data)

A key ring is purely an organizational container โ€” it groups related keys and has no cryptographic function itself, but its location (region, multi-region, or global) is fixed at creation and determines where the actual key material is stored and where operations using it are processed. A crypto key is the logical key your applications reference; its versions are what actually change on rotation โ€” the crypto key identity stays stable in your application config while the underlying key material rotates underneath it.

This separation matters practically: your application code references a crypto key by name, never a specific version, so key rotation is transparent to callers โ€” decrypt requests automatically use whichever version originally encrypted the data, referenced by metadata embedded in the ciphertext.


Creating and Using a Key

Terminal window
# Create a key ring in a specific location
gcloud kms keyrings create app-secrets \
--location=us-central1
# Create a symmetric encryption key with automatic rotation every 90 days
gcloud kms keys create app-encryption-key \
--location=us-central1 \
--keyring=app-secrets \
--purpose=encryption \
--rotation-period=90d \
--next-rotation-time=2026-04-01T00:00:00Z
# Encrypt a file
gcloud kms encrypt \
--location=us-central1 \
--keyring=app-secrets \
--key=app-encryption-key \
--plaintext-file=config.json \
--ciphertext-file=config.json.enc
# Decrypt it back
gcloud kms decrypt \
--location=us-central1 \
--keyring=app-secrets \
--key=app-encryption-key \
--ciphertext-file=config.json.enc \
--plaintext-file=config-decrypted.json

The --rotation-period flag is doing real work here โ€” Cloud KMS automatically generates a new key version every 90 days without you writing any rotation logic, and old versions remain available for decrypting data encrypted before the rotation, which is what makes automated rotation safe rather than a data-loss risk.


Envelope Encryption: How Large Data Is Actually Protected

Cloud KMS itself has a payload size limit for direct encrypt/decrypt calls (64 KiB for symmetric keys), which means itโ€™s not designed to encrypt large files or database backups directly. The pattern used instead โ€” and the one nearly every GCP service uses internally โ€” is envelope encryption:

Generate a random Data Encryption Key - DEK

Encrypt the actual data locally with the DEK

Send the DEK to Cloud KMS

KMS encrypts the DEK using the Key Encryption Key - KEK

Store the encrypted DEK alongside the encrypted data

Discard the plaintext DEK from memory

To decrypt later, you send the encrypted DEK to Cloud KMS (a small, fast operation regardless of how large the original data was), get back the plaintext DEK, and use it locally to decrypt the actual payload. This is why encrypting a 50 GB database backup doesnโ€™t mean sending 50 GB through KMS โ€” only the small DEK ever touches the KMS API, and the KEK (the crypto key stored in KMS) never leaves KMS at all, even during decryption.


Software Keys vs Cloud HSM vs External Key Manager

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Protection level โ”‚ What it means โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Software โ”‚ Key material stored and processed in โ”‚
โ”‚ โ”‚ Google's software-based key management โ”‚
โ”‚ โ”‚ system โ€” the default, sufficient for most โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ HSM โ”‚ Key material generated and used inside a โ”‚
โ”‚ โ”‚ FIPS 140-2 Level 3 validated hardware โ”‚
โ”‚ โ”‚ security module โ€” required by some โ”‚
โ”‚ โ”‚ compliance frameworks โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ External (EKM) โ”‚ Key material lives entirely outside Google,โ”‚
โ”‚ โ”‚ in a third-party or on-prem key manager โ€” โ”‚
โ”‚ โ”‚ Google never has access to the raw key โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Most workloads never need anything beyond software keys โ€” the security guarantee is genuinely strong, and itโ€™s meaningfully cheaper and lower-latency than HSM. Cloud HSM matters when a specific compliance framework (some financial or government regulations) mandates hardware-backed key storage as a checklist requirement, not because software keys are cryptographically weaker in practice. External Key Manager is the answer to โ€œwe need to guarantee Google literally cannot access our data even under legal compulsionโ€ โ€” a real requirement for some regulated industries and a substantial operational complexity trade-off for everyone else.


CMEK: Bringing Your Own Key to GCP Services

Customer-Managed Encryption Keys (CMEK) let you point a GCP service โ€” Cloud Storage, BigQuery, Compute Engine, Cloud SQL โ€” at a Cloud KMS key you control, instead of relying on Googleโ€™s default encryption.

Terminal window
# Create a BigQuery dataset encrypted with a CMEK key
bq mk --dataset \
--default_kms_key=projects/my-project/locations/us-central1/keyRings/app-secrets/cryptoKeys/bq-key \
my-project:sensitive_data

The practical superpower this unlocks is crypto-shredding: disabling or destroying the KMS key immediately renders every piece of data encrypted with it unreadable, everywhere, without touching the data itself. For a company that needs to prove complete data destruction for a departed customer under a data-processing agreement, disabling their dedicated CMEK key is a fast, verifiable way to satisfy that obligation compared to hunting down and deleting every copy, backup, and replica of their data manually.


Asymmetric Keys: Signing and Verification

Beyond symmetric encryption, Cloud KMS also manages asymmetric key pairs for digital signing โ€” a different use case entirely from encrypting data, but one that shows up constantly in service-to-service authentication and software supply chain integrity.

Terminal window
# Create an asymmetric signing key
gcloud kms keys create code-signing-key \
--location=us-central1 \
--keyring=app-secrets \
--purpose=asymmetric-signing \
--default-algorithm=ec-sign-p256-sha256
# Sign a digest of a build artifact
gcloud kms asymmetric-sign \
--location=us-central1 \
--keyring=app-secrets \
--key=code-signing-key \
--key-version=1 \
--digest-algorithm=sha256 \
--input-file=artifact.digest \
--signature-file=artifact.sig

The private key material never leaves KMS โ€” signing happens inside the service, and only the signature is returned. Verification, by contrast, only needs the public key, which you can export and distribute freely to anything that needs to verify a signature without ever needing access to KMS itself. This pattern underpins Binary Authorizationโ€™s attestation model, where a build pipeline signs an image digest with a KMS key and a deploy-time policy verifies that signature before allowing the image to run.


Real-World Use Case: Multi-Tenant Data Isolation

A SaaS company with per-customer data isolation requirements is a strong real-world case for CMEK done deliberately. Rather than one shared encryption key across all tenant data, the architecture provisions one crypto key per tenant (or per tenant tier), and tenant data โ€” stored in shared BigQuery tables or Cloud Storage buckets โ€” is encrypted with that tenant-specific key. Offboarding a customer, or responding to a โ€œright to be forgottenโ€ request, becomes disabling one key rather than a fragile, error-prone data-deletion script that has to correctly find every row across every table and backup.


Best Practices


Common Mistakes

Destroying a key without verifying nothing still depends on it. Key destruction (after the scheduled destruction delay passes) is permanent and unrecoverable โ€” any data encrypted with that key becomes permanently unreadable, which is sometimes exactly the intended crypto-shredding outcome and sometimes a catastrophic mistake from destroying the wrong key.

Treating rotation as a substitute for revocation. Rotating a key generates a new version but doesnโ€™t retroactively re-encrypt data or invalidate a compromised old versionโ€™s ability to decrypt existing ciphertext โ€” if a key version is actually compromised, disabling that specific version (not just rotating forward) is the real remediation.

Ignoring key ring location constraints during architecture design. A key ringโ€™s location is immutable once created, and it constrains which resources can use it efficiently โ€” discovering this after building around a mismatched location is a common and entirely avoidable rework.


Frequently Asked Questions

Does Cloud KMS store my actual data? No โ€” KMS stores and operates on keys only. Your data is encrypted by your application or by a GCP service using a key from KMS, but the ciphertext lives wherever you originally stored it, not inside KMS.

What happens to already-encrypted data when a key is rotated? Nothing changes for existing data โ€” it remains decryptable using the key version that originally encrypted it. Only newly encrypted data uses the latest key version going forward.

Is Cloud HSM required for compliance? Only for specific frameworks that explicitly mandate hardware-backed key storage. Most compliance requirements around encryption key management are satisfied by software keys with proper access control and audit logging โ€” check your specific frameworkโ€™s requirements rather than assuming HSM is universally required.

Can I import my own existing keys into Cloud KMS instead of generating new ones? Yes, via the key import feature, which is commonly used when migrating from an existing on-prem or third-party key management system without needing to re-encrypt all existing data under a newly generated key.

Whatโ€™s the difference between KMS and Secret Manager? KMS manages cryptographic keys used to encrypt and decrypt data; Secret Manager stores the actual secret values (API keys, passwords, tokens) themselves, and under the hood Secret Manager uses KMS to encrypt what it stores. Theyโ€™re complementary layers, not competing products.


Summary

Cloud KMSโ€™s real value isnโ€™t cryptography โ€” AES-256 encryption is well understood and Google isnโ€™t inventing new math here โ€” itโ€™s the operational infrastructure around key lifecycle: rotation without breaking decryption of old data, fine-grained IAM control over who can use a key versus who can manage it, audit logging of every key operation, and the crypto-shredding capability that CMEK unlocks. Design your key hierarchy deliberately around isolation boundaries that matter to your business (tenant, environment, sensitivity tier) before you need it for a compliance audit or an urgent data-destruction request, because retrofitting key isolation onto data already encrypted under one shared key is far harder than building it in from the start.