Envelope Encryption, KMS Keys, Policies, Grants, and Rotation
coreintermediateEnvelope encryption uses two keys: a data key that encrypts your actual data, and a KMS key that encrypts (wraps) that data key. KMS never touches your bulk data directly — it only ever handles the small, wrapped data key. A key policy is the resource policy every KMS key must have, controlling who can use it. A grant hands out a narrow, temporary permission on a key without editing that key policy at all.
Think of it as
Think of a data key as the physical key to a filing cabinet, and the KMS key as a safe that stores a copy of that filing-cabinet key. You never put the whole filing cabinet inside the safe — that would be slow and the safe is small. You lock the cabinet key inside the safe, carry the locked key alongside the cabinet, and only open the safe (a single small operation) when you actually need to unlock the cabinet.
What we're doing: See encryption context enforced as authenticated data: an Encrypt call with one context, then a Decrypt call with a different context.
- 1
- The encryption context is not encrypted itself — it travels alongside the ciphertext in plaintext, and shows up in CloudTrail logs for auditing.
- 4
- KMS treats the context as additional authenticated data: changing even one value causes decryption to fail outright, even though it was never secret.
Why this works: Encryption context lets you bind ciphertext to a specific piece of metadata (which table, which tenant) without adding a secret — a mismatch is strong evidence the ciphertext is being used somewhere it should not be, and every use of it is visible in CloudTrail for audit.
Assuming encryption context is a secret credential
Wrong
Better
What you see: The value chosen as "secret" context shows up in plaintext in CloudTrail logs for every encrypt/decrypt call, defeating the intended confidentiality.
Why: Encryption context is authenticated but never encrypted — KMS logs it in full on every API call specifically so it is auditable, which makes it the wrong place for anything meant to stay confidential.
- Key policy
- One per key, always required — the baseline authorization document
- Edited directly; changes apply to everyone the policy names
- The natural place for long-lived, broad access
- Grant
- Any number per key, all optional — layered on top of the key policy
- Created and retired independently, without touching the key policy
- The natural place for narrow, temporary, or automated access
The three KMS key types
Together
Remember: Envelope encryption: a data key encrypts your data, a KMS key encrypts the data key. Every key needs exactly one key policy; grants add temporary access without editing it. Encryption context is authenticated but not secret — it appears in CloudTrail. Customer managed keys support cross-account sharing and optional rotation (365-day default); AWS managed keys don't share cross-account and rotate automatically every year regardless.
See also: kms authorization iam and key policy · encryption at rest vs in transit

