5.2.1. Encryption at Rest: KMS Key Types and Policies
💡 First Principle: Encryption at rest converts data into ciphertext that requires a key to read. The security of encryption at rest depends entirely on the security of the key — so key management is the real challenge. AWS KMS solves key management by keeping keys inside hardware security modules (HSMs) that never expose the raw key material outside the HSM.
KMS Key Types:
| Key Type | Managed By | Cost | Use Case |
|---|---|---|---|
| AWS Owned Keys | AWS | Free | Default encryption for many services (S3 SSE-S3, DynamoDB default) |
| AWS Managed Keys | AWS (auto-rotation) | Free | Per-service keys (aws/s3, aws/rds); less control |
| Customer Managed Keys (CMK) | You | ~$1/key/month | Full control: custom key policy, rotation control, cross-account use |
Key Policies: Unlike IAM policies, KMS key policies are resource-based policies that must explicitly grant access. Without a key policy statement allowing an account, even the root user cannot use the key.
The default key policy for a CMK includes a statement allowing the root account principal — which means IAM policies can then control access. Without this root account statement, you could permanently lose access to the key.
Envelope Encryption: The KMS Encrypt API sends the plaintext to KMS over the network and accepts at most 4 KB, so it suits only small secrets. For data of any real size, services use envelope encryption:
KMS generates a data key (via GenerateDataKey). Your application uses the data key to encrypt the actual data. KMS then encrypts the data key using your CMK. The encrypted data key is stored alongside the encrypted data. To decrypt: call KMS to decrypt the data key, then use the plaintext data key to decrypt the data. The CMK never leaves KMS.
Service-Specific Encryption:
| Service | SSE Option | Key Management |
|---|---|---|
| S3 | SSE-S3 | AWS managed (free) |
| S3 | SSE-KMS | AWS or CMK (auditable, CloudTrail logs every decrypt) |
| S3 | SSE-C | Customer provides key with each request |
| EBS | Default encryption | AWS managed or CMK |
| RDS | Storage encryption | AWS managed or CMK (must be set at creation) |
| DynamoDB | Default | AWS owned (free) or CMK |
Key Rotation: Automatic rotation is available for symmetric CMKs. When enabled, KMS rotates the key material annually but keeps the old material to decrypt data encrypted with previous versions. The key ID and ARN stay the same — applications need no changes.
Manual rotation: creating a new key and pointing an alias at it is a manual rotation. The old key must stay enabled, because each ciphertext remains bound to the key that encrypted it; disabling or deleting it makes that data undecryptable. For symmetric keys, call Decrypt without a KeyId so KMS uses the key that encrypted the ciphertext. Passing the alias fails once the alias points to the new key.
Other key controls:
- AWS managed keys: you can view their key policy but not change it, and AWS rotates them every year. Use a customer managed key when you need your own policy or grants.
- Grants: give a principal temporary, scoped permission to use a key (for example, an AWS service acting on your behalf) without editing the key policy. Grants can be retired or revoked.
- Disable vs. delete: disabling a key is reversible. Deletion is scheduled with a waiting period of 7–30 days (default 30) and can be cancelled during that window; afterwards the key, and any data encrypted only under it, is unrecoverable.
- EBS: an existing unencrypted volume can't be encrypted in place. Snapshot it, copy the snapshot with encryption enabled, then create a new volume from the copy. EBS encryption by default is a per-Region account setting that applies only to volumes created afterwards.
⚠️ Exam Trap: RDS encryption must be enabled at database creation time — you cannot encrypt an existing unencrypted RDS instance. The workaround: create an encrypted snapshot of the unencrypted instance (by copying the snapshot with encryption enabled), then restore from the encrypted snapshot. This creates a new encrypted RDS instance, and you switch your application to the new endpoint.
Reflection Question: An auditor requires that every KMS API call (encrypt, decrypt, generate data key) be logged for compliance. Your S3 buckets use SSE-KMS with a CMK. What is automatically logged, where, and how do you verify this?