Sub topic 6
Service control policies: setting permission boundaries
This chapter assumes you know IAM policy JSON, have an organization with at least one OU, and can run the AWS CLI from the management account.
What an SCP does
A service control policy (SCP) sets the maximum permissions available to the IAM users and roles in a member account. An SCP never grants access. An action is allowed only when both the SCP and an IAM policy allow it.
Three details cause most surprises:
- SCPs do not affect the management account, even when attached to the root.
- SCPs affect every principal in a member account, including the root user of that account.
- SCPs do not affect service-linked roles.
Enabling SCPs
Policy types must be enabled on the organization root. An organization created with all features can use SCPs. With Terraform, enabled_policy_types = ["SERVICE_CONTROL_POLICY"] handles this. A new organization starts with the AWS-managed FullAWSAccess policy attached to the root, every OU and every account. It allows everything, so nothing is blocked until you add a deny.
Writing a deny SCP
This policy stops member accounts from leaving the organization:
{
"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:
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-exampleouid111Every account in that OU, and in any OU below it, now inherits the deny.
How the boundary works
An explicit deny in either layer always wins. The management account skips the SCP check.
Conditions in SCPs
Deny statements can use conditions. This SCP blocks most actions outside two Regions. NotAction exempts global services that do not operate in a single Region:
{
"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"]
}
}
}
]
}Common errors
- Access denied with an allowing IAM policy. Check the SCPs on the account and on each parent OU. The error message may mention an explicit deny in a service control policy.
- Policy has no effect on the management account. This is by design. Keep workloads out of that account.
- Locking yourself out. Test new SCPs on a sandbox OU before attaching them near the root.
Exercise
A role in a member account has an IAM policy allowing s3:*. The account's OU has an SCP chain containing only a deny for ec2:*. Can the role call s3:ListBuckets? Why?
Show answer
Yes, as long as FullAWSAccess (or another allow covering S3) is still in the SCP chain. The SCP only denies EC2, so S3 stays within the boundary, and the IAM policy grants the S3 permission. If FullAWSAccess had been detached with no replacement, the call would fail because no SCP allows it.