Sub topic 3
Attaching policies and how inheritance works
This chapter assumes you know the organization tree (root, OUs, accounts) and have enabled the SCP and RCP policy types on the root. It covers where you attach policies and how they combine along the path to an account.
Where policies attach
You can attach an SCP or RCP to three kinds of target:
- The root, which affects every account in the organization.
- An organizational unit (OU), which affects every account in it and in its child OUs.
- A single account.
A policy is created once and can be attached to many targets. Attaching it does not copy it, so editing the policy changes it everywhere it is attached.
aws organizations attach-policy \
--policy-id p-examplepolicyid \
--target-id ou-exam-ple12345
aws organizations list-policies-for-target \
--target-id ou-exam-ple12345 \
--filter SERVICE_CONTROL_POLICY
aws organizations list-targets-for-policy \
--policy-id p-examplepolicyidlist-policies-for-target shows only policies attached directly to that target. It does not show policies inherited from parents. To see everything that applies to an account, check the account, each parent OU, and the root.
How inheritance works
Policies flow down the tree. A policy attached to a parent applies to all of its descendants. A child cannot opt out of a parent's policy.
At each level, the policies attached there are evaluated together, and the result is an intersection with the levels above. An action is available to an account only if every level on the path from the root to the account allows it. The path is the root, then each OU, then the account.
This gives two rules to remember:
- An explicit Deny at any level blocks the action for everything below. A lower level cannot override it.
- An Allow at a level only lets the action pass that level. It does not grant anything on its own, and a missing Allow at any level blocks the action.
The default FullAWSAccess policy
When you enable a policy type, AWS attaches a default full-access policy to the root, every OU, and every account. For SCPs it is FullAWSAccess. For RCPs it is RCPFullAWSAccess. These allow everything, so nothing is blocked until you add a Deny.
Each target must always have at least one policy of each enabled type attached. AWS will not let you detach the last one. If you plan an allow-list approach, you attach your own allow policy first and then detach the default. Deny-list and allow-list strategies are covered in a later chapter.
Limits to know
| Limit | Value |
|---|---|
| Policies attached directly to one root, OU, or account | 5 per policy type |
| Maximum size of an SCP or RCP | 5,120 characters |
| OU nesting depth below the root | 5 levels |
Because of the attachment limit, group related statements into one policy instead of creating many small ones. Because of the size limit, remove whitespace and avoid repeating long action lists.
Exercise
An account sits in OU "Dev", which is inside OU "Workloads", which is under the root. The root and Workloads have only FullAWSAccess. Dev has an SCP that denies ec2: and FullAWSAccess. An administrator attaches an SCP to the account that explicitly allows ec2:. Can principals in the account use EC2?
Show answer
No. The explicit Deny at the Dev OU is inherited by the account and cannot be overridden by an Allow at a lower level. An SCP Allow also never grants permissions by itself.