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
# Create a key ring in a specific locationgcloud kms keyrings create app-secrets \ --location=us-central1
# Create a symmetric encryption key with automatic rotation every 90 daysgcloud 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 filegcloud kms encrypt \ --location=us-central1 \ --keyring=app-secrets \ --key=app-encryption-key \ --plaintext-file=config.json \ --ciphertext-file=config.json.enc
# Decrypt it backgcloud kms decrypt \ --location=us-central1 \ --keyring=app-secrets \ --key=app-encryption-key \ --ciphertext-file=config.json.enc \ --plaintext-file=config-decrypted.jsonThe --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:
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.
# Create a BigQuery dataset encrypted with a CMEK keybq mk --dataset \ --default_kms_key=projects/my-project/locations/us-central1/keyRings/app-secrets/cryptoKeys/bq-key \ my-project:sensitive_dataThe 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.
# Create an asymmetric signing keygcloud 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 artifactgcloud 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.sigThe 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
- Separate key rings by environment and sensitivity tier, not just by application โ a production key ring should never share IAM bindings with a development one.
- Grant
cloudkms.cryptoKeyEncrypterDecrypternarrowly, scoped to the specific key a workload actually needs, never at the key ring or project level as a shortcut. - Enable automatic rotation on every key with a genuine long-term data protection requirement โ a key thatโs never rotated is a growing liability, since a single key compromise event exposes the full history of data ever encrypted with it.
- Log and alert on key disable/destroy operations specifically โ these are catastrophic, hard-to-reverse (destruction has a mandatory delay before itโs irreversible, disable is instant) operations that deserve tighter monitoring than routine encrypt/decrypt calls.
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.