Policy documents and evaluation logic

Intermediate · 21 min

Read and write IAM JSON: actions, resources, conditions and principals, and how AWS combines identity, resource and guardrail policies into one decision.

Before thisIAM users, groups, roles and policies

Amazon Web Services · 24 min · from 3:16

Policy documents and evaluation logic

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Amazon Web ServicesReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Everything is denied until allowed, and an explicit Deny in any applicable policy beats every Allow.
  • Guardrails (SCPs, RCPs, permissions boundaries, session policies) only limit. They never grant anything.
  • Within one account, an allow from either the identity policy or the resource policy is usually enough. Across accounts both sides must allow.
  • Role trust policies and KMS key policies are exceptions: they must themselves allow the principal.
  • Inside a Condition, different keys and operators are ANDed, and several values for one key are ORed.
  • Look up which resource types and condition keys an action supports. An action without resource-level support only works with Resource set to *.

A policy is a list of sentences

Each statement in a policy reads like a sentence: Effect (allow or deny) these Actions on these Resources when these Conditions hold. Resource-based policies add a Principal: for whom.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "ReadOwnPartitionFromOffice",
    "Effect": "Allow",
    "Action": ["dynamodb:GetItem", "dynamodb:Query"],
    "Resource": "arn:aws:dynamodb:eu-west-1:123456789012:table/orders",
    "Condition": {
      "ForAllValues:StringEquals": {"dynamodb:LeadingKeys": ["${aws:username}"]},
      "IpAddress": {"aws:SourceIp": "203.0.113.0/24"}
    }
  }]
}

Always set "Version": "2012-10-17". It is the language version, not a date you update, and policy variables such as ${aws:username} need it.

In a Condition, separate operators and keys must all match. Several values for one key mean any of them. If the request lacks the key, most operators do not match, which matters a great deal for Deny statements. The IfExists suffix changes that. Set operators such as ForAllValues have their own trap: it is true when the request carries no values at all.

NotAction and NotResource mean “everything except”. With Allow they grant far more than people expect.

Not every action takes every resource

AWS publishes, per service, which resource types and condition keys each action supports. It is also available as public JSON. For DynamoDB:

Action Resource types
GetItem table
Query table, index
ListTables none

“None” means you must write "Resource": "*". A table ARN there grants nothing. And Query on an index needs the index ARN, .../table/orders/index/by-customer. This explains many puzzling AccessDenied errors.

Combining policies

Many policies can apply to one request. Think of a building with several locked doors in a row, plus a banned list at the entrance.

  1. Explicit deny anywhere? Then deny. Nothing overrides it.
  2. Organization guardrails. If SCPs and RCPs apply, they must allow the action.
  3. Is there a grant? An identity-based or resource-based policy must allow it.
  4. Principal limits. A permissions boundary or session policy, if present, must also allow it.
  5. Otherwise the request is implicitly denied.

Guardrails never grant. A permission exists where the grants and all the limits overlap.

A permissions boundary is a managed policy attached to a user or role as its ceiling. Its main use is safe delegation: “developers may create roles, but only roles carrying this boundary”. A session policy narrows one particular assumed session.

Same account, different account

Within one account, an allow in either the identity policy or the resource policy is usually enough. Two important exceptions: a role’s trust policy and a KMS key policy must explicitly allow the principal.

There is a subtlety in who the resource policy names. A grant naming a role session ARN, or an IAM user ARN, is not limited by an implicit deny in boundaries or identity policies. A grant naming the role ARN is still capped by the role’s boundary and session policy.

Across accounts, both must agree. The calling account must allow its principal to make the request, and the owning account’s resource policy must allow that principal in. Neither can push access onto the other.

Naming arn:aws:iam::111122223333:root as a principal does not mean the root user only. It trusts the account, which then decides which of its identities get the permission.

Debugging a denial

Read the error: it often names the principal, the action and the kind of policy that blocked it. Then check, in order: who am I really (aws sts get-caller-identity), the exact action and resource ARN, explicit denies, then guardrails. The IAM policy simulator tests identity policies without making calls, IAM Access Analyzer validates policy grammar and flags risky grants, and CloudTrail records the refused request.

Writing a policy, start from what the code calls, name resources exactly, and add conditions such as aws:PrincipalOrgID (only my organization) or aws:SourceArn (only on behalf of this resource) where a service or wildcard principal is involved.

About the video

The embed is a clip (3:16 to 27:07) of AWS’s “IAM Policy Evaluation Series: policy evaluation chains”, March 2023. The chapters in this range walk through a role reaching a resource in the same account, SCPs, resource-based policies with several ways of naming the principal, KMS and trust policy cases, users, and cross-account evaluation. It predates resource control policies, which the organizations lesson covers. I judged it from chapters and description, since transcripts couldn’t be fetched. The companion video in deeper covers the policy language.

What was run: the DynamoDB resource table was read from AWS’s public service reference JSON. No policy was evaluated: there is no account here, and the emulator’s IAM enforcement differs from AWS’s. The example policy and the evaluation rules are written from the documentation, checked in November 2026.

Where this fits

Policies decide what a principal may do. The next lesson is how you become a different principal for a while: assuming roles with STS.

Check yourself

  1. 01A user's policy allows s3:* on everything, and a bucket policy denies s3:GetObject to that user. Can they read the object?

    No. An explicit deny that applies wins over any number of allows, wherever each of them is written.

  2. 02An SCP allows ec2:* for an account, and a user in it has no identity policy. Can the user start an instance?

    No. The SCP only sets the maximum. Without an allow from an identity-based or resource-based policy, the request stays implicitly denied.

  3. 03A role in account A is allowed by its own policy to read a queue in account B. The queue has no resource policy. What happens?

    It is denied. Cross-account access needs an allow on both sides: the identity policy in A and the resource policy in B.

  4. 04You allow dynamodb:Query on a table ARN, and queries against an index of that table fail. Why?

    An index is a separate resource with its own ARN ending in /index/name. Add that ARN to the Resource list.

  5. 05A Deny uses Bool aws:MultiFactorAuthPresent false. Why might a long-lived access key slip past it?

    The key is absent from requests signed with long-term credentials, so a plain Bool test does not match and the deny does not apply. BoolIfExists treats a missing key as matching.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark