AWS Secrets Manager
Cất mật khẩu, API key
Lưu mật khẩu, API key, thông tin kết nối DB một cách mã hoá; có thể tự xoay vòng mật khẩu định kỳ.
- Chi phí$ Rẻ
- Độ khó●●●●●
- Để không có tốn tiền?Có
- AWS quản lý
- Có trong đềSAA · DVA · SOA
Hình dungNhư két sắt mật khẩu tự đổi mã mỗi tháng.
Secrets Manager đứng ở đâu trong hệ thống?
Gọi tới Secrets Manager
Secrets Manager gọi tới
Một ví dụ thật, từng bước
- Mật khẩu database đang nằm trong file .env và đã từng bị lộ lên GitHub.
- Bạn lưu thông tin đăng nhập database vào Secrets Manager, được mã hoá bằng KMS.
- Ứng dụng có IAM role được phép đọc đúng bí mật đó, và lấy mật khẩu khi khởi động thay vì đọc từ file.
- Bạn bật xoay mật khẩu tự động mỗi 30 ngày; Secrets Manager đổi mật khẩu trong RDS và cập nhật bí mật.
- Ứng dụng luôn đọc bản mới nhất nên không bị gián đoạn khi mật khẩu đổi.
Khi nào nên dùng
✓ Nên dùng khi
Không muốn để mật khẩu trong code/biến môi trường.
✗ Không nên dùng khi
Cấu hình không bí mật, cần rẻ → Parameter Store (Systems Manager).
Ví dụ hay gặp
- Lưu mật khẩu database và tự xoay vòng
- Lưu API key của bên thứ ba
- Chia sẻ secret chéo tài khoản
Secrets Manager, Systems Manager hay KMS?
| Lưu gì | Bí mật: mật khẩu, API key | Cấu hình và bí mật đơn giản (Parameter Store) | Khoá mã hoá |
|---|---|---|---|
| Tự xoay | Có, sẵn cho RDS/Aurora | Không | Xoay khoá, không đổi mật khẩu |
| Sao chép sang region khác | Có | Không | Multi-Region key |
| Tính tiền | Theo bí mật/tháng + số lần gọi | Bản tiêu chuẩn miễn phí | Theo khoá/tháng + số lần gọi |
Tốn bao nhiêu tiền?
- Cách tính: $0,40/secret/tháng + $0,05/10.000 API call.
- Miễn phí: Dùng thử 30 ngày cho secret mới.
Gọi API mỗi request thay vì cache trong ứng dụng; secret không còn dùng vẫn tính phí; cấu hình không bí mật nên để ở Parameter Store (miễn phí).
Đề có “xoay mật khẩu database tự động”, “ít vận hành nhất” → Secrets Manager. Chỉ lưu cấu hình, muốn rẻ → Parameter Store. Đừng chọn KMS để “lưu mật khẩu”: KMS giữ khoá mã hoá, không xoay mật khẩu database.
Thử sức với câu hỏi thi thật
1A company uses Amazon RDS for PostgreSQL databases for its data tier. The company must implement password rotation for the databases. Which solution meets this requirement with the LEAST operational overhead?
- AStore the password in AWS Secrets Manager. Enable automatic rotation on the secret.
- BStore the password in AWS Systems Manager Parameter Store. Enable automatic rotation on the parameter.
- CStore the password in AWS Systems Manager Parameter Store. Write an AWS Lambda function that rotates the password.
- DStore the password in AWS Key Management Service (AWS KMS). Enable automatic rotation on the customer master key (CMK).
Xem đáp án
Đáp án đúng: A
Secrets Manager có sẵn chức năng tự xoay mật khẩu cho RDS, chỉ cần bật. Parameter Store không tự xoay; xoay khoá KMS không đổi mật khẩu database.
2A company has a custom application with embedded credentials that retrieves information from an Amazon RDS MySQL DB instance. Management says the application must be made more secure with the least amount of programming effort. What should a solutions architect do to meet these requirements?
- AUse AWS Key Management Service (AWS KMS) customer master keys (CMKs) to create keys. Configure the application to load the database credentials from AWS KMS. Enable automatic key rotation.
- BCreate credentials on the RDS for MySQL database for the application user and store the credentials in AWS Secrets Manager. Configure the application to load the database credentials from Secrets Manager. Create an AWS Lambda function that rotates the credentials in Secrets Manager.
- CCreate credentials on the RDS for MySQL database for the application user and store the credentials in AWS Secrets Manager. Configure the application to load the database credentials from Secrets Manager. Set up a credentials rotation schedule for the application user in the RDS for MySQL database using Secrets Manager.
- DCreate credentials on the RDS for MySQL database for the application user and store the credentials in AWS Systems Manager Parameter Store. Configure the application to load the database credentials from Parameter Store. Set up a credentials rotation schedule for the application user in the RDS for MySQL database using Parameter Store.
Xem đáp án
Đáp án đúng: C
Lưu thông tin đăng nhập trong Secrets Manager, ứng dụng đọc từ đó thay vì để trong code, rồi đặt lịch xoay mật khẩu bằng tính năng có sẵn cho RDS, không phải tự viết Lambda.
Câu hỏi thường gặp
Xoay mật khẩu tự động hoạt động thế nào?
Secrets Manager theo lịch gọi một hàm Lambda để tạo mật khẩu mới, cập nhật vào database và lưu phiên bản mới. Với RDS, Aurora, Redshift và DocumentDB có sẵn mẫu hoặc chế độ do AWS quản lý nên gần như không phải viết code.
Secrets Manager tính tiền thế nào?
Mỗi bí mật tính phí theo tháng, cộng với số lần gọi API. Lưu nhiều cấu hình không bí mật ở đây sẽ tốn tiền không cần thiết; nên để chúng ở Parameter Store.
Đề thi AWS hay hỏi gì về Secrets Manager?
Không để mật khẩu trong code hay biến môi trường dạng chữ thường, xoay mật khẩu database tự động, chọn giữa Secrets Manager và Parameter Store theo chi phí và tính năng, và mã hoá bằng KMS.