ระดับ 6a · บทที่ 1/5

หลายบัญชีด้วย Organizations — OU, SCP, RCP, Control Tower และ IAM Identity Center

⏱ 60 นาทีลองในAWS Console ↗
ข้อมูลบางส่วนอาจเปลี่ยน — ตรวจสอบก่อนใช้

บทนี้มีข้อมูลที่เปลี่ยนบ่อย (ฟีเจอร์ ราคา ชื่อเมนู) ตรวจกับเว็บทางการก่อนนำไปใช้

เป้าหมาย

ออกแบบโครงหลายบัญชีที่โตได้ถึงหลายสิบบัญชีโดยไม่วุ่น วาง guardrail ด้วย SCP/RCP ที่ "ห้ามได้แม้แต่ admin ของบัญชีลูก" ให้คนเข้าใช้ผ่าน IAM Identity Center อย่างเดียว และรู้ว่า Control Tower ช่วยอะไร/ไม่ช่วยอะไร

ทำไมต้องหลายบัญชี

บัญชี AWS คือขอบเขตการแยกที่แข็งที่สุด — IAM policy ผิดพลาดได้ แต่ข้ามบัญชีต้องมี trust อย่างชัดเจน

แยกบัญชีเพื่อ ตัวอย่าง
blast radius dev โดน compromise ไม่ลาม prod
quota Lambda concurrency ของ dev ไม่กิน prod (quota ส่วนใหญ่ต่อบัญชีต่อ region)
ค่าใช้จ่าย บิลแยกต่อบัญชีโดยไม่ต้องพึ่ง tag 100%
compliance บัญชีที่เก็บข้อมูลบัตรอยู่ใน scope audit แยกจากที่เหลือ

โครง OU ที่แนะนำ (ตามแนวทาง AWS)

Root
├── Security          ← Log Archive (เก็บ CloudTrail/Config ทุกบัญชี), Audit/Security Tooling (delegated admin)
├── Infrastructure    ← Network (Transit Gateway, DNS), Shared Services (CI, ECR กลาง)
├── Workloads
│   ├── Prod          ← บัญชี prod ต่อแอป/ต่อทีม
│   └── NonProd       ← dev, staging
├── Sandbox           ← ทดลองได้อิสระ มีงบจำกัด
└── Suspended         ← บัญชีรอปิด (SCP deny ทุกอย่าง)
  • management account ไม่รัน workload — ใช้แค่ billing, Organizations และงานบริหาร เพราะ SCP ไม่มีผลกับ management account
  • งาน security ให้ delegated administrator ไปอยู่บัญชี Audit (GuardDuty, Security Hub, Config, IAM Access Analyzer)
  • OU ตาม นโยบายที่ต่างกัน (prod vs non-prod) ไม่ใช่ตามผังองค์กร — ผังองค์กรเปลี่ยนบ่อยกว่า

Guardrail: SCP vs RCP vs declarative policy

SCP RCP Declarative policy
คุมใคร principal (user/role) ในบัญชีลูก resource (S3, KMS, SQS, Secrets Manager, STS ฯลฯ) ในบัญชีลูก การตั้งค่าบริการ (เช่น ห้าม public AMI, บังคับ IMDSv2)
ให้สิทธิ์ได้ไหม ไม่ได้ — กำหนดเพดานสูงสุดเท่านั้น ไม่ได้ — เพดานฝั่ง resource ไม่ใช่สิทธิ์ เป็น config
ตัวอย่าง ห้ามใช้ region นอก ap-southeast-1/us-east-1 ห้าม principal นอก org เข้าถึง bucket ของเรา (data perimeter) บังคับ IMDSv2 ทั้ง OU
  • สิทธิ์จริง = IAM policy ∩ SCP ∩ RCP ∩ permission boundary (และไม่มี explicit deny ที่ไหนเลย)
  • ตั้งแต่ ก.ย. 2025 SCP ใช้ภาษา IAM ได้เต็ม (condition/resource ARN ใน Allow, NotResource, wildcard กลาง action) — แต่แนวทางที่ดียังเป็น deny-list: ปล่อย FullAWSAccess แล้วซ้อน SCP แบบ Deny
  • SCP ไม่มีผลกับ service-linked role และ management account
  • ขนาด SCP มีเพดาน (ราว 5,120 ตัวอักษร) และแนบได้จำกัดจำนวนต่อ target → รวม statement อย่างประหยัด

⚠️ ต้องตรวจสอบ: ขนาดสูงสุดของ SCP และจำนวน policy ต่อ OU ดูที่ "Quotas for AWS Organizations" ก่อนออกแบบ

SCP ชุดพื้นฐานที่แทบทุกองค์กรใช้

  1. ห้ามออกจาก organization (organizations:LeaveOrganization)
  2. ห้ามปิด/ลบ CloudTrail, GuardDuty, Config ที่ platform team ตั้งไว้
  3. จำกัด region (ยกเว้นบริการ global เช่น IAM, CloudFront, Route 53, Organizations, Support)
  4. ห้ามสร้าง IAM user/access key (บังคับใช้ Identity Center + role)
  5. ห้ามใช้ root user ของบัญชีลูก (และใช้ centralized root access ลบ root credential ของบัญชีลูก)

Control Tower คืออะไร

  • ตั้ง landing zone ให้: OU Security + บัญชี Log Archive และ Audit, org-wide CloudTrail, Config, IAM Identity Center, และ controls (preventive = SCP/RCP, detective = Config rule, proactive = CloudFormation hook)
  • Account Factory สร้างบัญชีใหม่ที่มี baseline ครบในไม่กี่นาที (ทำเป็นโค้ดได้ด้วย Account Factory for Terraform — AFT)
    ข้อดี ข้อควรรู้
    เริ่มได้เร็ว ตามแนวทาง AWS ตัว Control Tower ไม่คิดเงิน แต่ Config/CloudTrail/S3 ที่มันเปิดคิดเงิน ต่อบัญชี
    อัปเดต baseline ได้จากศูนย์กลาง แก้ resource ที่ Control Tower สร้างเองแล้วเกิด drift ต้อง repair
    controls สำเร็จรูปหลายร้อยตัว องค์กรที่มี Organizations ซับซ้อนอยู่แล้วต้องวางแผนก่อน enroll

IAM Identity Center: ทางเข้าเดียวของคน

  • เชื่อม IdP (Entra ID, Google Workspace, Okta) ผ่าน SAML + SCIM → คนออกจากบริษัท ปิดที่ IdP ที่เดียว
  • permission set = template ของ role → assign ให้ group × account (ไม่ assign รายคน)
  • ตัวอย่างชุด: ReadOnly (ทุกบัญชี), Developer (NonProd), ProdDeployer (Prod, session สั้น 1 ชม.), BreakGlass (ใช้ฉุกเฉิน มี alarm ทุกครั้งที่ใช้)
  • CLI ใช้ aws configure sso → credential ชั่วคราว ไม่มี access key ในเครื่อง

ลองเลย 🧪

profile ที่ใช้ในระดับ 6a (เทียบกับ learn จากระดับ 2) — ตอนเปิด IAM Identity Center ในระดับ 2 AWS สร้าง organization ให้ และบัญชีเดียวของคุณกลายเป็น management account จึงแปลว่า learn = management account

profile ชี้ไปที่ ได้มาอย่างไร
mgmt management account (บัญชีเดียวกับ learn) คัดลอก [profile learn] เป็น [profile mgmt] หรือจะใช้ learn ต่อก็ได้
sandbox บัญชีสมาชิกใหม่สำหรับทดลอง guardrail สร้างด้านล่าง (SCP ไม่มีผลกับ management จึงต้องมีบัญชีนี้)
dev บัญชีที่ใช้ทำแล็บ (จาก 5a-01) ถ้า dev ยังชี้บัญชีเดียวกับ learn ใช้ต่อได้ แต่ควรเปลี่ยน sso_account_id ไปที่บัญชีสมาชิก (จะใช้บัญชี sandbox ก็ได้) เพื่อไม่ให้ management account รันงาน

สร้างบัญชี sandbox (ฟรี — ใช้อีเมลที่ไม่ซ้ำกับบัญชีอื่น เช่น plus address) แล้วรอจนสถานะเป็น SUCCEEDED

aws sso login --profile learn
REQ=$(aws organizations create-account --profile learn --email "[[email protected]]" --account-name sandbox \
  --query CreateAccountStatus.Id --output text)
aws organizations describe-create-account-status --profile learn --create-account-request-id "$REQ" \
  --query "CreateAccountStatus.[State,AccountId]" --output text

ผลที่ควรเห็น: IN_PROGRESS แล้วสักครู่รันซ้ำได้ SUCCEEDED 444455556666 (เลขบัญชี sandbox — จดไว้) → Console IAM Identity Center → AWS accounts → sandbox → Assign users or groups เลือกผู้ใช้ของคุณ + permission set AdministratorAccess แล้วเพิ่มใน ~/.aws/config (ใช้ sso_session เดิมจากระดับ 2)

[profile mgmt]
sso_session = cloud-ladder
sso_account_id = 111122223333
sso_role_name = AdministratorAccess
region = ap-southeast-1

[profile sandbox]
sso_session = cloud-ladder
sso_account_id = 444455556666
sso_role_name = AdministratorAccess
region = ap-southeast-1

(111122223333 = เลขบัญชีใน [profile learn], 444455556666 = เลขบัญชี sandbox)

⚠️ ต้องรันจาก management account (หรือบัญชีที่เป็น delegated admin ของ Organizations) ด้วยสิทธิ์ admin · ห้ามทดลอง SCP กับ OU ที่มีบัญชี prod — สร้าง OU Sandbox-Lab แยก · Organizations และ SCP ไม่คิดเงิน

aws sso login --profile mgmt
export AWS_PROFILE=mgmt AWS_REGION=ap-southeast-1
aws organizations describe-organization --query "Organization.[Id,FeatureSet]" --output text
ROOT=$(aws organizations list-roots --query "Roots[0].Id" --output text)
aws organizations list-organizational-units-for-parent --parent-id "$ROOT" --query "OrganizationalUnits[].[Name,Id]" --output table

ผลที่ควรเห็น: o-xxxxxxxxxx ALL (ต้องเป็น ALL จึงใช้ SCP ได้) และรายชื่อ OU

ทดลอง A — สร้าง OU แล็บและเปิด policy type

aws organizations enable-policy-type --root-id "$ROOT" --policy-type SERVICE_CONTROL_POLICY 2>/dev/null || echo "SCP เปิดอยู่แล้ว"
LAB_OU=$(aws organizations create-organizational-unit --parent-id "$ROOT" --name Sandbox-Lab \
  --query OrganizationalUnit.Id --output text)
echo "ROOT=$ROOT LAB_OU=$LAB_OU" | tee org-lab-ids.txt     # เก็บไว้ใช้ตอนลบ (เหมือน ids.txt ในระดับ 2)

ทดลอง B — SCP จำกัด region + ห้ามออกจาก org + ห้ามสร้าง access key

cat > scp-baseline.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyOutsideApprovedRegions",
      "Effect": "Deny",
      "NotAction": [
        "iam:*", "organizations:*", "sts:*", "support:*", "account:*",
        "cloudfront:*", "route53:*", "route53domains:*", "budgets:*", "ce:*",
        "health:*", "sso:*", "identitystore:*", "waf:*", "wafv2:*", "shield:*",
        "kms:*", "s3:GetAccountPublicAccessBlock", "s3:ListAllMyBuckets"
      ],
      "Resource": "*",
      "Condition": {
        "StringNotEquals": { "aws:RequestedRegion": ["ap-southeast-1", "us-east-1"] },
        "ArnNotLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/OrgPlatformAdmin" }
      }
    },
    {
      "Sid": "DenyLeaveOrg",
      "Effect": "Deny",
      "Action": "organizations:LeaveOrganization",
      "Resource": "*"
    },
    {
      "Sid": "DenyLongLivedKeys",
      "Effect": "Deny",
      "Action": ["iam:CreateUser", "iam:CreateAccessKey"],
      "Resource": "*",
      "Condition": { "ArnNotLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/OrgPlatformAdmin" } }
    }
  ]
}
EOF
SCP_ID=$(aws organizations create-policy --name lab-baseline --type SERVICE_CONTROL_POLICY \
  --description "6a lab baseline guardrails" --content file://scp-baseline.json \
  --query Policy.PolicySummary.Id --output text)
echo "SCP_ID=$SCP_ID" >> org-lab-ids.txt
aws organizations attach-policy --policy-id "$SCP_ID" --target-id "$LAB_OU"
aws organizations list-policies-for-target --target-id "$LAB_OU" --filter SERVICE_CONTROL_POLICY \
  --query "Policies[].Name" --output text

ผลที่ควรเห็น: FullAWSAccess lab-baseline

us-east-1 ถูกอนุญาตไว้เพราะบริการหลายตัว (ACM สำหรับ CloudFront, billing) ต้องใช้ · role OrgPlatformAdmin คือทางออกฉุกเฉินของทีม platform — ในงานจริงต้องมีจริงและมี alarm

ทดลอง C — พิสูจน์ guardrail ย้ายบัญชี sandbox เข้า OU แล็บ (บัญชีที่สร้างด้วย create-account อยู่ใต้ Root)

SANDBOX_ID=$(aws configure get sso_account_id --profile sandbox)
aws organizations move-account --account-id "$SANDBOX_ID" --source-parent-id "$ROOT" --destination-parent-id "$LAB_OU"
aws ec2 describe-vpcs --region eu-west-1 --profile sandbox
aws iam create-user --user-name test-user --profile sandbox

ผลที่ควรเห็น (ตัดมาบางส่วน):

An error occurred (UnauthorizedOperation) when calling the DescribeVpcs operation: You are not authorized to perform this operation. User: arn:aws:sts::444455556666:assumed-role/AWSReservedSSO_AdministratorAccess_.../you is not authorized to perform: ec2:DescribeVpcs with an explicit deny in a service control policy: arn:aws:organizations::...:policy/o-.../service_control_policy/p-...
An error occurred (AccessDenied) when calling the CreateUser operation: User: ... is not authorized to perform: iam:CreateUser on resource: ... with an explicit deny in a service control policy: arn:aws:organizations::...

→ ข้อความบอกตรงๆ ว่าเป็น explicit deny จาก SCP (บางครั้งมี ARN ของ SCP ต่อท้าย) · action ของ EC2 ที่สร้าง/แก้ resource เช่น RunInstances อาจได้ Encoded authorization failure message: ... แทน ถอดดูด้วย aws sts decode-authorization-message --encoded-message [ข้อความ] (ต้องมีสิทธิ์ sts:DecodeAuthorizationMessage) · แม้ role ในบัญชีลูกจะมี AdministratorAccess ก็ทำไม่ได้ — นี่คือพลังของ SCP

ทดลอง D — Identity Center: ตรวจว่าทุก profile ไม่มีคีย์ถาวร

aws sso-admin list-instances --region ap-southeast-1 --query "Instances[0].[InstanceArn,IdentityStoreId]" --output text
for p in mgmt sandbox; do aws sts get-caller-identity --profile $p --query Arn --output text; done
aws configure list --profile sandbox

ผลที่ควรเห็น: ARN แบบ arn:aws:sts::[ACCOUNT]:assumed-role/AWSReservedSSO_AdministratorAccess_xxxx/[you] ของทั้งสองบัญชี (เลขบัญชีต่างกัน) และคอลัมน์ Type ของ access_key เป็น sso · ในองค์กรจริงสร้าง permission set แยก (ReadOnly, Developer ฯลฯ) assign ให้ group ไม่ใช่รายคน (--region ของ sso-admin = region ที่เปิด Identity Center)

เก็บกวาด (ย้ายบัญชีออกก่อน แล้วค่อยถอด policy/ลบ OU)

# ถ้าเปิดเทอร์มินัลใหม่: export AWS_PROFILE=mgmt AWS_REGION=ap-southeast-1 && source org-lab-ids.txt
SANDBOX_ID=$(aws configure get sso_account_id --profile sandbox)
aws organizations move-account --account-id "$SANDBOX_ID" --source-parent-id "$LAB_OU" --destination-parent-id "$ROOT"
aws organizations detach-policy --policy-id "$SCP_ID" --target-id "$LAB_OU"
aws organizations delete-policy --policy-id "$SCP_ID"
aws organizations delete-organizational-unit --organizational-unit-id "$LAB_OU"

บัญชี sandbox เก็บไว้ใช้บทถัดไปได้ (บัญชีเปล่าไม่คิดเงิน) · ถ้าจะปิด: aws organizations close-account --account-id "$SANDBOX_ID" — บัญชีจะอยู่สถานะ SUSPENDED 90 วันก่อนปิดถาวร และ AWS จำกัดจำนวนบัญชีที่ปิดได้ต่อช่วงเวลา ถ้าพัง: PolicyTypeNotEnabledException → ยังไม่ enable SCP · OrganizationalUnitNotEmptyException → ยังมีบัญชีใน OU · AWSOrganizationsNotInUseException → บัญชีนี้ไม่ใช่สมาชิก org หรือไม่ใช่ management

กับดักที่เจอบ่อย

อาการ สาเหตุ / แก้
ใส่ SCP region แล้ว IAM/Route 53/CloudFront พังทั้งบัญชี ลืมยกเว้นบริการ global ใน NotAction — ทดสอบใน Sandbox OU ก่อนเสมอ
แนบ SCP แล้ว management account ยังทำได้ทุกอย่าง ถูกต้อง SCP ไม่มีผลกับ management — อย่ารัน workload ที่นั่น
ถอด FullAWSAccess แล้วทุกอย่างถูก deny SCP เป็น allow-list โดยธรรมชาติ ถ้าไม่มี Allow เลยก็ไม่มีสิทธิ์ — ใช้ FullAWSAccess + Deny ซ้อน
ล็อกตัวเองออก (lock-out) SCP deny ไม่มีทางออก — ใส่เงื่อนไขยกเว้น role ฉุกเฉินและเก็บ break-glass ไว้
บิล Config/CloudTrail พุ่งหลังเปิด Control Tower 50 บัญชี ค่าใช้จ่ายต่อบัญชีคูณจำนวนบัญชี — ใช้ Config periodic recording สำหรับ resource ที่เปลี่ยนบ่อย และประเมินก่อน enroll
คนยังมี IAM user ในบัญชีลูก ห้ามด้วย SCP และย้ายทุกคนไป Identity Center ผูก group

สรุปจำง่าย

บัญชีคือกำแพงที่แข็งที่สุด — OU ตามนโยบาย ไม่ตามผังองค์กร — management account ไม่รันงาน — SCP คุม principal, RCP คุม resource, ไม่มีอันไหนให้สิทธิ์ — FullAWSAccess + Deny-list ทดสอบใน sandbox ก่อน — คนเข้าผ่าน Identity Center ด้วย group × permission set เท่านั้น