Home / AWS

AWSRunbookAdvanced

Sev1: AWS SCP change denies everything in production accounts

A new or edited service control policy blocks deployments, pipelines and even admins across an OU. Find the policy, detach or fix it from the management account, and stop it recurring.

Deepak Bhardwaj5 min read

Applies toAWS Organizations (all features), service control policies, resource control policies, AWS CLI v2

Symptoms

  • Many accounts start failing at the same time, often right after a platform or security change window.
  • Errors include the phrase with an explicit deny in a service control policy, for example: User: arn:aws:sts::111122223333:assumed-role/Admin/jane is not authorized to perform: ec2:RunInstances ... with an explicit deny in a service control policy.
  • Admin roles inside the member accounts cannot fix it. Their permissions are capped by the SCP too.
  • If the message says resource control policy instead, an RCP is the cause. The steps are the same with a different policy type.

The fix happens in the management account (or a delegated administrator account for Organizations policies, if you set one up). SCPs never apply to the management account, so it is your way back in.

Step 1: confirm it is an SCP and find the scope (5 minutes)

From an affected account, capture one full error. Many services include the policy type in the message; some only return a plain AccessDenied. Look at CloudTrail for the denied call:

aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances \
  --max-results 5 --query "Events[].CloudTrailEvent" --output text | grep -o '"errorMessage":"[^"]*"'

Then sign in to the management account and see what is attached along the path to the account. An account inherits SCPs from the root, every parent OU and the account itself.

ACCOUNT=111122223333
aws organizations list-parents --child-id $ACCOUNT
aws organizations list-policies-for-target --target-id $ACCOUNT --filter SERVICE_CONTROL_POLICY \
  --query "Policies[].[Id,Name,AwsManaged]" --output table
aws organizations list-policies-for-target --target-id ou-abcd-11111111 --filter SERVICE_CONTROL_POLICY \
  --query "Policies[].[Id,Name,AwsManaged]" --output table
aws organizations list-roots --query "Roots[].Id" --output text

Repeat list-policies-for-target for each parent up to the root. For RCPs, use --filter RESOURCE_CONTROL_POLICY.

Step 2: find what changed

Organizations is a global service; its CloudTrail events are recorded in us-east-1.

aws cloudtrail lookup-events --region us-east-1 \
  --lookup-attributes AttributeKey=EventSource,AttributeValue=organizations.amazonaws.com \
  --start-time $(date -u -d '-6 hours' +%FT%TZ) \
  --query "Events[?contains('CreatePolicy UpdatePolicy AttachPolicy DetachPolicy', EventName)].[EventTime,EventName,Username]" \
  --output table

Read the suspect policy:

aws organizations describe-policy --policy-id p-examplebad \
  --query "Policy.Content" --output text | python -m json.tool
aws organizations list-targets-for-policy --policy-id p-examplebad --output table

Common culprits:

What you see in the policy Why it denies everything Fix
Deny with "NotAction" list missing services you use Everything not listed is denied Add the missing actions or switch to an explicit Deny list
Region deny using aws:RequestedRegion without exempting global services IAM, STS, Organizations, Route 53, CloudFront calls go to us-east-1 and get blocked Exempt global services with NotAction
StringNotEquals on aws:PrincipalTag or aws:PrincipalArn with a typo No principal matches the exemption, so all are denied Correct the tag key, value or ARN pattern
FullAWSAccess detached and an allow-list SCP attached that is too narrow Allow-list SCPs grant nothing outside the list Re-attach FullAWSAccess or widen the allow list
Condition key that does not exist for the action Condition evaluates unexpectedly Validate the policy (see Prevent)

Step 3: restore service

Pick the fastest safe option. Detaching is quicker and easier to reason about than editing JSON under pressure.

Option A: detach the bad policy from the target.

aws organizations detach-policy --policy-id p-examplebad --target-id ou-abcd-11111111

Every root, OU and account must keep at least one SCP attached. If the bad policy is the only one, attach FullAWSAccess first:

aws organizations attach-policy --policy-id p-FullAWSAccess --target-id ou-abcd-11111111

Look up the real ID with aws organizations list-policies --filter SERVICE_CONTROL_POLICY.

Option B: put back the previous version of the policy. Organizations does not keep policy versions. Use your IaC repository, or pull the old content from the UpdatePolicy CloudTrail event's requestParameters, save it as previous.json, then:

aws organizations update-policy --policy-id p-examplebad --content file://previous.json

Warning

If the SCP is managed by Terraform, CloudFormation StackSets, Control Tower or Customizations for Control Tower, a manual fix can be reverted by the next pipeline run. Pause that pipeline or merge the fix there right after the console change.

Caution

aws organizations disable-policy-type --root-id r-xxxx --policy-type SERVICE_CONTROL_POLICY removes every SCP in the organization, including your security guardrails. Use it only if you cannot identify the bad policy, and re-enable and re-attach immediately after.

Changes are eventually consistent. Allow a few minutes, then retest from an affected account:

aws sts get-caller-identity
aws ec2 describe-instances --max-results 5 --query "Reservations[].Instances[].InstanceId"

Step 4: clean up after the outage

  • Re-run failed pipelines and scheduled jobs. Auto Scaling groups may have suspended processes after repeated launch failures; check aws autoscaling describe-auto-scaling-groups --query "AutoScalingGroups[].[AutoScalingGroupName,SuspendedProcesses]".
  • Check CloudFormation stacks that went into UPDATE_ROLLBACK_FAILED during the window.
  • Confirm the guardrail you intended to add is in place in its corrected form, so the security gap is closed again.

Prevent it next time

Validate every SCP before it is attached. IAM Access Analyzer checks syntax and flags common mistakes:

aws accessanalyzer validate-policy --policy-type SERVICE_CONTROL_POLICY \
  --policy-document file://new-scp.json --query "findings[].[findingType,issueCode,findingDetails]" --output table

Roll out in rings. Attach a new SCP to a sandbox OU first, then non-production, then production, with a soak period between each.

aws organizations attach-policy --policy-id p-newpolicy --target-id ou-abcd-sandbox

Build in a break-glass exemption. Deny statements can exclude a dedicated emergency role:

{
  "Effect": "Deny",
  "Action": "*",
  "Resource": "*",
  "Condition": {
    "StringNotLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/BreakGlassAdmin" },
    "StringNotEquals": { "aws:RequestedRegion": ["eu-west-1", "us-east-1"] }
  }
}

Keep BreakGlassAdmin tightly controlled and alarmed on use.

  • Manage SCPs only through code review. Restrict organizations:UpdatePolicy and organizations:AttachPolicy in the management account to the pipeline role.
  • Alert on changes: an EventBridge rule in us-east-1 for organizations.amazonaws.com events UpdatePolicy, AttachPolicy and DetachPolicy, sent to the on-call channel.
  • Keep workloads out of the management account. It is exempt from SCPs, which is exactly why it must stay minimal and locked down.