متقدم
البحث فيالمعامل
طريقة البحث
  • ابحث عن مهمة أو أداة (lvm، selinux، ‎@podman)؛ وصفِّ حسب المستوى والكتاب أو الدورة.
  • مع مربع بحث فارغ، الفلتر وحده يعرض المعامل — مثلًا كل المعامل الصعبة لدورة واحدة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

معمل 2.1AWS Solutions Architect Professional, الفصل 2

Multi-account guardrails: AWS Organizations, OUs, SCPs and a central log trail

المستوى
صعب
60 دقيقة
الأجهزة
an AWS account you own that can become an Organizations management account, AWS CLI v2
الحالة
لم يبدأ

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

الهدف

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 +lab alias of your email works).

المهام

  1. Create the organization with all features and enable the policy type SERVICE_CONTROL_POLICY.
  2. Create the OUs Security, Workloads, and inside Workloads the OUs Prod and Dev. Create a member account and move it to Dev.
  3. Write the SCP deny-leave-and-regions: deny organizations:LeaveOrganization, and deny everything outside eu-central-1 and me-central-1 (except global services like IAM, Organizations, CloudFront, Route 53, Support, STS).
  4. Write the SCP protect-cloudtrail: deny cloudtrail:StopLogging, DeleteTrail, UpdateTrail for everyone except a break-glass role.
  5. Attach both SCPs to the Workloads OU. In the member account, try to start an EC2 instance in us-east-1 and to stop the trail; both must fail with explicit deny in a service control policy.
  6. Create an organization trail for all accounts and regions into an S3 bucket with versioning, block public access and a bucket policy for CloudTrail.
  7. Create a monthly budget of 10 USD with an email alert at 80 %.
  8. 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 Security and Workloads; Workloads has Prod and Dev.
  • Both SCPs are attached to Workloads.
  • The trail shows org: true and multi: true.
  • In the member account, aws ec2 run-instances --region us-east-1 ... fails with explicit 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 a NotAction list 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).

الحل

اعرض الحل
  1. 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
  2. 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
  3. Test in the member account (assume OrganizationAccountAccessRole first).
    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
  4. 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
  5. 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"}]}]'
  6. 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.

ملاحظاتي

لا توجد ملاحظات بعد.

دروس هذا المعمل

الأوامر في هذا المعمل