Lesson 3 Security baseline

AWS Account Setup

AWS Account เป็น boundary ใหญ่ที่สุดของ Resource และ Billing ใน Phase นี้ต้องตั้งค่า Account ให้ปลอดภัยก่อนทำ Lab อื่น: เปิด MFA, หลีกเลี่ยง Root User, ใช้ IAM Identity Center หรือ IAM User อย่างระมัดระวัง และตรวจ Identity ด้วย AWS CLI

Root user ใช้เฉพาะ account-level work เปิด MFA ทันที และไม่สร้าง access key สำหรับใช้งานประจำ
Daily identity ใช้ SSO หรือ IAM user แบบจำกัดสิทธิ์ เริ่มจาก least privilege และใช้ temporary credentials เมื่อทำได้
CLI guardrail ตรวจ Account และ Arn ก่อนสร้าง resource aws sts get-caller-identity ลดโอกาสรันผิด account หรือผิด role

Root User

Root User ถูกสร้างพร้อม AWS Account และมีสิทธิ์สูงสุด ใช้สำหรับงานจำเป็นบางอย่างเท่านั้น เช่น ตั้งค่า Account-level หรือ Recovery บางกรณี ไม่ควรใช้ Root User ทำงานประจำหรือสร้าง Access Key

  • ใช้อีเมลที่ควบคุมโดยเจ้าของ Account หรือองค์กร
  • เปิด MFA ทันที
  • ไม่สร้าง Root Access Key
  • เก็บ recovery information ให้ปลอดภัย

IAM Identity Center หรือ IAM User

สำหรับผู้ใช้จริงในองค์กร ควรใช้ IAM Identity Center เพื่อให้ Login ผ่าน SSO และรับ temporary role session แทนการสร้าง IAM User พร้อม credential ระยะยาว แต่ใน Account เรียนส่วนตัวอาจใช้ IAM User ได้ถ้าจำเป็น โดยต้องเปิด MFA และจำกัด Permission

Security baseline: อย่าเก็บ Access Key ใน Git, source code, screenshot, note app หรือไฟล์ที่ sync ขึ้น cloud storage

AWS CLI และ Profile

AWS CLI เป็นเครื่องมือเรียก AWS API จาก Terminal ใช้เพื่อทดสอบ Identity, Automation และต่อยอดไป Infrastructure as Code ควรแยก Profile ตาม Account หรือ Environment เช่น dev, staging, prod

aws configure --profile learning
aws sts get-caller-identity --profile learning

คำสั่ง aws sts get-caller-identity คืนค่า UserId, Account และ Arn ของ IAM identity ที่ credential ปัจจุบันใช้อยู่ จึงเหมาะสำหรับตรวจว่าคุณกำลังทำงานใน Account และ Role ที่ถูกต้อง

Best practices

  • ใช้ Least Privilege: ให้สิทธิ์เท่าที่ต้องใช้ ไม่ให้สิทธิ์เผื่อ
  • ใช้ temporary credentials ผ่าน Role เมื่อทำได้
  • แยก Profile และตรวจ Account ก่อนรันคำสั่งที่สร้างหรือลบ Resource
  • ตั้งค่า default output เป็น json เพื่อให้ Automation อ่านง่าย

Common mistakes

  • ใช้ Root User ทำทุกอย่างเพราะตั้งค่าง่าย
  • ใช้ Access Key เดียวกันในหลายเครื่อง หลาย Project และไม่ rotate
  • ลืมตรวจ Profile ก่อนรันคำสั่งใน Account จริง

Review questions

Before next lesson
  1. Root user เปิด MFA แล้ว และไม่ได้ใช้ทำงานประจำ
  2. มี identity สำหรับเรียนที่ไม่ใช่ root พร้อม permission ที่เหมาะสม
  3. รัน aws sts get-caller-identity แล้วอ่าน Account/Arn ได้
  1. ทำไมไม่ควรใช้ Root User ทำงานประจำ?
  2. aws sts get-caller-identity ช่วยลดความเสี่ยงอะไร?
  3. IAM Identity Center ช่วยลดการใช้ credential ระยะยาวอย่างไร?