2.2.7 Key Rotation

Key Rotation

Automatic vs Manual

Automatic RotationManual Rotation
Customer Managed Key✅ Every year (configurable)Tạo new key, update alias
AWS Managed Key✅ Every year (by AWS)N/A
Imported Key Material❌ Not supportedTạo new key, re-import
Key IDGiữ nguyênThay đổi
Old dataVẫn decrypt đượcCần giữ old key hoặc re-encrypt

Automatic Rotation

Year 1: Key version 1 (active)
Year 2: Key version 2 (active), version 1 (decrypt only)
Year 3: Key version 3 (active), version 1+2 (decrypt only)
  • Key ID không đổi
  • Old key versions vẫn available để decrypt old data
  • Chỉ new encryptions dùng latest version

Manual Rotation với Alias

1. Tạo new KMS key
2. Update alias trỏ đến new key
3. Application dùng alias → tự động dùng new key
4. Giữ old key để decrypt old data
# Update alias to new key
aws kms update-alias \
  --alias-name alias/my-app-key \
  --target-key-id new-key-id

Cross-Account Encryption

  • AWS Managed keys (aws/s3, aws/ebs) KHÔNG thể share cross-account
  • Phải dùng Customer Managed Keys (CMK)
  • Cần cả Key Policy + IAM Policy (both phải allow)
// Key Policy — cho phép Account B dùng key
{
  "Effect": "Allow",
  "Principal": {"AWS": "arn:aws:iam::222222222222:root"},
  "Action": ["kms:Decrypt", "kms:GenerateDataKey"],
  "Resource": "*"
}

Exam Tip: Automatic rotation giữ nguyên Key ID. Manual rotation cần alias. Cross-account encryption = CMK only (không dùng AWS managed keys). Imported keys không hỗ trợ automatic rotation.