Lab 8: Security Baseline
Lab นี้สร้าง security baseline สำหรับ workload ตัวอย่าง: จัดการ database credential, ใช้ KMS กับ storage, เพิ่ม WAF rule และเปิด threat detection/recommendations
Learning objectives
- เก็บ Database Credential ใน Secrets Manager
- ใช้ KMS เข้ารหัส S3 และ EBS
- สร้าง AWS WAF Rule พื้นฐาน
- เปิด GuardDuty และตรวจ Finding ตัวอย่าง
- เปิด Security Hub และอ่าน recommendations
Prerequisites
- มี AWS Account สำหรับ Lab และตั้ง Budget แล้ว
- มี S3 bucket หรือ test bucket ที่สร้างใหม่ได้
- มี EC2/EBS test resource หรือเข้าใจว่าจะสร้างแล้วลบหลังจบ Lab
- มี ALB หรือ CloudFront distribution ถ้าจะ associate WAF Web ACL
- มี permission สำหรับ KMS, Secrets Manager, WAF, GuardDuty และ Security Hub
Step 1: Store database credential in Secrets Manager
aws secretsmanager create-secret \
--name learning/db/credential \
--description "Learning database credential" \
--secret-string '{"username":"learning_user","password":"ChangeMe-UseStrongPassword"}'
ให้ application role อ่าน secret ด้วย permission เฉพาะ secret ARN ที่ต้องใช้เท่านั้น
Step 2: Use KMS with S3
- Create Customer Managed Key หรือใช้ key ที่องค์กรกำหนด
- เปิด default encryption ของ S3 bucket เป็น SSE-KMS
- Upload object และตรวจ properties ว่า encryption เป็น SSE-KMS
Step 3: Use encryption with EBS
- สร้าง EBS volume test พร้อม encryption enabled
- เลือก KMS key ที่เหมาะสม
- Attach กับ test EC2 เฉพาะถ้าต้องทดสอบ mount จริง
Step 4: Create a basic WAF rule
- Create Web ACL สำหรับ Regional resource หรือ CloudFront ตาม workload
- Add AWS Managed Rules เช่น Core rule set
- Add rate-based rule สำหรับ path สำคัญ เช่น login endpoint
- เริ่มจาก Count mode แล้วดู sampled requests ก่อนเปลี่ยนเป็น Block
Step 5: Enable GuardDuty
- เปิด GuardDuty ใน Region ที่ใช้ Lab
- ดูหน้า Findings และลอง Generate sample findings ถ้าใช้ Console
- อ่าน finding type, severity, affected resource และ recommended action
Step 6: Enable Security Hub
- เปิด Security Hub
- Enable AWS Foundational Security Best Practices standard
- ดู failed controls และจด remediation ที่เกี่ยวกับ S3, IAM, CloudTrail หรือ Security Groups
Expected results
- มี secret สำหรับ database credential พร้อม ARN
- S3 bucket ใช้ SSE-KMS
- EBS test volume เปิด encryption
- WAF Web ACL มี managed rule และ/หรือ rate-based rule
- GuardDuty แสดง findings หรือ sample findings ได้
- Security Hub แสดง recommendations/controls ให้ตรวจต่อได้
Verification steps
aws secretsmanager describe-secret --secret-id learning/db/credential
aws s3api get-bucket-encryption --bucket YOUR_BUCKET_NAME
aws guardduty list-detectors
aws securityhub get-enabled-standards
Troubleshooting
| อาการ | แนวทางแก้ |
|---|---|
| Application อ่าน secret ไม่ได้ | ตรวจ IAM role, secret ARN, KMS permission และ Region |
| S3 upload fail หลังใช้ SSE-KMS | ตรวจว่า principal มี kms:GenerateDataKey และ kms:Decrypt ตาม use case |
| WAF block traffic ปกติ | กลับไป Count mode และดู sampled requests ก่อนปรับ rule |
| Security Hub ไม่มีผลทันที | รอ evaluation cycle และตรวจว่า standard ถูก enabled แล้ว |
Cleanup procedures
- Delete test secret ถ้าไม่ใช้ต่อ
- Delete test EBS volume
- Detach/Delete WAF Web ACL หรือ rule ที่สร้างเพื่อ Lab
- Disable GuardDuty/Security Hub เฉพาะ account Lab ถ้าไม่ต้องการเสียค่าใช้จ่ายต่อ
- Schedule deletion ของ KMS key เฉพาะ key ที่สร้างเพื่อ Lab และไม่มี data สำคัญผูกอยู่
Mini quiz
- ทำไมต้องระวังการลบ KMS key?
- WAF Count mode ช่วยลดความเสี่ยงอย่างไร?
- Security Hub recommendation ควรถูกนำไปใช้ใน workflow ใด?