2.2.4 KMS Encryption Keys

KMS — Key Management Service

Key Types

TypeManaged byRotationCross-accountCost
AWS OwnedAWSAutomaticN/AFree
AWS Managed (aws/s3)AWSEvery year (auto)Free
Customer Managed (CMK)CustomerConfigurable$1/month + API calls

Envelope Encryption (data > 4KB)

1. GenerateDataKey → plaintext data key + encrypted data key
2. Encrypt data locally với plaintext key
3. Lưu encrypted data key cùng encrypted data
4. Delete plaintext key from memory

Decrypt:
1. KMS Decrypt encrypted data key → plaintext data key
2. Decrypt data locally với plaintext data key

KMS API Calls

APIMô tảData Size
EncryptEncrypt data trực tiếp bằng KMS key≤ 4KB
DecryptDecrypt data≤ 4KB
GenerateDataKeyTrả về plaintext + encrypted data keyFor envelope encryption
GenerateDataKeyWithoutPlaintextChỉ encrypted data keyDeferred encryption
ReEncryptDecrypt + re-encrypt với key khácKey rotation

KMS Quotas

  • 5,500 → 30,000 requests/second (tùy region và key type)
  • Throttling → ThrottlingException
  • Solutions: Request quota increase, data key caching, SSE-S3

Data Key Caching

Without caching: Every encrypt → KMS API call
With caching: Cache data key → reuse for multiple encrypts
  • AWS Encryption SDK hỗ trợ data key caching
  • Giảm KMS API calls → giảm cost + avoid throttling

KMS API có quota limits. High-throughput encryption → dùng data key caching hoặc SSE-S3 thay vì SSE-KMS.

Exam Tip: Data > 4KB = Envelope Encryption (GenerateDataKey). AWS Managed keys không share cross-account → dùng CMK. KMS throttling → data key caching.