Skip to main content
KBY Technologies Logo

How AWS Decides Allow or Deny: IAM Policy Evaluation Step by Step

AWS denied your request? Learn the policy evaluation order, tell an explicit deny from an implicit one in the error text, and test it in the IAM policy simulator.

KBY Technologies13 min readFoundation12 min
How AWS Decides Allow or Deny: IAM Policy Evaluation Step by Step

Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.

Before you begin

  • An AWS account you are allowed to experiment in, ideally a sandbox or training account with no production workloads.
  • An IAM identity that can open the IAM console and use the policy simulator, with no broader access than that.
  • A text editor for a short note of your results.

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

When AWS refuses a request with an access denied error, the verdict comes from a fixed order of checks, not from whichever policy you happen to be reading. AWS looks for an explicit Deny in every policy that applies, and one is enough. If there is none, the request still needs an Allow, because everything is denied by default. The wording of the error message tells you which kind of denial you hit.

Once you can say which check refused a request, you stop editing policies at random and start reading evidence. The sections below walk through the logic, apply it to a worked example, and then use the IAM policy simulator to test three requests without sending any of them to AWS or changing anything in your account.

#By the end you can

  • Describe the three steps AWS takes when a request arrives: authentication, processing the request context and evaluating policies.
  • Explain the difference between an implicit deny and an explicit deny, and say which one beats an allow.
  • Say which policy types AWS checks for a Deny, and which it then checks for an Allow.
  • Read an access denied message and name the policy type responsible.
  • Run a read-only simulation in the IAM policy simulator and interpret allowed, implicitly denied and explicitly denied results.

#Before you begin

  • An AWS account you are allowed to experiment in, ideally a sandbox or training account that holds no production workloads.
  • An IAM identity that can open the IAM console and use the policy simulator. The simulator has its own permission requirements, so if the page will not load, ask your administrator rather than widening your own access.
  • A text editor for a short note of your results.

The exercise uses the simulator in Custom mode, where you paste a policy in. Custom policies are simulated on their own and are not saved to your account, so nothing you do changes your real permissions.

#What happens between a request and an answer

Every call you make, from the console, the or the CLI, arrives at AWS as a request from a principal: the user, role or session making the call. AWS completes three steps before it answers. It authenticates the principal if it needs to, which it does not for the few services, such as Amazon S3, that accept some anonymous requests. It then gathers the request context, which decides which policies apply.

Finally it evaluates those policies against the context. Three rules from AWS’s documentation govern that last step. By default every request is implicitly denied, with the exception of the account root user, which has full access. A request is allowed only when a policy, or set of policies, explicitly allows it. And an explicit deny overrides an explicit allow. Everything else in policy evaluation is detail about where AWS looks for each of those.

#
The order AWS checks things

AWS describes the enforcement logic as a sequence, and the order matters because a deny found early ends the evaluation. The first pass is the deny evaluation. The enforcement code examines every applicable policy within the account: Organizations service control policies (SCPs) and resource control policies (RCPs), resource-based policies, identity-based policies, permissions boundaries and session policies. It looks for a Deny statement that matches. One match produces a final decision of Deny.

If no explicit deny is found, evaluation moves on to the allows, and each layer can still end it with a Deny:

  1. RCPs. If RCPs apply and none allows the action, the result is Deny. When RCPs are enabled, a managed policy called RCPFullAWSAccess is attached across the organization and cannot be detached, so by default there is always an allow.
  2. SCPs. If SCPs apply and none allows the action, the result is Deny.
  3. Resource-based policies. Within one account, an allow here can be enough on its own, with exceptions covered below.
  4. Identity-based policies. With no statement that allows the action, the request is implicitly denied.
  5. Permissions boundaries. If the boundary does not allow the action, the request is implicitly denied.
  6. Session policies. For role sessions and federated user sessions, a session policy that does not allow the action causes a Deny. If the principal is not a session principal, or no session policy was passed, this step allows the request.

Following along? Tap a step’s number to tick it off.

Loading diagram...

The diagram is the simplified model to keep in your head. The numbered list above is the full order, and the simplification hides how the layers combine, which the next section explains.

A detailed macro shot of a brass padlock with a key on heavy steel chains, symbolizing security and protection.
Photo by Pixabay on Pexels

#
How the policy types combine

Within a single account, identity-based and resource-based policies combine as a union. If either allows the action, the request is allowed, unless one of them contains an explicit deny.

A permissions boundary behaves differently: the effective permissions are the intersection of the identity-based policies and the boundary, so adding a boundary can only remove access. SCPs and RCPs are intersections as well: for a resource with no resource-based policy, an action must be allowed by the user’s policies, the SCPs and the RCPs together.

There are two exceptions to “an allow in either policy is enough”. IAM role trust policies and AWS KMS key policies must explicitly allow the principal. Policies on resources from some other services may also need an explicit allow in the same account, so read the documentation for the service you are working with.

How policy types combine within one account, from the AWS documentation
Policy typesHow they combineEffect of an explicit deny
Identity-based and resource-basedUnion: an allow in either is enoughAn explicit deny in either overrides the allow
Identity-based and permissions boundaryIntersection: both must allowAn explicit deny in either overrides the allow
Identity-based, SCPs and RCPs (no resource-based policy)Intersection: all three must allowAn explicit deny in the identity-based policy, an SCP or an RCP overrides the allow

#A worked example: Carlos and the log bucket

AWS’s own documentation walks through a user called Carlos, with the IAM user name carlossalazar. His identity-based policy has three statements. One allows a few read-only S3 listing actions on all buckets. One, named AllowS3Self, allows s3:* on the bucket named after him and its objects. The third, DenyS3Logs, denies s3:* on any bucket whose name contains log. A bucket policy on his bucket also allows him.

1{
2    "Version": "2012-10-17",
3    "Statement": [
4        {
5            "Sid": "AllowS3Self",
6            "Effect": "Allow",
7            "Action": "s3:*",
8            "Resource": [
9                "arn:aws:s3:::amzn-s3-demo-bucket-carlossalazar/*",
10                "arn:aws:s3:::amzn-s3-demo-bucket-carlossalazar"
11            ]
12        },
13        {
14            "Sid": "DenyS3Logs",
15            "Effect": "Deny",
16            "Action": "s3:*",
17            "Resource": "arn:aws:s3:::*log*"
18        }
19    ]
20}

The code above is a trimmed copy of that policy, keeping the two statements that decide the outcome. Carlos first tries to save a file to amzn-s3-demo-bucket-carlossalazar-logs. AWS checks for a Deny first and finds DenyS3Logs, because the bucket name contains log. The request is refused, and nothing else is consulted.

He then saves the file to amzn-s3-demo-bucket-carlossalazar instead. There is no matching deny this time. The identity-based policy and the bucket policy both allow the request, so it succeeds. AWS adds that if only one of the two allowed it, the request would still succeed, and if either contained an explicit deny, it would fail. This is the whole model in one small case: deny first, then at least one allow, within one account.

#
Reading the error message

AWS tells you which kind of denial you hit, in most cases. Access denied messages usually follow the format User <user> is not authorized to perform <action> on <resource> because <context>, and the context is the part to read closely.

  • An explicit deny includes the phrase with an explicit deny in a <type> policy. It may also give the policy ARN, but not when an inline policy caused the denial.
  • An implicit deny includes the phrase because no <type> policy allows the <action> action.

For example, because no identity-based policy allows the codecommit:ListRepositories action means nothing allowed the action, so the fix involves adding an allow. A message ending with an explicit deny in a service control policy means an allow elsewhere cannot rescue the request, because only removing or changing that deny helps.

Treat the message as one clue, not the full picture. If several policies of the same type deny a request, the message does not say how many were evaluated. If several policy types deny it, only one type appears in the message. Some AWS services do not use this message format at all.

#Exercise: simulate three requests without sending any

Objective. Predict, then confirm, one allow, one explicit deny and one implicit deny, and name the statement or the missing statement behind each. Safe setup. Use the IAM policy simulator in Custom mode in your sandbox account. The simulator makes no real service request, so the requested actions are not run and you receive no service response. It reports only whether each action would be allowed or denied.

  1. Write down your predictions first. For s3:PutObject, predict the result on arn:aws:s3:::amzn-s3-demo-bucket-carlossalazar/report.txt, on arn:aws:s3:::amzn-s3-demo-bucket-carlossalazar-logs/report.txt and on arn:aws:s3:::amzn-s3-demo-other/report.txt.
  2. In the IAM console, choose Policy simulator in the navigation pane and select Custom mode.
  3. Paste the two-statement policy from the worked example into the policy editor.
  4. Add the s3:PutObject action and enter the three resource ARNs from step 1.
  5. Run the simulation and record, for each row, whether the result is allowed, implicitly denied or explicitly denied, together with the explanation shown.
  6. Edit the pasted copy of the policy in the editor to remove the DenyS3Logs statement and run the simulation again. The edit affects only the simulation, and the policy in your account is unchanged.

Expected evidence. By the evaluation logic, the first resource should be allowed because AllowS3Self matches and no deny does. The second should be explicitly denied, because DenyS3Logs matches the word log. The third should be implicitly denied, because no statement allows it. After step 6, the second resource should change from an explicit deny to an implicit deny, because AllowS3Self never covered that bucket.

Pass condition. Your results match your predictions, and for each denied row you can name the cause: a matched Deny or a missing Allow.

Stop condition. Stop if the simulator asks you to attach, save or apply a policy to a real identity, or if you find yourself pasting a policy from a production account that you are not allowed to copy. Cleanup. Nothing to undo, because nothing was attached or saved. Close the simulator and keep your note.

Close-up of smartphone displaying Google Chrome's welcome page and logo.
Photo by AS Photography on Pexels

#How to check that the simulator told the truth

A simulation is a model of AWS’s decision, not the decision itself. AWS says its results can differ from your live environment and recommends checking your policies against the live environment after testing with the simulator. Some advanced configurations, such as VPC endpoint policies, role chaining or several resource-based policies on one resource, can produce different live behaviour. The simulator also does not support resource control policies.

Use that to decide how far to trust a result. A simulator result that matches the reasoning you did on paper, as in this exercise, is strong evidence that you understand the model. A result that surprises you is a prompt to look at what the simulator did not include.

  • Did you supply the condition key values your policy references? A value that does not satisfy a condition leads to a deny, and a missing value leads to an implicit deny, with the missing keys listed in missingContextValues when you use the API.
  • If an SCP is involved, remember that the simulator reports whether it allows or denies but does not show the matched SCP statement.
  • Did you simulate the identity that makes the real request? A result for one user, group or role is not a result for another.

For the live check, make the real request from the identity in a sandbox and compare the error message with your simulated result, using the phrases above to see whether the denial was explicit or implicit.

#What goes wrong when you read a denial

  • Adding an allow to fix an explicit deny. An explicit deny overrides every allow, so the deny statement has to change. Check whether a service control policy, a boundary or a session policy contains it.
  • Looking only at the identity-based policy. The request is checked against every policy type that applies, and the error message names only one of them.
  • Treating a permissions boundary as a grant. A boundary limits what the identity-based policies can give. Removing it can widen access, and adding one can narrow it.
  • Assuming a resource-based policy always rescues a request. Within an account it often does, but role trust policies and KMS key policies must explicitly allow the principal, and session policies and boundaries can still limit a role.
  • Confusing the root user with other principals. The default of full access applies to the account root user, not to every administrator.
  • Trusting a single simulator run. Results can differ from live behaviour, so confirm with a real request in a safe place.

#Taking policy reasoning into production

The method scales, but the permissions and the risk change. In production, give people who triage denials read access to the policies and to the simulator, and keep policy edits with the people who own the access decision. The simulator can reveal permissions assigned to other IAM entities, so AWS suggests restricting access to its principal-policy operations.

When a deny appears after a change, the question is usually who changed what, and when. The guide on using AWS CloudTrail Event History to find who changed a security group shows one way to trace a change back to a person. For a practical case where permissions on an S3 bucket matter, recovering a deleted Amazon S3 object from a versioned bucket is a good next exercise.

If the message names a service control policy or a resource control policy, you cannot fix it from the account. The policy belongs to the AWS Organizations administrator, and AWS directs you to contact them to find out whether an SCP or RCP is denying a request. Take them the full error message, the action, the resource and your simulation, not a general report that something is denied.

#What to remember

  • Requests are denied by default, and the account root user is the exception.
  • An explicit deny in any applicable policy ends the evaluation with a Deny, whatever else allows the request.
  • Within one account, identity-based and resource-based policies combine as a union, while boundaries, SCPs and RCPs limit as intersections.
  • The error message says whether the denial was explicit or implicit and names one policy type.
  • The simulator predicts without sending requests, but confirm important results against the live environment.
  • Escalate SCP and RCP denials to the Organizations administrator, with the evidence.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Found this useful? Follow KBY for more like it.

Reader Interaction

Comments

Add a thoughtful note on How AWS Decides Allow or Deny: IAM Policy Evaluation Step by Step. Comments are checked for spam and held for moderation before appearing.

Loading comments...

More from KBY that goes with this article.

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Build practical engineering skills.

Receive new lessons, learning paths, practical exercises and early-career guidance.