What “encrypted at rest” usually means

Most of the time it means someone ticked a box. The disk volume or the bucket is encrypted with a key the platform manages, and the checkbox on the compliance spreadsheet turns green. That is not worthless. It covers a stolen drive, a decommissioned array that gets resold, a snapshot that lands in the wrong account. It does nothing against the more common threat: a process or a person with legitimate read access to the storage service. The platform decrypts transparently for anyone it considers authorized, so the encryption never gets in their way.
If you want encryption to be a control and not a label, the design question is where the keys live, who can use them, and what happens when you need to change them. Envelope encryption handles all three reasonably well, and that’s why the major cloud KMS products are built around it.
The two-layer idea
You use two kinds of keys. A data encryption key (DEK) encrypts the actual data, one DEK per object, file, row group or tenant, whatever granularity you pick. A key encryption key (KEK) encrypts the DEKs. The wrapped DEK is stored next to the ciphertext. The KEK stays inside a KMS or HSM and never leaves it in plaintext.
The first reason for this design is practical, not security. KMS services only want to handle small payloads. AWS KMS Encrypt accepts at most 4096 bytes of plaintext, so you cannot send a 2 GB backup through it. Instead you ask for a fresh data key, encrypt locally with a fast library, and keep only the wrapped copy:
import boto3
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
import os
kms = boto3.client("kms")
r = kms.generate_data_key(
KeyId="alias/billing-data",
KeySpec="AES_256",
EncryptionContext={"tenant": "acme", "object": "invoices/2026-11.csv"},
)
dek, wrapped = r["Plaintext"], r["CiphertextBlob"]
nonce = os.urandom(12)
ct = AESGCM(dek).encrypt(nonce, data, b"invoices/2026-11.csv")
del dek # best effort; Python will not zero it for you
store(wrapped, nonce, ct)
Decrypting reverses it: send wrapped to kms.decrypt with the same encryption context, get the DEK back, decrypt locally. Every decrypt is a KMS API call, which means every decrypt is an authorization decision and a CloudTrail line. That audit trail is the part people underrate. Without it you know the data is encrypted. With it you know who asked for the key and when.
Binding ciphertext to its context
The encryption context in that call does real work. KMS uses it as additional authenticated data, so a wrapped key issued for tenant acme will not unwrap if you present it with tenant globex. It is also logged in clear, which makes it useful for detection and for IAM conditions such as kms:EncryptionContext:tenant.
Do the same thing on the data side. AES-GCM takes associated data that is authenticated but not encrypted, and the object’s identifier is a good candidate. Without it, an attacker who can write to your storage can swap one valid record for another and your decryption will happily succeed. NIST SP 800-38D defines GCM and is explicit that the authentication covers the AAD as well as the ciphertext. Binding the ID costs nothing and kills a whole class of substitution bugs.
A runnable version without a cloud account
To check the mechanics I wrote a small script using the Python cryptography package, with RFC 3394 AES key wrap standing in for the KMS. It seals a record, rotates the KEK by rewrapping, and tries two things that should fail. I ran it in a throwaway container. The output is below.

The screenshot shows real output from that script. Two lines matter here. The ciphertext hash is identical before and after the rotation, so the bulk data was never touched. And a record moved to a different object ID fails with InvalidTag even though the key is correct.
Rotation without downtime
This is where people get confused, because “rotate the key” means two different jobs.
Rotating the KEK is cheap if you built the hierarchy properly. You decrypt each DEK with the old KEK and wrap it with the new one. The bulk data stays where it is. Vault’s transit engine calls this rewrap, and AWS KMS has ReEncrypt. A billion objects means a billion small operations on 40-byte blobs (a wrapped 256-bit DEK under RFC 3394 is 40 bytes, as the output above shows), which you can run in the background at whatever pace your KMS quota allows.
AWS’s automatic rotation is a related but weaker thing. It makes new key material for the same key ID, on a 365-day period by default and configurable between 90 and 2560 days, and keeps the old material so existing ciphertext still decrypts. Nothing gets re-encrypted. That is fine for hygiene and for auditors who want to see a rotation date. It does not limit the damage from a leaked key, because old material stays usable for everything it ever protected.
Rotating a DEK means re-encrypting the data, and that is expensive. You do it when you have a reason: a suspected exposure, an employee with DEK access leaving, or a cryptographic limit. The limit is real for GCM. With random 96-bit nonces, SP 800-38D caps you at 2^32 encryptions under one key before the collision probability gets uncomfortable. A DEK per object makes that a non-issue. One long-lived DEK for a busy table does not.
To roll without downtime, store a key ID or version with every record. Reads pick the key by that ID, writes always use the current one, and a background job migrates old records. The version field has to exist from day one. Retrofitting it later means guessing which key encrypted which row. That is miserable.
The hierarchy, and who gets which permission
A realistic hierarchy has three levels. A root key sits in an HSM or the cloud KMS, and a per-service or per-tenant KEK is wrapped by it. Below that, DEKs are generated per object. SP 800-57 Part 1 describes this kind of key hierarchy and the reasoning behind separating key-wrapping from data keys.
The permission split is the real security benefit. The storage admin can read and copy ciphertext but cannot call kms:Decrypt. The application role can decrypt only with its own KEK and only with a matching encryption context. The KMS administrator can manage and disable keys but has no access to the data. Compromise any one of those roles alone and you still do not have plaintext.
Deleting a KEK also gives you something close to crypto-shredding. If a tenant leaves and you delete their KEK after the scheduled waiting period (7 to 30 days in AWS KMS), every DEK wrapped under it becomes unrecoverable. That works as deletion for backups you cannot practically scrub, assuming no copy of the plaintext KEK or any unwrapped DEK exists elsewhere. Check that assumption before you tell a regulator about it.
Where this goes wrong
Caching DEKs in memory for performance is fine, with a TTL and a usage cap. The AWS Encryption SDK has a caching layer with limits on both. Caching them forever turns your hierarchy into one long-lived key again.
Logging is the sneaky one. A DEK in a debug log or a core dump undoes everything above. Treat plaintext key material as a secret with a lifetime of seconds.
And test the failure path. Disable the KEK in a staging environment and watch what your application does. A common mistake is a fallback that stores plaintext “so the system keeps working” when the KMS call fails.
