Skip to content
Visual explainer 3h to learn 5 steps

Trace an AWS request through IAM policy evaluation

Follow one request through identity, resource and session policies and explain an AccessDenied from its evidence.

By Invicly Tech, , in AWS Cloud Engineering. About 12 minutes to read.

Topic 4 of 38

In short

Every AWS request is checked against all the policies that apply to it: identity policies on the caller, resource policies on the target, organization guardrails, permissions boundaries and session policies. An explicit deny anywhere wins, an allow is needed from the right places, and anything not allowed is implicitly denied. Learning that order lets you read an AccessDenied message and point at the policy that caused it.

Think of it like this: Getting into a concert needs a valid ticket (identity policy), your name on the door list if the venue keeps one (resource policy), and no ban from security (explicit deny); any single ban beats every ticket.

Explained simply

In AWS, nothing is allowed by default. Every time someone or something calls an AWS API, such as reading a file from S3, AWS collects every policy that applies to that request and decides yes or no. A policy is a small JSON document listing actions, resources and whether they are allowed or denied.

Policies can sit in several places. Identity policies are attached to the caller, such as a role. Resource policies are attached to the thing being used, such as a bucket policy on S3. Organization policies, called SCPs, set outer limits for whole accounts.

The rules are simple to remember. First, an explicit Deny anywhere wins, no matter how many allows exist. Second, if no policy says Allow, the answer is no; this is called an implicit deny. Third, when several layers apply, each limiting layer must leave room for the action.

Roles add one more piece. A role has a trust policy that says who may become the role, and permission policies that say what the role can do once assumed. Mixing these two up is one of the most common beginner mistakes.

When access fails, AWS returns an AccessDenied error. Newer messages often name the policy type that caused it, for example 'no identity-based policy allows' or 'explicit deny in a service control policy'. Read that sentence carefully; it tells you where to look.

Press Play on a diagram to walk through it one step at a time.

FlowHow AWS decides one request
  1. 1
    Start: deny by default

    Nothing is allowed unless a policy allows it.

  2. 2
    Any explicit deny?

    In any applicable policy. If yes: denied.

  3. 3
    Organization guardrails

    SCPs and RCPs must allow the action.

  4. 4
    Resource or identity allow

    Same account: either can allow. Cross account: both must.

  5. 5
    Boundaries and session policy

    If present, they must also allow it.

  6. 6
    Allowed

    Every applicable layer permitted the request.

LayersPolicy types that can apply to one request
  1. 1
    SCPs and RCPs

    Organization limits on principals and resources

  2. 2
    Resource-based policy

    Bucket, queue, key or role trust policy

  3. 3
    Identity-based policy

    Attached to the user, group or role

  4. 4
    Permissions boundary

    Maximum for that user or role

  5. 5
    Session policy

    Passed at AssumeRole time for one session

In depth

Anatomy of a request and a policy statement

A request carries a principal (who is calling, for example the worker role session), an action (s3:GetObject), a resource (arn:aws:s3:::filesvc-uploads/in/report.csv) and context such as source IP, time, tags and whether MFA was used. AWS matches this request context against every statement in every applicable policy.

A statement has Effect (Allow or Deny), Action, Resource and optionally Condition. Resource policies also have Principal, because they must say who they apply to. Wildcards are allowed: s3:Get* matches every S3 action starting with Get. Conditions use keys such as aws:SourceIp, aws:PrincipalTag/team or s3:prefix. A statement only counts when every part matches, including all its conditions.

  • Principal: who
  • Action: which API call
  • Resource: which ARN
  • Condition: when and under which context
  • Effect: Allow or Deny

Identity and resource policies together

Inside a single account, AWS takes the union of identity-based and resource-based allows: if either allows the action and nothing denies it, the request succeeds. That is why a bucket policy alone can grant a role in the same account read access. There are exceptions involving permissions boundaries and session policies, which can still cut that access back.

Across accounts, the rule changes. 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. Both sides have to agree. Services such as KMS add another twist: a key policy must allow use of the key, so reading an object encrypted with a customer managed key needs both S3 permissions and kms:Decrypt permitted by the key policy.

CompareSame account versus cross account
Same account
  • Identity OR resource policy can allow
  • Explicit deny still wins
  • Boundaries and session policies can narrow it
  • Example: bucket policy grants a local role
Cross account
  • Identity policy in caller account must allow
  • Resource policy in owner account must allow
  • Either side can deny
  • Example: dev role reading a prod bucket

Role trust, sessions and session policies

Assuming a role is itself an API call: sts:AssumeRole for AWS principals, sts:AssumeRoleWithWebIdentity for OIDC tokens and sts:AssumeRoleWithSAML for SAML. For it to work, the role's trust policy must allow the caller. When the caller is an IAM principal in another account, its own identity policy must also allow sts:AssumeRole on that role ARN.

The result is a session with temporary credentials. Its permissions are those of the role's permission policies, limited further by any session policy passed in the AssumeRole call, by the role's permissions boundary and by SCPs. Session policies are handy when a broad role is shared but one script should only touch one prefix. They can never add access the role does not already have.

SequenceAssuming a role with a session policy
Caller
AWS STS
Role
Amazon S3
  1. 1AssumeRole(RoleArn, session policy: only in/ prefix)
    Caller to AWS STS: AssumeRole(RoleArn, session policy: only in/ prefix)
  2. 2Check trust policy allows the caller
    AWS STS to Role: Check trust policy allows the caller
  3. 3Temporary credentials for the session
    AWS STS to Caller: Temporary credentials for the session
  4. 4GetObject in/report.csv: allowed by role and session policy
    Caller to Amazon S3: GetObject in/report.csv: allowed by role and session policy
  5. 5GetObject out/result.json: denied, outside session policy
    Caller to Amazon S3: GetObject out/result.json: denied, outside session policy

Reading denied-access evidence

Start with the error text. Many services now say who was denied, which action, which resource and which policy type was responsible, such as 'because no identity-based policy allows', 'with an explicit deny in a resource-based policy' or 'with an explicit deny in a service control policy'. Then confirm the caller with sts get-caller-identity, because the wrong role is a frequent cause.

Next, look for the event in CloudTrail. Event history shows management events for 90 days; data events such as S3 object reads only appear if a trail or event data store records them. The record shows errorCode AccessDenied, the userIdentity ARN, the request parameters and the source IP. Finally, test fixes safely with the IAM policy simulator or aws iam simulate-principal-policy, and use IAM Access Analyzer to validate policy syntax.

  • Error text: action, resource, policy type
  • get-caller-identity: right principal?
  • CloudTrail: errorCode, userIdentity, parameters
  • Policy simulator: test before changing
  • Check KMS key policies and VPC endpoint policies too

Learn it in 5 short steps

About 35m each. Track them with a timer in your plan.

  1. 1
    Order explicit deny, allow and implicit deny~35m
  2. 2
    Combine identity and resource policies~35m
  3. 3
    Read a role trust policy~35m
  4. 4
    Apply session policies~35m
  5. 5
    Read an AccessDenied message~35m

Key points

  • Explicit deny beats any allow, in any policy type.
  • With no matching allow, the result is an implicit deny.
  • Within one account, an allow in either the identity policy or the resource policy is usually enough; across accounts both sides must allow.
  • A role's trust policy only controls who may assume the role; its permission policies control what the session can do.
  • Session policies and permissions boundaries can only narrow access, never widen it.

Key terms

Tap a card to flip it. 0/6 known

Examples

json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "lambda.amazonaws.com" },
    "Action": "sts:AssumeRole"
  }]
}

A trust policy that lets the Lambda service assume the worker role. It grants no S3 or SQS access by itself.

Tracing the worker's AccessDenied on S3

The Lambda worker fails with AccessDenied when reading in/report.csv. Step 1: the log line says the assumed-role filesvc-worker is not authorized to perform s3:GetObject 'because no identity-based policy allows the s3:GetObject action'. Step 2: open the worker role's policy; it allows s3:GetObject on arn:aws:s3:::filesvc-uploads but not on the objects. Step 3: object actions need the object ARN, so the resource should be arn:aws:s3:::filesvc-uploads/in/*. Step 4: simulate the fixed policy, deploy it and re-run. Evidence: the simulator says allowed and the next invocation succeeds.

bash
aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::111122223333:role/filesvc-worker \
  --action-names s3:GetObject \
  --resource-arns arn:aws:s3:::filesvc-uploads/in/report.csv \
  --query "EvaluationResults[].[EvalActionName,EvalDecision]"
# Before fix: implicitDeny   After fix: allowed

An explicit deny that no allow can fix

An admin can list the bucket but cannot download any object, even with AdministratorAccess. Step 1: the error says 'with an explicit deny in a resource-based policy'. Step 2: the bucket policy has a Deny for s3:GetObject when aws:SecureTransport is false, plus a second Deny for any principal not using the filesvc VPC endpoint. Step 3: the admin's laptop is outside the VPC, so the second Deny matches. Step 4: decide whether that is intended. Usually it is, and the fix is to read from inside the VPC, not to weaken the policy. Evidence: CloudTrail shows the denied call with the laptop's public source IP and no vpcEndpointId.

json
{
  "Effect": "Deny",
  "Principal": "*",
  "Action": "s3:GetObject",
  "Resource": "arn:aws:s3:::filesvc-uploads/*",
  "Condition": { "StringNotEquals": { "aws:SourceVpce": "vpce-0abc1234def567890" } }
}

Quick reference

  • Explicit deny > allow > implicit deny (the default)
  • Same account: identity OR resource policy can allow. Cross account: both must allow
  • Trust policy = who can assume the role; permission policies = what the session can do
  • Session policies and boundaries only narrow permissions
  • Bucket actions use arn:aws:s3:::bucket; object actions use arn:aws:s3:::bucket/key
  • aws iam simulate-principal-policy tests a principal's policies without making the call
  • Encrypted data with a customer managed key also needs the KMS key policy to allow use

Common mistakes

  • Adding more Allow statements to fix a denial that is caused by an explicit deny or an SCP.
  • Editing a role's permission policy when the problem is its trust policy, or the other way round.
  • Forgetting the KMS key policy when an encrypted S3 object or SQS message is denied.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1A role's identity policy allows sqs:SendMessage and the queue has no resource policy. Both are in the same account and no SCP blocks it. Result?

Question 2

2What does a role's trust policy control?

Question 3

3A session policy allows s3:* but the role's permission policy only allows s3:GetObject. What can the session do in S3?

Question 4

4An error says 'with an explicit deny in a service control policy'. Who can fix it?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Write an identity policy that lets the worker role read objects under in/ and write objects under out/ in the filesvc-uploads bucket, and nothing else.

  2. Exercise 2medium

    Create a test role that trusts your own account, attach the policy above, assume it with a session policy that only allows the in/ prefix, and prove that writing to out/ is denied.

  3. Exercise 3hard

    Given a denied cross-account read (dev role in 444455556666 reading s3://filesvc-prod-results in 111122223333), list every policy you must check and the CloudTrail evidence you would collect.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Why does AWS deny by default?
It is safer: a forgotten or mistyped policy fails closed rather than open. You add exactly the access you need.
Do I need both an identity policy and a bucket policy?
Within one account, one of them is enough if nothing denies the request. Across accounts, you need both.
What is the difference between a permissions boundary and an SCP?
A boundary limits one user or role and is set in that account. An SCP limits every principal in the member accounts it is attached to and is managed by the organization.

Go deeper

ShareXLinkedInWhatsApp