IAM Security Practices
IAM ที่ดีไม่ใช่แค่ Policy เขียนถูก แต่ต้องมีวิธีลด credential ระยะยาว, บังคับ MFA, ตรวจ unused access, validate policy และลด permission ให้ใกล้ Least Privilege อย่างต่อเนื่อง
Use federation and temporary credentials
สำหรับ human users ควรใช้ federation ผ่าน Identity Provider หรือ IAM Identity Center เพื่อให้ผู้ใช้ได้ temporary credentials ผ่าน Role session แทนการถือ IAM User password/access key ถาวร
สำหรับ workload บน AWS เช่น EC2 หรือ Lambda ควรใช้ IAM Role ที่ service นั้น assume ได้โดยตรง Application ที่ใช้ AWS SDK จะค้นหา temporary credentials จาก runtime environment ได้เอง
MFA และ Root protection
- เปิด MFA สำหรับ Root User และ IAM User ที่ยังจำเป็นต้องใช้
- ใช้ phishing-resistant MFA เช่น passkey หรือ security key เมื่อทำได้
- ไม่สร้าง Root Access Key
- เก็บ Root recovery channel ให้ปลอดภัยและเข้าถึงได้เฉพาะผู้รับผิดชอบ
Least Privilege แบบทำได้จริง
เริ่มจาก AWS managed policies เพื่อทดลองได้ แต่ต้องค่อยๆ ลด Permission เป็น customer managed policies ที่เจาะจง use case ใช้ CloudTrail และ Access Analyzer เพื่อดูว่า Action ใดถูกใช้งานจริง แล้วตัด Action ที่ไม่จำเป็นออก
Access Key rotation
ถ้าจำเป็นต้องใช้ long-term Access Key ให้กำหนด owner, use case, rotation plan และ last-used review เมื่อลบหรือ rotate key ต้องทดสอบ workload ที่เกี่ยวข้อง และอย่า commit key ลง Git
IAM Access Analyzer
IAM Access Analyzer ช่วยตรวจ public หรือ cross-account access ของ resource ที่รองรับ และช่วย validate IAM Policy เพื่อหา syntax issue, overly broad access หรือ recommendation ด้าน best practice
Common mistakes
- สร้าง Access Key ให้ทุก developer แล้วไม่มี rotation หรือ owner
- ใช้ wildcard กว้างเพราะ Policy Simulator ผ่านเร็ว
- ไม่ลบ User, Role, Policy หรือ Credential ที่เลิกใช้แล้ว
- ไม่ตรวจ cross-account access หลังแก้ Bucket Policy หรือ Trust Policy
Review questions
- เลือก temporary credentials เป็น default สำหรับ human users และ workloads ได้
- รู้วิธีจัดการ long-term access key เมื่อจำเป็นต้องมี
- ใช้ Access Analyzer หรือ policy validation ตรวจ policy ก่อนใช้งานจริงได้
- ทำไม temporary credentials จึงเป็น best practice ทั้ง human users และ workloads?
- IAM Access Analyzer ช่วยลดความเสี่ยงอะไร?
- least privilege ควรเป็นงานครั้งเดียวหรือกระบวนการต่อเนื่อง?