A walkthrough of writing AWS Service Control Policies that restrict resource creation to approved regions while carving out exceptions for global services like IAM, CloudFront, and Route 53. Covers the aws:RequestedRegion condition key, common SCP mistakes, and how to answer this question in a DevOps or cloud security interview.Full interview prep guides and scenario walkthroughs: DevOpsInterview.CloudDaily 30-second interview drills: DevOps Interview Cloud on YouTubeTranscriptAn audit runs across your AWS Organization and the output is ugly. Resources sitting in fifteen regions nobody approved. EC2 instances in ap-southeast-2, an RDS cluster in sa-east-1, a stray VPC in eu-north-1. Nobody remembers creating most of it. That's region sprawl, and it's one of the most common findings in a cloud security review, because by default AWS lets any account with the right IAM permissions spin up resources in any region on earth.Interviewers ask about this because it tests three things at once. Do you understand the difference between IAM policies and Service Control Policies, or SCPs. Do you know how AWS evaluates deny logic across an Organization. And can you actually write a policy that blocks sprawl without breaking services that are inherently global, like IAM or CloudFront. A lot of candidates can say "use an SCP" but fall apart the moment you ask them to handle the global service exceptions. That's the part that separates people who've read about SCPs from people who've actually deployed one.Here's the mental model. An SCP doesn't grant any permissions. It's a guardrail, not a grant. Every account in your Organization already gets whatever IAM policies and roles say it can do. The SCP sits above that, at the Organization or Organizational Unit level, and it filters the maximum available permissions. Think of IAM as the accelerator and SCP as a speed limiter bolted onto the engine. If the SCP denies an action, it doesn't matter what the IAM policy says, even a full admin role can't override an SCP denial. That's why SCPs are the right tool for org-wide guardrails like region restriction, instead of trying to chase down every IAM policy in every account.The core mechanism is a condition key called aws colon RequestedRegion. You write a deny statement with a wildcard action, a wildcard resource, and a condition that says: if the requested region is not in my approved list, deny everything. Something like this. Effect deny, action star, resource star, condition StringNotEquals on aws colon RequestedRegion, with a list of your approved regions, say us-east-1, us-west-2, and eu-west-1 if you're a US and UK facing company. Attach that SCP to the root of the Organization, or to a specific Organizational Unit if you want different rules per business unit, and now any API call targeting a region outside that list gets an explicit deny, no matter which account or which IAM role makes the call.But if you stop there, you break your own Organization. A chunk of AWS services are global and don't have a regional home the way EC2 or RDS do. IAM itself is global. Organizations is global. Route 53 is global. CloudFront is global, and if you're using CloudFront with a custom certificate, that certificate has to live in ACM in us-east-1 specifically, regardless of where your users are. AWS Support, AWS Billing, AWS WAF when attached to CloudFront, and AWS Shield also operate globally or default to us-east-1 under the hood. If your deny statement doesn't carve these out, you'll lock yourself out of managing users, you'll break certificate issuance for your content delivery network, and you'll have people filing tickets within the hour.The fix is to add a NotAction clause, or layer a second condition, that excludes the actions belonging to those global services from the region check. In practice this looks like a list of service prefixes you exclude: iam colon star, organizations colon star, route53 colon star, cloudfront colon star, support colon star, and the global billing and cost management actions. You put those under NotAction in the same deny statement, so the statement reads: deny everything, on every resource, when the region isn't approved, except for these specific global service actions. That's the version that actually survives contact with a real Organization.Let's walk through the logic step by step the way you'd explain it on a whiteboard. First, decide your approved region list based on where your actual customers and compliance requirements sit. For a company serving the US and UK, that might be us-east-1 for primary workloads, us-west-2 for disaster recovery, and eu-west-1 for UK and EU data residency. Second, write the deny statement with action star and resource star, scoped by the RequestedRegion condition using StringNotEquals against that list. Third, add the NotAction exclusion list for IAM, Organizations, Route 53, CloudFront, Support, Trusted Advisor, and the Billing console actions, because none of ...
続きを読む
一部表示