HAMZA KAREEM / CONCEPTS hamzawi.dev

Lesson 1262 min read

IAM Policy Evaluation Order

Why Your Admin Role Still Gets AccessDenied

Cloud infrastructurecloud infrastructure / IAM & security

The symptom

Your CI role has AdministratorAccess. The deploy dies:

An error occurred (AccessDenied) when calling the PutObject operation

You re-read the policy. "Action": "*", "Resource": "*". It is genuinely correct. Nothing was revoked. It worked last week.

The instinct that wastes an hour

"Policy hasn't propagated" → wait, retry. Or: attach another Allow. Adding Allow never fixes this class of bug, because in IAM an Allow is not a vote that wins — it's one gate out of several.

The real model: one deny, five fences

A request succeeds only if it clears ALL of these:

1️⃣ Explicit Deny anywhere → denied. Beats every Allow, always.

2️⃣ SCP (AWS Organizations) must allow it

3️⃣ Permissions boundary (if attached to the role) must allow it

4️⃣ Session policy (passed at AssumeRole / OIDC federation) must allow it

5️⃣ Identity policy OR resource policy must allow it

AdministratorAccess only satisfies 5️⃣. Your effective permissions are the AND of every fence that applies — an intersection, not a union. SCPs and boundaries never grant anything; they only cap what grants can reach.

The debug trick almost nobody uses: read the message

AWS literally names the layer that blocked you. Compare the tails:

  • "...because no identity-based policy allows the s3:PutObject action" → you really are missing a grant
  • "...with an explicit deny in a service control policy" → org-level SCP
  • "...with an explicit deny in a resource-based policy" → bucket policy / KMS key policy
  • "...because no permissions boundary allows" → boundary too narrow
  • "...with an explicit deny in a VPC endpoint policy" → the network path, not the principal

Stop grepping policies until you've read that clause. It cuts the search space from 5 layers to 1.

This case

Tail said: explicit deny in a service control policy. The org had added a region-lockdown SCP:

{ "Effect": "Deny",
  "NotAction": ["iam:*","sts:*","cloudfront:*"],
  "Resource": "*",
  "Condition": { "StringNotEquals":
    { "aws:RequestedRegion": ["eu-central-1"] } } }

A new artifacts bucket had been created in us-east-1. Admin + explicit Deny = denied. Fix was the bucket's region, not the role's policy.

The gotcha that makes this worse

aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::111122223333:role/ci-deploy \
  --action-names s3:PutObject \
  --resource-arns arn:aws:s3:::artifacts-prod/build.zip

...reports allowed. The simulator evaluates identity policies and boundaries, but NOT SCPs — so it happily green-lights a call prod will reject. Same for most resource policies unless you pass them in. Trust CloudTrail's errorMessage over the simulator.

Faster path next time

  1. Grab the real event: CloudTrail → filter eventName = PutObject, errorCode = AccessDenied
  2. Read the errorMessage tail → you now know the layer
  3. SCP? → check the OU chain, not the account
  4. Resource policy? → check KMS key policy too, not just the bucket (SSE-KMS writes need kms:GenerateDataKey*)

Your exercise

Take one role you own. Attach a permissions boundary allowing only s3:GetObject. Keep its identity policy at Action "*". Now call s3:PutObject and s3:GetObject.

Predict both outcomes first, then read the exact AccessDenied clause you get back. Which fence does the message name — and does simulate-principal-policy agree?