Sub topic 3
Attaching policies and how inheritance works
This chapter assumes you know the structure of an organization (root, organizational units, accounts) and can read IAM policy JSON. It also assumes you have enabled the SCP and RCP policy types on the root, as shown earlier in this tutorial. Here you learn where policies attach, how they flow down the tree, and what that means for the permissions a principal ends up with.
Where policies attach
You can attach an SCP or an RCP to three kinds of target:
- The root. The policy applies to every OU and member account in the organization.
- An OU. The policy applies to every account in that OU and in all OUs below it.
- An account. The policy applies to that one account.
Attaching is a separate step from creating. A policy that exists but is attached nowhere has no effect. The same policy can be attached to many targets, and each target can have several policies.
aws organizations create-policy \
--name DenyLeavingOrganization \
--description "Prevent member accounts from leaving the organization" \
--type SERVICE_CONTROL_POLICY \
--content file://deny-leave-org.json
# Attach to an OU
aws organizations attach-policy \
--policy-id p-examplepolicyid \
--target-id ou-exam-ple12345
# Attach the same policy to a single account
aws organizations attach-policy \
--policy-id p-examplepolicyid \
--target-id 111122223333The --target-id value tells Organizations what kind of target you mean. Root IDs start with r-, OU IDs with ou-, and account IDs are 12 digits.
Inspecting what is attached
Two commands answer the questions you will ask most often. The first lists the policies attached to one target. The second lists every target a policy is attached to.
# Which SCPs are attached directly to this OU?
aws organizations list-policies-for-target \
--target-id ou-exam-ple12345 \
--filter SERVICE_CONTROL_POLICY
# Where is this policy attached?
aws organizations list-targets-for-policy \
--policy-id p-examplepolicyidUse --filter RESOURCE_CONTROL_POLICY to list RCPs instead. Neither command shows inherited policies. list-policies-for-target returns only what is attached directly to the target, so to see the full set that applies to an account you must also check every parent. Walk upward with list-parents --child-id <id> until you reach the root, and list the policies at each step.
aws organizations list-parents --child-id 111122223333
aws organizations list-parents --child-id ou-exam-ple12345The default policies
When you enable a policy type, Organizations attaches an AWS managed policy to every root, OU, and account.
| Policy type | Managed policy attached by default | What it does |
|---|---|---|
| SCP | `FullAWSAccess` | Allows all actions on all resources |
| RCP | `RCPFullAWSAccess` | Allows all actions by all principals on supported resources |
These policies do not grant anything by themselves. They keep the "allow" side of evaluation open so that your deny statements are the only thing that restricts access. Without an allow at a given level, nothing is permitted, as the next section explains.
How inheritance works
Policies are not merged into one document. Evaluation treats each level of the tree as a separate gate that a request must pass. An account's effective maximum permissions are the intersection of what every level allows.
For a principal in an account, AWS checks the following, from the root down to the account:
- The root must have an SCP that allows the action.
- Each OU on the path must have an SCP that allows the action.
- The account itself must have an SCP that allows the action.
- No SCP at any of those levels may explicitly deny the action.
Within one level, the SCPs attached to that target are combined. Any allow statement among them satisfies that level, and any matching deny blocks the request. Across levels, an allow is needed at every level.
Three consequences follow from this model.
- Lower levels can only narrow. An SCP on a child OU cannot grant something a parent withheld. If the root has no allow for an action, no lower attachment can bring it back.
- A deny cannot be overridden. A deny in an SCP attached at the root applies to every account. An allow on a child OU does not cancel it.
- Allow statements are not additive across levels. Allowing
s3:*on the account does nothing if the parent OU's SCPs allow onlyec2:*. The request fails at the OU level.
A worked example
Suppose the Prod OU has the default FullAWSAccess removed and replaced with an SCP that allows only s3:* and ec2:*. Account A sits in Prod and still has FullAWSAccess attached directly.
| Action by a principal in account A | Root | Prod OU | Account A | Result |
|---|---|---|---|---|
| `s3:GetObject` | Allowed | Allowed | Allowed | Not blocked by SCPs |
| `dynamodb:GetItem` | Allowed | No allow | Allowed | Blocked at Prod OU |
| `organizations:LeaveOrganization` | Allowed | No allow | Allowed | Blocked at Prod OU |
"Not blocked by SCPs" does not mean permitted. The principal still needs an identity-based or resource-based policy that grants the action. SCPs only set a ceiling.
Mixing allow lists and deny lists across levels
The usual approach is to keep FullAWSAccess attached at every level and add deny statements where you need them. That works with inheritance in your favor: a deny at the root reaches everything, and a deny at an OU reaches only that subtree. The strategies chapter covers the trade-offs. For now, note the one constraint that matters for attachment: if you remove FullAWSAccess from a target, you must put an SCP with the allows you want in its place, or the target permits nothing.
Moving accounts and OUs
Inheritance follows the account's position in the tree, not a copy of policies made at join time. When you move an account to a different OU, the policies it inherits change.
aws organizations move-account \
--account-id 111122223333 \
--source-parent-id ou-exam-ple12345 \
--destination-parent-id ou-exam-other678After the move, the account stops inheriting the old OU's policies and starts inheriting the new OU's. Policies attached directly to the account stay with it. This makes move-account a policy change in effect, so treat it with the same care as an attach. Moving an account from a restrictive OU into an open one removes guardrails immediately.
Detaching and limits
You remove a policy from a target with detach-policy:
aws organizations detach-policy \
--policy-id p-examplepolicyid \
--target-id ou-exam-ple12345Detaching does not delete the policy. It remains available to attach elsewhere. To delete a policy with delete-policy, first detach it from every target.
Keep these limits in mind when you design the tree. Check the current Organizations quotas page for exact values, because they can change.
- A target can have only a small number of policies of each type attached directly (the default is 5).
- Each policy document has a maximum size of 5,120 characters. Whitespace counts, so minify JSON if you are close to the limit.
- A target must always keep at least one policy of the type. You cannot detach the last SCP from a root, OU, or account, which prevents a target from being left with no allow.
- OUs can be nested only a limited number of levels below the root.
The attachment cap is the reason to attach broad guardrails high in the tree. Putting a policy on the root or a top-level OU spends one slot at that level and covers everything below. Attaching the same policy to fifty accounts one by one costs fifty slots across the accounts and is far harder to audit.
The management account
The management account sits at the root but is treated differently. SCPs do not restrict principals in the management account, even if the policy is attached to the root. Attaching a policy to the management account itself has no effect. Inheritance rules otherwise apply only to member accounts. The next chapters cover this and the other exemptions in detail.
Common mistakes
- Reading
list-policies-for-targetas the effective set. It shows direct attachments only. A missing deny on the account does not mean the account is unrestricted. - Testing in the wrong place. An allow on a child OU cannot repair a missing allow above it.
- Forgetting that moves change policy. Reorganizing OUs changes guardrails for the accounts involved.
- Removing
FullAWSAccesswithout a replacement allow. The target then permits nothing, and users see broad access denied errors.
Exercise
The root has FullAWSAccess. The Dev OU has only an SCP that allows ec2: and s3:. Account B is in the Dev OU and has FullAWSAccess attached directly. A principal in account B has an IAM policy allowing lambda:InvokeFunction. Can it invoke a function? What would you change to permit it, and where?
Show answer
No. The Dev OU's SCPs contain no allow for lambda:InvokeFunction, so the request fails at that level, and the allow on account B cannot restore it. To permit it, add an allow for lambda actions to an SCP attached to the Dev OU (or attach FullAWSAccess to the OU again). The principal's IAM policy then grants the action, and the SCPs no longer block it.
Exercise
You run list-policies-for-target on an account and see only FullAWSAccess. A colleague says the account is therefore not restricted by any SCP. What is wrong with that conclusion, and what should you check?
Show answer
The command shows only policies attached directly to that account. The account also inherits SCPs from its parent OUs and the root. Use list-parents to walk up the tree and run list-policies-for-target at each level, looking for deny statements or missing allows.