Secrets and Certificates
Credentials, API keys และ certificates ต้องมี lifecycle ชัดเจน: store, access, rotate, audit และ revoke โดยไม่ฝังไว้ใน Git หรือ AMI
Secrets Manager
AWS Secrets Manager เหมาะกับ secrets ที่ต้องการ rotation, versioning และ integration กับ services เช่น RDS ตัวอย่างเช่น database username/password, third-party API token หรือ application signing secret
aws secretsmanager create-secret \
--name prod/app/db \
--description "Database credential for prod app" \
--secret-string '{"username":"appuser","password":"REPLACE_ME"}'
Systems Manager Parameter Store
Parameter Store เหมาะกับ configuration และ secret ที่เรียบง่ายกว่า เช่น feature flag, endpoint, AMI ID หรือ secure string ข้อดีคือใช้งานง่ายและผูกกับ IAM/KMS ได้ แต่ automatic rotation ไม่ใช่จุดแข็งหลักเท่า Secrets Manager
Secrets Manager vs Parameter Store
| หัวข้อ | Secrets Manager | Parameter Store |
|---|---|---|
| เหมาะกับ | Credentials ที่ต้อง rotate | Config และ secure parameters |
| Rotation | รองรับ rotation workflow | ต้องออกแบบเองเป็นหลัก |
| Cost model | คิดค่าบริการต่อ secret/API ตามเงื่อนไข | มี standard tier และ advanced tier |
| ตัวอย่าง | RDS password, API token | App endpoint, environment value, simple secure string |
AWS Certificate Manager
AWS Certificate Manager ใช้ provision และ manage TLS certificates สำหรับ services เช่น ALB, CloudFront และ API Gateway สำหรับ public certificate ที่ออกโดย ACM และใช้กับ integrated services, ACM ช่วยต่ออายุ certificate อัตโนมัติเมื่อ validation ยังถูกต้อง
Best practices
- ให้ application อ่าน secret ด้วย IAM role และ Least Privilege
- อย่า print secret ลง log, error message หรือ build output
- ตั้ง naming convention เช่น
/prod/payments/db/passwordหรือprod/payments/db - แยก secrets ระหว่าง dev, staging และ prod
- ใช้ ACM certificate กับ HTTPS endpoint แทน self-managed certificate เมื่อเหมาะสม
Common mistakes
- เก็บ secrets ใน Terraform state โดยไม่ระวัง เพราะ state อาจมี plaintext sensitive values
- ใช้ secret เดียวกันทุก environment ทำให้ blast radius ใหญ่
- ไม่มี rotation plan เมื่อมีคนออกจากทีม หรือ credential อาจรั่ว
Review questions
- Secrets Manager เหมาะกว่า Parameter Store เมื่อไร?
- ทำไมไม่ควรเก็บ secret ใน source code?
- ACM ช่วยลดงาน operation เรื่อง TLS อย่างไร?