هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
الهدف
The SAP-C02 exam asks again and again how to govern many accounts. Build the core yourself: an organization with OUs for Security, Workloads/Prod and Workloads/Dev, service control policies (deny leaving the organization, allow only two regions, protect the audit trail), an organization-wide CloudTrail into a locked S3 bucket, and a budget alert. You test that an SCP really blocks an admin.
قبل أن تبدأ
- Use a personal practice account (not your company's). Organizations, SCPs and one trail are free; S3 storage costs cents.
- AWS CLI v2 with credentials of the management account:
aws sts get-caller-identity. - To test SCPs you need a member account: create one in task 2 (it needs a new email address; a
+labalias of your email works).
المهام
ضع علامة على المهمة عندما تنتهي منها. متصفحك فقط يتذكر ذلك.
- Create the organization with all features and enable the policy type
SERVICE_CONTROL_POLICY. - Create the OUs
Security,Workloads, and insideWorkloadsthe OUsProdandDev. Create a member account and move it toDev. - Write the SCP
deny-leave-and-regions: denyorganizations:LeaveOrganization, and deny everything outsideeu-central-1andme-central-1(except global services like IAM, Organizations, CloudFront, Route 53, Support, STS). - Write the SCP
protect-cloudtrail: denycloudtrail:StopLogging,DeleteTrail,UpdateTrailfor everyone except a break-glass role. - Attach both SCPs to the
WorkloadsOU. In the member account, try to start an EC2 instance inus-east-1and to stop the trail; both must fail with explicit deny in a service control policy. - Create an organization trail for all accounts and regions into an S3 bucket with versioning, block public access and a bucket policy for CloudTrail.
- Create a monthly budget of 10 USD with an email alert at 80 %.
- Explain in two lines when you would use Control Tower instead of building this by hand.
تحقّق من عملك
aws organizations list-organizational-units-for-parent --parent-id $(aws organizations list-roots --query 'Roots[0].Id' --output text)
aws organizations list-policies-for-target --target-id $WORKLOADS_OU --filter SERVICE_CONTROL_POLICY --query 'Policies[].Name'
aws cloudtrail describe-trails --query 'trailList[].{name:Name, org:IsOrganizationTrail, multi:IsMultiRegionTrail}'
aws budgets describe-budgets --account-id $(aws sts get-caller-identity --query Account --output text) --query 'Budgets[].BudgetName'- The root has
SecurityandWorkloads;WorkloadshasProdandDev. - Both SCPs are attached to
Workloads. - The trail shows
org: trueandmulti: true. - In the member account,
aws ec2 run-instances --region us-east-1 ...fails withexplicit deny in a service control policy.
تلميحات
اعرض التلميحات
- SCPs never give rights; they set the maximum. They do not apply to the management account itself — that is why you test in a member account.
- Region lock:
"Condition": {"StringNotEquals": {"aws:RequestedRegion": ["eu-central-1", "me-central-1"]}}with aNotActionlist of global services. - Exception for the break-glass role:
"Condition": {"ArnNotLike": {"aws:PrincipalARN": "arn:aws:iam::*:role/BreakGlass"}}. - Log in to the member account with the role
OrganizationAccountAccessRole(made automatically).
الحل
اعرض الحل
- and 2. The organization and the OUs.
aws organizations create-organization --feature-set ALL ROOT=$(aws organizations list-roots --query 'Roots[0].Id' --output text) aws organizations enable-policy-type --root-id $ROOT --policy-type SERVICE_CONTROL_POLICY aws organizations create-organizational-unit --parent-id $ROOT --name Security WORKLOADS_OU=$(aws organizations create-organizational-unit --parent-id $ROOT --name Workloads --query 'OrganizationalUnit.Id' --output text) aws organizations create-organizational-unit --parent-id $WORKLOADS_OU --name Prod DEV_OU=$(aws organizations create-organizational-unit --parent-id $WORKLOADS_OU --name Dev --query 'OrganizationalUnit.Id' --output text) aws organizations create-account --email you+lab@example.com --account-name lab-dev aws organizations move-account --account-id NEW_ID --source-parent-id $ROOT --destination-parent-id $DEV_OU - and 4. The two SCPs.deny-leave-and-regions.json
{ "Version": "2012-10-17", "Statement": [ {"Sid": "NoLeave", "Effect": "Deny", "Action": "organizations:LeaveOrganization", "Resource": "*"}, {"Sid": "OnlyTwoRegions", "Effect": "Deny", "NotAction": ["iam:*", "organizations:*", "sts:*", "cloudfront:*", "route53:*", "support:*", "budgets:*", "ce:*"], "Resource": "*", "Condition": {"StringNotEquals": {"aws:RequestedRegion": ["eu-central-1", "me-central-1"]}}} ] }protect-cloudtrail.json{ "Version": "2012-10-17", "Statement": [{ "Sid": "ProtectTrail", "Effect": "Deny", "Action": ["cloudtrail:StopLogging", "cloudtrail:DeleteTrail", "cloudtrail:UpdateTrail"], "Resource": "*", "Condition": {"ArnNotLike": {"aws:PrincipalARN": "arn:aws:iam::*:role/BreakGlass"}} }] }for p in deny-leave-and-regions protect-cloudtrail; do ID=$(aws organizations create-policy --name $p --type SERVICE_CONTROL_POLICY --description "$p" --content file://$p.json --query 'Policy.PolicySummary.Id' --output text); aws organizations attach-policy --policy-id $ID --target-id $WORKLOADS_OU; done - Test in the member account (assume
OrganizationAccountAccessRolefirst).aws ec2 run-instances --region us-east-1 --image-id ami-0abcdef1234567890 --instance-type t3.micro --dry-run An error occurred (UnauthorizedOperation) ... with an explicit deny in a service control policy - The organization trail (bucket policy from the CloudTrail documentation, with your organization ID).
B=org-trail-$(aws sts get-caller-identity --query Account --output text) aws s3api create-bucket --bucket $B --region eu-central-1 --create-bucket-configuration LocationConstraint=eu-central-1 aws s3api put-bucket-versioning --bucket $B --versioning-configuration Status=Enabled aws s3api put-public-access-block --bucket $B --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true aws s3api put-bucket-policy --bucket $B --policy file://trail-bucket-policy.json aws cloudtrail create-trail --name org-trail --s3-bucket-name $B --is-organization-trail --is-multi-region-trail --enable-log-file-validation aws cloudtrail start-logging --name org-trail - The budget.
aws budgets create-budget --account-id $(aws sts get-caller-identity --query Account --output text) --budget '{"BudgetName":"monthly-10","BudgetLimit":{"Amount":"10","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST"}' --notifications-with-subscribers '[{"Notification":{"NotificationType":"ACTUAL","ComparisonOperator":"GREATER_THAN","Threshold":80},"Subscribers":[{"SubscriptionType":"EMAIL","Address":"you@example.com"}]}]' - Control Tower builds this landing zone for you (log archive and audit accounts, guardrails, Account Factory, drift detection). Use it for a new multi-account setup; build by hand when you must fit an existing organization or need full control of every policy. Clean up: detach and delete the SCPs, close the member account, delete the trail and the bucket.
ملاحظاتي
لا توجد ملاحظات بعد.