KMS key management
KMS key types and ownership, key policies, grants and condition keys, envelope encryption, rotation, multi-Region and cross-account keys, and safe deletion.
Exam tasks: 5.2.1 (choose KMS and server- or client-side encryption), 5.3.3 (AWS generated key material), 5.3.5 (create and manage KMS keys across one or many Regions)
The decision: which kind of KMS key protects this data, who is allowed to use and administer it (and through which service), and how does it rotate, move between accounts and Regions, and eventually retire?
Picking the key
Who owns the key
| AWS owned | AWS managed | Customer managed | |
|---|---|---|---|
| Where it lives | Service's own account, invisible to you | Your account, alias aws/<service> | Your account |
| Key policy | None you can see | Written by AWS, read-only | Yours |
| Rotation | Service decides | Every year, automatic, can't change | Off by default; automatic every 90–2,560 days, plus on demand |
| Usable by other accounts | No | No | Yes, through the key policy |
| Disable, schedule deletion | No | No | Yes |
| Shows in your CloudTrail | No | Yes | Yes |
| Typical signal | "Encryption with no management" | "Audit, no control needed" | "Separation of duties", "revoke", "cross-account", "custom rotation" |
Exam signal
A question that says a DynamoDB table, SQS queue or EventBridge bus "must be encrypted, with no additional cost or management" is satisfied by the default AWS owned key. As soon as the question adds "the security team must be able to audit and revoke access", move to a customer managed key.
Key specs and what each can do
| Key spec | Key usage | Notes |
|---|---|---|
SYMMETRIC_DEFAULT (AES-256-GCM) | Encrypt and decrypt | The only type AWS services use for server-side encryption. Never leaves KMS unencrypted |
| RSA 2048, 3072, 4096 | Encrypt and decrypt, or sign and verify | Download the public key to encrypt or verify outside AWS |
| ECC NIST (P-256, P-384, P-521), ECC SECG P-256K1 | Sign and verify, or key agreement | Signing for code, JWTs and blockchain-style workloads |
| ML-DSA 44, 65, 87 | Sign and verify | Post-quantum signatures |
| HMAC 224 to 512 | Generate and verify MAC | Tamper-evident tokens without sharing a secret |
- Key usage is fixed at creation. An RSA key created for signing can't later encrypt.
- Asymmetric and HMAC keys don't rotate automatically or on demand. "Rotate" them by creating a new key and moving the alias.
- Asymmetric private keys never leave KMS. If a partner needs to verify your signatures offline, give them the
public key from
GetPublicKey.
Key policies
Every KMS key has exactly one key policy, and nothing can use the key unless that policy allows it, directly or by delegating to IAM.
{
"Sid": "LetAccountIamDecide",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::444455556666:root" },
"Action": "kms:*",
"Resource": "*"
}- That default statement doesn't grant access to everyone in the account. It lets IAM policies in account 444455556666 grant access. Remove it and only principals named in the key policy can use the key.
- Split duties in the policy: key administrators (
kms:Create*,kms:Put*,kms:ScheduleKeyDeletion,kms:EnableKeyRotation) and key users (kms:Encrypt,kms:Decrypt,kms:GenerateDataKey*,kms:ReEncrypt*). Administrators usually shouldn't be able to decrypt. - The policy lockout safety check refuses a policy that would stop the caller from managing the key. If you bypass it and lock yourself out, only AWS Support can help, and only if the account root still has access.
- IAM Access Analyzer reports key policies that grant access outside your organization.
Condition keys worth knowing
| Condition | What it restricts | Example use |
|---|---|---|
kms:ViaService | Only requests that arrive through a named service | The analytics role can decrypt only via s3.eu-west-1.amazonaws.com, never by calling KMS directly |
kms:EncryptionContext:<key> | Only requests with a specific context value | Tenant acme can decrypt only data encrypted with tenant=acme |
kms:EncryptionContextKeys | Which context keys must be present | Require that every call carries a project key |
kms:CallerAccount | Which account's principals | Allow all principals in one account, used with kms:ViaService for AWS managed-style keys |
kms:GrantIsForAWSResource | Grants only when an integrated service creates them | Let EBS or RDS create grants for your role without letting the role hand out grants itself |
kms:RotationPeriodInDays | Allowed rotation period values | Force a 180-day rotation period across the organization |
kms:RequestAlias, kms:ResourceAliases | Access based on aliases | ABAC: roles may use any key aliased alias/finance-* |
ViaService and the direct call
A role that can call kms:Decrypt directly can pull the data key for any ciphertext it holds, bypassing the
bucket policy. When the requirement is "only through S3" or "only through Secrets Manager", add kms:ViaService.
An IAM policy that only restricts s3:* leaves the KMS path open.
Grants
A grant gives one grantee principal a subset of operations on one key, without editing the key policy.
- Services use grants behind the scenes: EBS creates a grant when a volume attaches, RDS when an instance is created, Secrets Manager and Lambda for their own use.
- Grants support encryption context constraints, so a grant can be limited to one volume or one tenant.
- Grants are eventually consistent. The creator gets a grant token to use the grant immediately.
- Remove them with
RetireGrant(the grantee or retiring principal, when the work is done) orRevokeGrant(an administrator, when access must stop).ListGrantsshows who holds grants, which is worth checking after a compromise because a grant can outlive a deleted IAM policy.
Envelope encryption and encryption context
KMS encrypts at most 4 KB directly. Everything bigger uses a data key:
GenerateDataKeyWithoutPlaintextreturns only the encrypted copy. Use it when the component creating the key isn't the one that will encrypt, such as a control plane preparing keys for workers.- Encryption context is non-secret key-value data bound to the ciphertext as additional authenticated data. Decrypt fails unless the same context is supplied, every CloudTrail entry records it, and key policies and grants can condition on it.
- Don't put secrets in the context: it appears in plaintext in CloudTrail.
- Heavy request rates can hit KMS throttling. Use S3 Bucket Keys, and data key caching in the AWS Encryption SDK, rather than asking for a quota increase first.
Rotation
| Automatic | On demand | Manual (new key) | |
|---|---|---|---|
| Supported on | Symmetric keys with KMS-generated material | Symmetric keys, including imported material | Anything: asymmetric, HMAC, custom key store |
| What changes | New backing material; same key ID, ARN, policy | Same | New key ID; you repoint aliases and apps |
| Old ciphertext | Still decrypts, old material kept | Still decrypts | Needs the old key kept enabled |
| Frequency | Every 90 to 2,560 days (default 365) | Up to 25 times per key | Whenever you like |
- Rotation never re-encrypts existing data and doesn't rotate data keys. It only changes what new encryptions use.
- For multi-Region keys you enable rotation and trigger on-demand rotation on the primary; KMS copies new material to the replicas.
- KMS emits a
RotateKeyCloudTrail event and an EventBridge event you can use as audit evidence.
Multi-Region keys
- A primary key and replicas in other Regions share key ID and key material, so ciphertext from one decrypts in the others without a cross-Region call.
- Each replica has its own key policy, grants, aliases and tags. You set the replica's policy when you create it, and later edits to the primary's policy don't propagate, so review each one.
- You can promote a replica to primary (
UpdatePrimaryRegion), for example after losing the primary Region. - Use them for client-side encryption of data that moves between Regions, global tables with the Database Encryption SDK, and signing in several Regions. AWS services that re-encrypt on replication (S3 Replication, EBS snapshot copy, RDS cross-Region replicas) work fine with separate single-Region keys.
- A primary can't be deleted while replicas exist.
Multi-Region by default
"Encrypt all data with one key that works everywhere" isn't a best practice. Data sovereignty rules often require that ciphertext is not decryptable outside its Region. Choose multi-Region keys only when a workload needs the same ciphertext in more than one Region.
Cross-account use
- The key policy in the key-owning account names the other account (or specific roles in it).
- An IAM policy in the other account grants its principal the KMS actions on the key ARN (aliases don't resolve cross-account).
- The other account can't see the key in its console and can't manage it.
Common pattern: a central security account owns customer managed keys per data domain, and workload accounts get
use-only permissions, often combined with kms:ViaService so the keys only work through the storage service.
Disabling and deleting keys
- Disable first if you suspect a key is unused. Watch CloudTrail for failed requests, then schedule deletion.
- An EventBridge rule or CloudWatch alarm on use attempts during
PendingDeletioncatches forgotten dependencies before the key is gone. - Deleting a KMS key makes every ciphertext it protects permanently unreadable. AWS can't recover it.
- An SCP that denies
kms:ScheduleKeyDeletionto everyone except a break-glass role is a common guardrail.
Scenarios
kms:ViaService makes the key usable by that role only when S3 calls KMS on its behalf, so direct Decrypt calls
fail. Rotation changes future material but doesn't limit who can decrypt. SSE-S3 removes the separate KMS
permission entirely, making the problem worse. Object ACL permissions are unrelated to key use.
An asymmetric signing key keeps the private key inside KMS HSMs, logs every Sign call in CloudTrail, and lets anyone verify with the public key. HMAC verification needs the secret itself, which can't be shared out of KMS. A data key pair gives the application the plaintext private key, and a key stored in Secrets Manager was generated and used outside an HSM.
Disabling is reversible and shows who still calls the key. Scheduling deletion with an alarm on use attempts gives a final safety net, and you can cancel during the waiting period. Deleting an alias leaves the key intact. Rotation doesn't re-encrypt anything. A key always has a key policy; you can't simply remove it.
Further reading
Domain 5 · Data protection
18% of the exam. Who controls the keys, how traffic stays encrypted, how stored data survives deletion and ransomware, and how secrets and sensitive fields stay out of sight.
Key material and HSMs
Imported versus KMS-generated key material, rotating and expiring imported keys, CloudHSM clusters, and KMS custom key stores backed by CloudHSM or an external key manager.