Asterrr's Handbook

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 ownedAWS managedCustomer managed
Where it livesService's own account, invisible to youYour account, alias aws/<service>Your account
Key policyNone you can seeWritten by AWS, read-onlyYours
RotationService decidesEvery year, automatic, can't changeOff by default; automatic every 90–2,560 days, plus on demand
Usable by other accountsNoNoYes, through the key policy
Disable, schedule deletionNoNoYes
Shows in your CloudTrailNoYesYes
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 specKey usageNotes
SYMMETRIC_DEFAULT (AES-256-GCM)Encrypt and decryptThe only type AWS services use for server-side encryption. Never leaves KMS unencrypted
RSA 2048, 3072, 4096Encrypt and decrypt, or sign and verifyDownload the public key to encrypt or verify outside AWS
ECC NIST (P-256, P-384, P-521), ECC SECG P-256K1Sign and verify, or key agreementSigning for code, JWTs and blockchain-style workloads
ML-DSA 44, 65, 87Sign and verifyPost-quantum signatures
HMAC 224 to 512Generate and verify MACTamper-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

ConditionWhat it restrictsExample use
kms:ViaServiceOnly requests that arrive through a named serviceThe 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 valueTenant acme can decrypt only data encrypted with tenant=acme
kms:EncryptionContextKeysWhich context keys must be presentRequire that every call carries a project key
kms:CallerAccountWhich account's principalsAllow all principals in one account, used with kms:ViaService for AWS managed-style keys
kms:GrantIsForAWSResourceGrants only when an integrated service creates themLet EBS or RDS create grants for your role without letting the role hand out grants itself
kms:RotationPeriodInDaysAllowed rotation period valuesForce a 180-day rotation period across the organization
kms:RequestAlias, kms:ResourceAliasesAccess based on aliasesABAC: 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) or RevokeGrant (an administrator, when access must stop). ListGrants shows 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:

  • GenerateDataKeyWithoutPlaintext returns 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

AutomaticOn demandManual (new key)
Supported onSymmetric keys with KMS-generated materialSymmetric keys, including imported materialAnything: asymmetric, HMAC, custom key store
What changesNew backing material; same key ID, ARN, policySameNew key ID; you repoint aliases and apps
Old ciphertextStill decrypts, old material keptStill decryptsNeeds the old key kept enabled
FrequencyEvery 90 to 2,560 days (default 365)Up to 25 times per keyWhenever 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 RotateKey CloudTrail event and an EventBridge event you can use as audit evidence.
90–2,560 days
Allowed automatic rotation period for customer managed keys. The default is 365.
1 year
Fixed rotation for AWS managed keys.
25
On-demand rotations allowed per KMS key.
7–30 days
Deletion waiting period. The default is 30.
4 KB
Largest plaintext for a direct Encrypt call.

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

  1. The key policy in the key-owning account names the other account (or specific roles in it).
  2. An IAM policy in the other account grants its principal the KMS actions on the key ARN (aliases don't resolve cross-account).
  3. 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 PendingDeletion catches 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:ScheduleKeyDeletion to everyone except a break-glass role is a common guardrail.

Scenarios

Scenario
A healthcare analytics company stores patient extracts in an S3 bucket encrypted with a customer managed KMS key. A data engineering role needs to read the extracts through Amazon Athena. The security team is worried that the role could call the KMS Decrypt API directly on data keys it copies out of object metadata. What is the MOST effective control?
Scenario
A fintech firm signs outbound payment instructions and wants partners to verify the signatures offline. Its auditors also require that the private signing key never leaves an HSM and that every signing operation is logged. Which solution meets these requirements with the LEAST operational effort?
Scenario · choose 2
A security engineer is cleaning up unused customer managed keys and wants to make sure no production workload still depends on a key before it is gone for good. Which TWO steps should the engineer take?

Further reading

On this page