Sub topic 6
Service control policies: setting permission boundaries
This chapter assumes you can read IAM policy JSON, know how an IAM identity policy allows or denies an action, and have created an organization with OUs and member accounts. Inheritance and evaluation order across the OU tree come in the next chapter. Here the focus is what an SCP is, what it can and cannot do, and how to create and attach one.
What an SCP is
A service control policy (SCP) is an Organizations policy that sets the maximum permissions available to the IAM users and roles in a member account. It is a guardrail, not a grant. An SCP never gives anyone permission to do anything. It only limits what identity-based policies in the account are able to allow.
Because of this, an action succeeds only when both layers agree:
- The SCPs that apply to the account allow the action.
- An IAM policy in the account (identity-based, and where relevant resource-based or a permissions boundary) also allows it.
An administrator in a member account with AdministratorAccess still cannot call an action that an SCP blocks. The account's own administrators cannot remove the SCP either, because SCPs are managed from the management account.
What SCPs affect and what they do not
SCPs apply to every IAM user and role in a member account, including the account's root user. This is why they work as a boundary the account owner cannot step over.
They do not apply to:
- The management account. No SCP restricts it, which is one reason to run no workloads there.
- Service-linked roles, which AWS services use to act on your behalf.
- Principals outside your organization. An SCP on your account does not restrict an external account that you grant access to through a resource policy.
- A small set of actions that AWS exempts, such as certain root-user account tasks. Check the current documentation for the list.
Enabling SCPs and the default policy
SCPs require the organization to have all features enabled (not only consolidated billing). The SCP policy type must also be enabled on the root. Terraform sets this with enabled_policy_types = ["SERVICE_CONTROL_POLICY"]. With the CLI you use aws organizations enable-policy-type.
When SCPs are enabled, Organizations attaches an AWS-managed policy named FullAWSAccess to the root, to every OU and to every account. It allows all actions. Nothing is blocked until you add a deny, or detach FullAWSAccess and replace it with a narrower allow list. The next chapter explains why the first approach is usually better.
Anatomy of an SCP
An SCP uses the same JSON grammar as an IAM policy, with a smaller set of supported elements. You will mainly use:
| Element | Use in an SCP |
|---|---|
| `Effect` | `Deny` for guardrails. `Allow` to define an allow list. |
| `Action` / `NotAction` | The API actions the statement covers, or everything except those listed. |
| `Resource` | Usually `*`. Support for narrower resource ARNs depends on the effect, so check current limits. |
| `Condition` | Restricts when the statement applies, for example by Region or tag. |
| `Sid` | An optional label for the statement. |
SCPs have no Principal element, because they apply to the whole account. They have size limits, such as a maximum document size of 5,120 characters and a small number of policies attached directly to each target. Whitespace counts toward the size, so compact JSON helps.
A first SCP: deny leaving the organization
A member account with enough IAM permission can call organizations:LeaveOrganization and walk away, taking its billing and guardrails with it. This policy blocks that call.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyLeaveOrganization",
"Effect": "Deny",
"Action": "organizations:LeaveOrganization",
"Resource": "*"
}
]
}Save it as deny-leave-org.json. Then create the policy and attach it to an OU. Every account in that OU, and in any OU below it, is covered.
aws organizations create-policy \
--name DenyLeaveOrg \
--description "Block member accounts from leaving the organization" \
--type SERVICE_CONTROL_POLICY \
--content file://deny-leave-org.json
aws organizations attach-policy \
--policy-id p-examplepolicyid111 \
--target-id ou-examplerootid111-exampleouid111The create-policy call returns the real policy ID. Use that value in attach-policy. The target can be the root (r-...), an OU (ou-...) or a single account (12-digit ID).
A second SCP: restrict Regions
A common data-residency guardrail denies everything outside approved Regions. Global services have no Region of their own, or are served from a fixed Region, so the policy exempts them with NotAction.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyOutsideApprovedRegions",
"Effect": "Deny",
"NotAction": [
"iam:*",
"organizations:*",
"route53:*",
"cloudfront:*",
"support:*",
"budgets:*",
"sts:*"
],
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": ["eu-west-1", "eu-central-1"]
}
}
}
]
}Read it as: "Deny every action except those listed, when the requested Region is not one of these two." The statement uses a double negative, so reading it aloud is a good review step. The list of exempt services is the part that most often needs maintenance, since new global services appear over time.
Working with SCPs in practice
Some habits prevent most problems:
- Attach to OUs, not accounts. Per-account attachments become hard to audit. Put the policy on the OU whose accounts share the need.
- Use clear names and
Sidvalues. The AccessDenied error from an SCP-blocked call says the denial came from a service control policy, but it does not always name which one. Meaningful names help your search. - Keep policies small and single-purpose. A policy that denies one thing is easier to reason about, reuse and remove than one that bundles ten rules.
- Check CloudTrail when something is denied unexpectedly. The error message for an SCP denial states that "an explicit deny in a service control policy" caused it.
- Version them as code. Store the JSON in a repository and apply it with the CLI or Terraform, so changes get reviewed.
Common mistakes
- Expecting an SCP to grant access. An allow in an SCP does nothing unless an IAM policy also allows the action.
- Testing from the management account. SCPs do not apply there, so a blocked action will appear to work.
- Detaching
FullAWSAccesswithout a replacement. The account then has no allowed actions, and every call fails, including the ones you need to repair the mistake. - Forgetting service-linked roles and external principals. A guardrail that seems complete may still leave these paths open.
- Locking out the Regions-based exemption list. Denying
iam:*orsts:*by Region can break sign-in and role assumption, which is why the example exempts them.
Exercise
A developer in a member account has an IAM policy allowing s3:*. An SCP attached to the account's OU denies s3:DeleteBucket. The same developer runs the delete from the management account using an identical policy. What happens in each case, and why?
Show answer
In the member account the delete fails, because the explicit deny in the SCP caps what the account's IAM policies can allow, and the account's own administrators cannot override it. From the management account the delete can succeed, because SCPs do not apply to the management account. The IAM policy allows the action there, and nothing restricts it.
Exercise
You attach an SCP containing only Allow for ec2:* to an OU and also detach FullAWSAccess from that OU. Can a user in an account in that OU, who has AdministratorAccess, create an S3 bucket?
Show answer
No. With FullAWSAccess detached, the only SCP allow is for ec2:*, so S3 actions are not allowed by the SCP layer. The AdministratorAccess policy cannot exceed that boundary, so the call is denied.