Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 70 ยท Identity and access management

How Policy Evaluation Works

Learn how AWS decides allow or deny: explicit deny, implicit deny, permission boundaries, SCPs, session policies and cross-account access, with a runnable evaluator.

Every call to AWS is checked against policies before anything happens. You may have written several policies by now, attached to a user, a role and a bucket, and they all apply at once. So how does AWS combine them into one answer? The rules are short and worth memorizing, because almost every "AccessDenied" mystery comes down to one of them.

This lesson follows Writing IAM Policies, where you learned the shape of a single policy. Here you will see how many policies from different places are merged: identity policies, resource policies, permission boundaries, service control policies (SCPs) and session policies.

Real IAM runs inside AWS and cannot run on this site. The AWS policies and CLI commands below are read-only. The runnable examples are small Python evaluators that follow the same rules, so you can try the logic yourself. They leave out many real features (condition keys, principal ARNs, and others), and each lesson section says what is simplified.

The three possible outcomes

For each request AWS ends in one of three states:

  1. Explicit deny. Some applicable policy has a statement with "Effect": "Deny" that matches the action and resource. The request fails. Nothing can override this.
  2. Allow. No explicit deny exists, and the right combination of policies contains a matching "Effect": "Allow".
  3. Implicit deny. No deny matched, but no allow matched either. By default, everything is denied unless something allows it.

The golden rule: an explicit deny always wins, then an allow is required, otherwise the answer is no. A policy cannot "undo" a deny by adding an allow. That is why deny statements are the right tool for guardrails.

flowchart TD
    A["Request arrives"] --> B{"Any matching<br/>explicit Deny?"}
    B -- Yes --> D1["DENY"]
    B -- No --> C{"Do all guardrails allow it?<br/>SCP, boundary, session policy"}
    C -- No --> D2["DENY (implicit)"]
    C -- Yes --> E{"Does a grant allow it?<br/>identity or resource policy"}
    E -- No --> D3["DENY (implicit)"]
    E -- Yes --> OK["ALLOW"]

The decision order, simplified: deny first, then guardrails, then a grant.

Grants and guardrails

It helps to split policy types into two groups.

Grants give permission:

  • Identity-based policies attached to a user, group or role.
  • Resource-based policies attached to a resource such as an S3 bucket, an SQS queue or a KMS key. They name who (the Principal) may do what.

Guardrails only limit what the grants may achieve. They never give permission by themselves:

  • Service control policies (SCPs) in AWS Organizations limit what the accounts in an organization can do, even for the account's root user.
  • Permission boundaries limit the maximum permissions an IAM user or role can get from its identity policies.
  • Session policies are passed when you assume a role (or federate) and limit that one session.

Think of a guardrail as a fence around a field. Inside the fence, identity policies decide where you actually walk. If your grants point outside the fence, you still cannot go there.

An example boundary that limits a developer role to S3 and CloudWatch, whatever else its policies say:

JSON
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:*", "cloudwatch:*"],
      "Resource": "*"
    }
  ]
}

You attach it as a boundary with the CLI (read-only here):

Terminal
aws iam put-role-permissions-boundary \
  --role-name dev-role \
  --permissions-boundary arn:aws:iam::123456789012:policy/dev-boundary

Notice that the boundary has an Allow effect. It does not grant anything. It lists what is permitted to pass through the fence. An Allow in a boundary with no matching Allow in an identity policy still gives nothing.

Same account and cross-account

When the caller and the resource live in the same account, an allow from either the identity policy or the resource policy is enough (as long as the guardrails and denies do not stop it).

When they live in different accounts, both sides must allow. The caller's account must allow the action in an identity policy, and the resource's account must allow the caller in a resource policy (or the caller assumes a role in the resource's account instead). This makes sense: one account cannot hand out access to another account's data without that account agreeing.

flowchart LR
    subgraph A["Account 111111111111"]
        U["Role: analyst<br/>identity policy allows s3:GetObject"]
    end
    subgraph B["Account 222222222222"]
        S["Bucket: reports<br/>bucket policy allows account 111111111111"]
    end
    U -- "both must allow" --> S

Cross-account access needs an allow on both sides of the account boundary.

A bucket policy that opens read access to another account looks like this (read-only):

JSON
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowAnalystAccount",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111111111111:root" },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::reports/*"
    }
  ]
}

:root here means "this account" (not the root user): it delegates the decision to that account's own IAM, which can then grant access to specific users and roles.

A first evaluator: deny beats allow

This stand-in implements the golden rule for a flat list of policies. It supports * and ? wildcards in actions and resources, like real IAM. Notice that the explicit deny on the secret/ prefix wins even though another statement allows everything in the bucket.

Python Explicit deny, allow and implicit deny

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first request is allowed by ReadBucket. The second matches both the allow and the deny, so the deny wins. The third has no matching allow (PutObject is not listed), and the fourth is for a service nobody allowed. Both are implicit denies. In AWS the error message for these cases differs slightly: it says whether an explicit deny or a missing allow was the cause, which is a big help when debugging.

Layers: SCPs, boundaries and session policies

Now the full picture. A request must pass every guardrail that applies, and after that a grant must exist. This evaluator adds an SCP, a permission boundary, a session policy, a resource policy and an account check. It is a teaching model: real IAM also evaluates condition keys, principal ARNs, NotAction, and more.

Python A layered policy evaluator with cross-account access

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the results line by line. The boundary case shows that an allow in the identity policy gives nothing outside the boundary. The SCP case shows a guardrail with an explicit deny. The session policy case narrows one session without touching the role's own policy. In the cross-account pair the identity policy alone is not enough, but adding the matching resource policy allows the call. The last line shows an explicit deny in a resource policy beating an identity allow.

One more real-world detail that the stand-in simplifies: when a resource-based policy names an IAM user or role ARN directly (not just the account), same-account access can be granted without any identity policy, and the permission boundary does not limit that grant. Session policies and SCPs still apply.

Debugging an AccessDenied

When a call fails, ask in order:

  1. Is there a deny? Look for SCPs, a bucket or key policy deny, a boundary or session policy that does not list the action.
  2. Is there an allow in the right place? Same account: identity or resource. Different account: both.
  3. Is the policy attached to the right principal? Roles assumed through a session carry the role's permissions, not your original user's.

The IAM policy simulator in the console and aws iam simulate-principal-policy run these rules against your real policies (read-only here). CloudTrail error messages also say which type of policy caused an explicit deny. You will practice this in Common Mistakes and Troubleshooting.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A user has an identity policy that allows s3:* on everything, and a bucket policy with an explicit deny for that user on s3:DeleteObject. What happens when the user deletes an object?

    An explicit deny in any applicable policy overrides every allow, no matter where the allow comes from.
  2. 2. What does a permission boundary do?

    A boundary is a guardrail. Effective permissions are the overlap of the boundary and the identity policies, so a boundary alone grants nothing.
  3. 3. For a call from account A to a bucket in account B, which allows are needed?

    Across accounts both sides must agree. Within one account, either an identity policy or a resource policy is enough.
  4. 4. What is an implicit deny?

    Everything is denied by default. If nothing allows the request and nothing denies it explicitly, the outcome is an implicit deny.

Summary

  • The order is: an explicit deny wins, then guardrails must allow, then a grant must exist; otherwise the result is an implicit deny.
  • Grants are identity-based and resource-based policies. Guardrails are SCPs, permission boundaries and session policies; they never grant access on their own.
  • Within one account an allow from the identity policy or the resource policy is enough. Across accounts both sides must allow.
  • Use explicit denies for rules that must never be bypassed, such as blocking dangerous actions organization-wide.
  • Debug in order: look for denies, then for the missing allow, then check which principal and session actually made the call.

Next: IAM Best Practices and Least Privilege