All guides

Service control policies: guardrails for every AWS account

A service control policy sets the maximum permissions for the IAM users and roles in a member account. It grants nothing. It limits what the IAM policies inside the account can allow.

A pair of glasses in front of two screens showing code

What an SCP does

A service control policy (SCP) is a policy type in AWS Organizations. It is available only in an organization with all features enabled. You attach it to the root, to an organizational unit (OU) or to one account. It restricts the IAM users and roles in the member accounts below, including each member account's root user.

No permissions are granted by an SCP. The effective permissions are the intersection of what the SCPs allow and what identity-based and resource-based policies allow.

Two rules decide the outcome:

  • For a permission to hold, an explicit Allow has to be present at the root, at each OU on the path and at the account. This is why AWS attaches the managed policy FullAWSAccess to every root, OU and account.
  • A Deny at any level applies to all the OUs and accounts under it.

The AWS example SCPs use a deny list strategy: FullAWSAccess stays attached and the SCPs add Deny statements. If you remove FullAWSAccess and attach no replacement, all AWS actions from the member accounts fail.

SCPs use a syntax similar to IAM policies. Two differences: an SCP has no Principal element, and an Allow statement accepts only * as its Resource. Both kinds of statement can carry conditions, and a Deny statement can name individual ARNs.

What an SCP does not restrict

  • The management account. SCPs do not affect its users or roles.
  • Service-linked roles.
  • Users from accounts outside the organization. In the AWS example, a bucket policy grants access to users from an outside account, and the SCP on the bucket owner's account does not apply to them.
  • A short list of tasks that the documentation names, such as registering for the Enterprise support plan as the root user.

A member account designated as a delegated administrator is still subject to SCPs. Because the management account is exempt, keep workloads out of it.

Deny leaving the organization

JSON

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Deny",
      "Action": [
        "organizations:LeaveOrganization"
      ],
      "Resource": "*"
    }
  ]
}

This AWS sample prevents member accounts from leaving the organization. SCPs affect only accounts that are part of the organization.

Deny Regions you do not use

JSON

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyAllOutsideEU",
      "Effect": "Deny",
      "NotAction": ["cloudfront:*", "iam:*", "route53:*", "support:*"],
      "Resource": "*",
      "Condition": {
        "StringNotEquals": {
          "aws:RequestedRegion": ["eu-central-1", "eu-west-1"]
        }
      }
    }
  ]
}

This is the example from the SCP syntax page. Put your own Regions in the list. A few global services, IAM for one, have only one endpoint. IAM calls are always made to us-east-1, so a policy that denies every other Region makes them fail. NotAction exempts those services. The AWS samples repository carries a much longer NotAction list, so start from that one. The key aws:RequestedRegion controls which endpoint is called. It does not control the impact of the operation: S3 replication set up in one Region affects others.

Protect CloudTrail

JSON

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Deny",
      "Action": [
        "cloudtrail:DeleteTrail",
        "cloudtrail:PutEventSelectors",
        "cloudtrail:StopLogging",
        "cloudtrail:UpdateTrail",
        "cloudtrail:CreateTrail"
      ],
      "Resource": "arn:aws:cloudtrail:<region>:111122223333:trail/<trail-name>",
      "Condition": {
        "ArnNotLike": {
          "aws:PrincipalARN": "arn:aws:iam::111122223333:role/<privileged-role>"
        }
      }
    }
  ]
}

This is the AWS sample named Deny modifications to specific AWS CloudTrail trails. Its trail and its privileged role are written here as ARNs for you to fill in. The sample's notes add an alternative: with an organization trail, users in member accounts do not have sufficient permissions to delete the trail, turn logging on or off, or change which events are logged.

Resource control policies

AWS draws the line this way. Use an SCP to limit the permissions of IAM principals in your member accounts. Use a resource control policy (RCP) to restrict principals from outside the organization that request access to resources in your member accounts. An RCP affects principals whether or not they belong to your organization. Like an SCP it grants nothing, does not affect the management account and does not restrict service-linked roles. RCPs apply only to the services on a list that AWS publishes, and Amazon S3 is on it.

Rollout on one OU first

AWS strongly recommends that you do not attach an SCP to the root before you have tested its impact. Create an OU, move accounts into it one at a time or in small numbers, and attach the policy there.

Shell

aws organizations create-policy \
  --name deny-leave-organization \
  --description "Member accounts cannot leave the organization" \
  --type SERVICE_CONTROL_POLICY \
  --content file://deny-leave.json

aws organizations attach-policy \
  --policy-id <policy-id> \
  --target-id <ou-id>

Before you widen the scope, check four things:

  1. Service last accessed data in IAM shows whether an account uses a service.
  2. CloudTrail logs service usage at the API level. Look there for calls that are now denied.
  3. aws accessanalyzer validate-policy accepts --policy-type SERVICE_CONTROL_POLICY. Run it on the policy file.
  4. The policy fits the quotas. On the quotas page today, an SCP holds 10,240 characters, and a root, an OU or an account takes 10 directly attached SCPs.

Then follow the AWS advice: deploy to more specific OUs first and to broader OUs over time.

Sources

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides