Mục tiêu học tập
- Hiểu cách hoạt động của AWS Organizations
- Nắm vững cấu trúc OU và account hierarchy
- Biết cách sử dụng Service Control Policies (SCPs)
1. Tổng quan AWS Organizations
Định nghĩa
AWS Organizations cho phép quản lý tập trung nhiều AWS accounts, bao gồm:
- Consolidated billing
- Hierarchical grouping (OUs)
- Policy-based management
- Automated account provisioning
Cấu trúc cơ bản
2. Organizational Units (OUs)
Best Practice OU Structure
OU Design Principles
- Flat structure: Tránh quá nhiều levels (max 5)
- Purpose-based: Nhóm theo mục đích sử dụng
- Policy inheritance: SCPs inherit từ parent
- Separation of duties: Tách biệt responsibilities
3. Service Control Policies (SCPs)
Cách hoạt động
SCP Inheritance
SCP Strategies
Strategy 1: Deny List (Recommended)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyLeaveOrg",
"Effect": "Deny",
"Action": "organizations:LeaveOrganization",
"Resource": "*"
},
{
"Sid": "DenyRootUser",
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {
"StringLike": {
"aws:PrincipalArn": "arn:aws:iam::*:root"
}
}
}
]
}
Strategy 2: Allow List
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:*",
"s3:*",
"rds:*"
],
"Resource": "*"
}
]
}
Common SCP Use Cases
| Use Case | SCP Action |
|---|---|
| Prevent leaving organization | Deny organizations:LeaveOrganization |
| Restrict regions | Deny all actions in non-approved regions |
| Prevent root user usage | Deny * with root principal |
| Require encryption | Deny if encryption disabled |
| Prevent public S3 | Deny s3:PutBucketPublicAccessBlock |
Example: Region Restriction SCP
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyNonApprovedRegions",
"Effect": "Deny",
"NotAction": [
"cloudfront:*",
"iam:*",
"route53:*",
"support:*"
],
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": [
"ap-southeast-1",
"us-east-1"
]
}
}
}
]
}
4. Consolidated Billing
How it works
Benefits
- Volume discounts: Usage aggregated across accounts
- Reserved Instance sharing: RIs apply across organization
- Savings Plans sharing: SPs apply across organization
- Single payment method: One bill, one payment
5. Organization Features
All Features vs Consolidated Billing Only
| Feature | All Features | Billing Only |
|---|---|---|
| Consolidated billing | ✓ | ✓ |
| SCPs | ✓ | ✗ |
| Tag policies | ✓ | ✗ |
| Backup policies | ✓ | ✗ |
| AI services opt-out | ✓ | ✗ |
| Service access | ✓ | ✗ |
Delegated Administrator
6. AWS Control Tower
Relationship with Organizations
7. CloudTrail Organizational Trail
Khái niệm
Organizational trail là CloudTrail trail được tạo từ management account (hoặc từ delegated administrator cho CloudTrail) và tự động áp dụng cho MỌI member account trong Organization — kể cả account được tạo/join sau này.
Đặc điểm quan trọng (hay ra thi)
- Tạo 1 lần, phủ toàn org: không cần vào từng account tạo trail riêng — giảm operational overhead.
- Member account KHÔNG thể can thiệp: member account thấy organizational trail (read-only) trong console/API của mình nhưng không thể tắt (StopLogging), sửa, hay xoá trail đó. Đây chính là cơ chế chống tampering — kể cả admin của member account cũng không tắt được audit log.
- Log tập trung 1 nơi: toàn bộ events từ mọi account ghi về một S3 bucket duy nhất ở account trung tâm, phân theo prefix
AWSLogs/<org-id>/<account-id>/.... - New account tự động được cover: account mới join org → trail apply ngay, không cần thao tác thêm.
Kiến trúc log tập trung
Bucket policy cho central S3 bucket
S3 bucket ở account trung tâm phải có bucket policy cho phép service principal cloudtrail.amazonaws.com ghi log, giới hạn theo ARN của org trail bằng aws:SourceArn (chống confused deputy):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailWrite",
"Effect": "Allow",
"Principal": {"Service": "cloudtrail.amazonaws.com"},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::central-audit-logs/AWSLogs/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"aws:SourceArn": "arn:aws:cloudtrail:ap-southeast-1:111111111111:trail/org-trail"
}
}
}
]
}
Best practice
- Log về S3 bucket trong Log Archive account riêng (không phải management account) — tách quyền truy cập log khỏi quyền quản trị org. AWS Control Tower làm chính xác điều này khi setup landing zone: tự tạo organizational trail ghi vào Log Archive account.
- Bật log file validation + S3 Object Lock/versioning để tăng tính bất biến của audit trail.
- Delegate quản trị CloudTrail cho security account (delegated administrator) để giảm việc dùng management account.
Exam keyword: "centralize audit logs across all accounts in the organization" + "prevent member accounts from tampering/disabling logging" → CloudTrail organizational trail (không phải tạo trail từng account + SCP thủ công).
8. aws:PrincipalOrgID trong Resource Policy
Vấn đề
Muốn cho tất cả accounts trong Organization truy cập một resource (S3 bucket, SQS queue, SNS topic, KMS key, Secrets Manager secret, Lambda, VPC endpoint policy...) — nếu liệt kê từng account ID trong resource policy thì policy phình to, và phải cập nhật mỗi khi thêm/bớt account.
Giải pháp: condition key aws:PrincipalOrgID
Global condition key so sánh Organization ID của principal đang gọi với giá trị chỉ định. Chỉ cần một condition, mọi principal (IAM user/role) thuộc bất kỳ account nào trong org đều match — account mới join org tự động có quyền, account rời org tự động mất quyền.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowOrgWideAccess",
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::shared-artifacts",
"arn:aws:s3:::shared-artifacts/*"
],
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "o-a1b2c3d4e5"
}
}
}
]
}
Lưu ý: "Principal": "*" kết hợp condition aws:PrincipalOrgID không phải là public — chỉ principals đã authenticated thuộc org mới thoả condition (anonymous access không có org ID nên bị loại).
aws:PrincipalOrgPaths — giới hạn theo OU
Khi chỉ muốn cho phép accounts trong một OU cụ thể (không phải cả org), dùng aws:PrincipalOrgPaths với đường dẫn OU:
{
"Condition": {
"ForAnyValue:StringLike": {
"aws:PrincipalOrgPaths": "o-a1b2c3d4e5/r-ab12/ou-ab12-11111111/*"
}
}
}
- Path có dạng
<org-id>/<root-id>/<ou-id>/...; wildcard*ở cuối bao gồm cả sub-OU bên dưới. - Là multivalued key → phải dùng set operator
ForAnyValue/ForAllValues.
So sánh nhanh
| Condition key | Phạm vi | Use case |
|---|---|---|
aws:PrincipalOrgID | Toàn bộ organization | Share resource cho mọi account trong org |
aws:PrincipalOrgPaths | Một OU (và sub-OU) cụ thể | Chỉ Production OU được truy cập |
aws:PrincipalAccount | Một account | Grant cho account đơn lẻ |
Exam keyword: "grant access to all accounts in the organization" / "without listing/maintaining individual account IDs" → resource policy với
aws:PrincipalOrgID. Nếu đề bài giới hạn "only accounts in the Production OU" →aws:PrincipalOrgPaths.
9. Câu hỏi ôn tập
-
Management Account có bị ảnh hưởng bởi SCPs không?
Xem đáp án
Không — Management account không bị SCPs apply, kể cả SCP ở root OU. Best practice: không deploy workloads trong management account. Chỉ dùng management account cho organization management, billing, Control Tower. Tất cả workloads nên ở member accounts — chịu SCP governance.
-
SCP inheritance hoạt động như thế nào?
Xem đáp án
SCPs áp dụng hierarchically: Root → OU → Sub-OU → Account. Account phải có SCP allow ở tất cả các level cha để action được phép. Ví dụ: Root SCP deny us-west-2 → tất cả accounts kể cả trong OU con đều không dùng us-west-2 được. OU SCP restrict thêm trong phạm vi Root SCP đã cho phép. Không thể dùng OU SCP để "unblock" những gì Root SCP đã block.
-
Deny List vs Allow List SCP strategy, cái nào được recommend?
Xem đáp án
AWS recommend Deny List (default allow all, explicitly deny specific). Lý do: easier to start — mặc định tất cả permissions available, chỉ thêm Deny khi cần restrict (ví dụ: deny region access, deny specific services). Allow List (default deny all, explicitly allow everything needed) phức tạp hơn, rủi ro block unexpected services, maintenance overhead cao. Deny List phổ biến hơn trong production Organizations.
-
Reserved Instances có thể share across organization không?
Xem đáp án
Có — với consolidated billing, RI và Savings Plans của một account trong Organization tự động apply (discount) sang accounts khác nếu account đó có matching usage và RI không được dùng hết. Có thể disable sharing per account nếu muốn (RI credit sharing settings trong Billing). Đây là lý do consolidated billing tiết kiệm: unused RIs không "wasted" mà benefit entire org.
-
Delegated Administrator dùng để làm gì?
Xem đáp án
Cho phép một member account quản lý một AWS service cho toàn bộ Organization (thay vì phải làm từ management account). Ví dụ: delegate GuardDuty admin đến Security account, delegate Config admin đến Audit account, delegate IAM Identity Center admin đến dedicated SSO account. Giảm need access management account, tách concerns — security team manage từ security account riêng.
-
Công ty cần centralize CloudTrail logs của 50 accounts và đảm bảo admin của member account không thể tắt logging. Giải pháp nào ít operational overhead nhất?
Xem đáp án
CloudTrail organizational trail tạo từ management account (hoặc delegated administrator), log về S3 bucket ở Log Archive account. Trail tự động apply cho mọi member account (kể cả account mới join); member account thấy trail nhưng không thể StopLogging/sửa/xoá. So với phương án tạo trail từng account + SCP deny
cloudtrail:StopLogging: organizational trail ít overhead hơn (1 trail duy nhất, không phải maintain 50 trails + SCP), và chống tampering là built-in chứ không phụ thuộc SCP viết đúng. -
Làm sao cho phép tất cả accounts trong Organization đọc một S3 bucket mà không phải liệt kê từng account ID?
Xem đáp án
Dùng bucket policy với condition
aws:PrincipalOrgID:"Condition": {"StringEquals": {"aws:PrincipalOrgID": "o-xxxx"}}kèm"Principal": "*". Chỉ principals authenticated thuộc org thoả condition (không phải public); account mới join org tự động có quyền, account rời org tự động mất — không cần maintain danh sách account IDs. Nếu chỉ muốn giới hạn theo một OU cụ thể → dùngaws:PrincipalOrgPaths(multivalued key, cầnForAnyValue:StringLike) với patho-xxxx/r-xxxx/ou-xxxx/*.
10. Bài tập thực hành
- Tạo AWS Organization với 2 OUs
- Tạo SCP deny specific region
- Setup consolidated billing view
- Explore Control Tower landing zone
Tài liệu tham khảo chính thức
- AWS Organizations User Guide
- Service Control Policies
- AWS Organizations FAQ
- Creating a trail for an organization (CloudTrail)
- AWS global condition context keys (aws:PrincipalOrgID, aws:PrincipalOrgPaths)
Ngày tiếp theo: Multi-Account Patterns