Security
AWS Key Management Service (KMS)
Key Management Service, Encryption Keys, Envelope Encryption, Key Rotation
Tổng quan
AWS KMS là dịch vụ quản lý encryption keys được AWS quản lý hoàn toàn. KMS giúp bạn tạo, quản lý và sử dụng các keys để mã hóa data một cách dễ dàng và an toàn.
Hiểu đơn giản: KMS làm gì?
Tại sao cần KMS thay vì tự quản lý keys?
- ✅ AWS bảo vệ keys trong hardware an toàn
- ✅ Keys tự động rotate (thay mới)
- ✅ Dễ dàng set permissions (ai được dùng key)
- ✅ Audit trail (biết ai đã decrypt data)
- ✅ Tích hợp sẵn với 100+ AWS services
Các loại KMS Keys
1. Phân loại theo người quản lý
So sánh
| Type | Ai tạo | Bạn thấy? | Control | Cost |
|---|---|---|---|---|
| AWS Owned | AWS | ❌ | ❌ | Free |
| AWS Managed | AWS | ✅ | Limited | Free |
| Customer Managed | Bạn | ✅ | Full | $1/month |
[!TIP] Best Practice: Dùng Customer Managed Keys cho sensitive data để có full control và audit.
2. Phân loại theo loại key
| Key Type | Mô tả | Use Case |
|---|---|---|
| Symmetric | 1 key cho cả encrypt + decrypt (AES-256) | Mặc định, dùng cho AWS services |
| Asymmetric | Public + Private key pair (RSA, ECC) | Digital signatures, encrypt outside AWS |
| HMAC | Hash-based Message Authentication | Verify integrity |
Envelope Encryption
KMS dùng Envelope Encryption để encrypt data lớn một cách hiệu quả:
Workflow:
- Encrypt: Call KMS
GenerateDataKey→ Get Data Key (plaintext + encrypted) - Use plaintext Data Key to encrypt your data locally
- Store encrypted Data Key + encrypted data together
- Decrypt: Call KMS
Decryptto get plaintext Data Key → Decrypt data locally
Key Rotation
Automatic Rotation
Key Policies
Key Policies contrrol ai có thể dùng KMS key:
Key Actions:
kms:Encrypt- Mã hóa datakms:Decrypt- Giải mã datakms:GenerateDataKey- Tạo data key cho envelope encryptionkms:DescribeKey- Xem thông tin keykms:CreateGrant- Cho phép người khác dùng key tạm thời
KMS Integration với AWS Services
Multi-Region Keys
Custom Key Store Options
| Option | Mô tả | Security Level |
|---|---|---|
| Standard KMS | Keys trong AWS managed HSMs | FIPS 140-2 Level 2 |
| CloudHSM Key Store | Keys trong dedicated CloudHSM | FIPS 140-2 Level 3 |
| External Key Store (XKS) | Keys stored outside AWS | Depends on your HSM |
| Imported Key Material (BYOK) | Import your own keys | FIPS 140-2 Level 2 |
So sánh KMS với các services liên quan
| Service | Lưu gì | Dùng khi nào |
|---|---|---|
| KMS | Encryption keys | Encrypt AWS resources (S3, EBS, RDS) |
| CloudHSM | Keys (dedicated hardware) | FIPS Level 3, full control |
| Secrets Manager | Passwords, API keys | DB credentials, auto-rotate |
| Parameter Store | Config, secrets | App config (free) |
| ACM | SSL certificates | HTTPS for websites |
Pricing
| Component | Cost |
|---|---|
| Customer Managed Key | $1/month |
| AWS Managed Key | Free |
| API Calls | $0.03 per 10,000 requests |
| Multi-Region Key | $1/month per replica |
Exam Tips cho Cloud Practitioner
[!IMPORTANT] Keywords để nhớ KMS:
- Managed encryption keys cho AWS services
- Tích hợp với 100+ AWS services (S3, EBS, RDS...)
- FIPS 140-2 Level 2 validated
- All key usage logged in CloudTrail
- Customer Managed Keys = Full control, $1/month
Câu hỏi thường gặp
| Câu hỏi | Trả lời |
|---|---|
| Service nào quản lý encryption keys? | AWS KMS |
| KMS encrypt S3 objects như thế nào? | SSE-KMS (Server-Side Encryption) |
| Ai có thể dùng KMS key? | Định nghĩa bởi Key Policy |
| Làm sao encrypt data > 4KB? | Envelope Encryption (Data Keys) |
| KMS hay CloudHSM cho general use? | KMS (CloudHSM cho FIPS Level 3) |
| Key loại gì dùng phổ biến nhất? | Symmetric (AES-256) |