Sub topic 1
What AWS evaluates: the request and its context
Every call you make to AWS is a request. Before the service does any work, AWS decides whether to allow that request. This chapter describes what goes into that decision. Later chapters cover how the different policy types combine. They all assume you know what the inputs are.
Prerequisites
This chapter assumes you can:
- Tell apart AWS accounts, IAM users, groups, and roles.
- Read JSON.
- Recognize an AWS API action such as
s3:GetObject, and an Amazon Resource Name (ARN) such asarn:aws:s3:::example-reports-bucket/*.
You do not need to know how policies are combined yet. That starts in later chapters.
Authentication comes before authorization
AWS handles each request in two stages, and they answer different questions.
- Authentication asks who is making the request. AWS checks the signature on the request, which comes from an access key, a console sign-in session, or temporary credentials from AWS STS. If this fails, you see errors such as
InvalidClientTokenId,SignatureDoesNotMatch, orExpiredToken. No policy is involved. - Authorization asks whether that identity may do this thing. AWS gathers the policies that apply and evaluates them. If this fails, you see
AccessDenied,AccessDeniedException, orUnauthorizedOperation, depending on the service.
Telling these apart saves time when debugging. An expired token is an authentication problem, and editing policies will not fix it.
The four parts of a request
Authorization works on a set of facts about the request. AWS builds these facts, called the request context, from the request itself and from the environment around it. They fall into four groups.
| Part | Question it answers | Example |
|---|---|---|
| Principal | Who is calling? | An IAM role session, an IAM user, an AWS service, or an anonymous caller |
| Action | What operation is requested? | `s3:PutObject`, `ec2:DescribeInstances` |
| Resource | What is the operation on? | `arn:aws:s3:::example-reports-bucket/2026/summary.csv` |
| Context | What else is true about the request? | Source IP address, time, whether TLS was used, tags |
Principal
The principal is the entity that sent the signed request. For an IAM user, it is the user. For a role, it is a role session: someone or something assumed the role and received temporary credentials. You can see which principal your CLI credentials map to with this command:
aws sts get-caller-identityThe output includes an Arn field. For a role session, it looks like arn:aws:sts::111122223333:assumed-role/ReportWriter/my-session. That is the session ARN. Policies that name the role itself use a different form, arn:aws:iam::111122223333:role/ReportWriter. Mixing up the two forms is a common mistake in Principal elements and in conditions on aws:PrincipalArn.
A principal can also be an AWS service. For example, Amazon S3 can call another service on your behalf. It can also be anonymous, when a request carries no credentials, as with a public S3 object.
Action
An action is the API operation, written as a service prefix and an operation name: s3:GetObject. Three details matter:
- Action names are not always the same as CLI command names. The CLI command
aws s3 cpcalls several API operations depending on what you copy, such asGetObject,PutObject, andListBucket. - One user-visible task can involve several actions. A single click in the console often sends many API calls, and each call is evaluated separately. If one of them is denied, part of the page can fail while the rest loads.
- Some permissions have no matching API call of the same name. For example,
s3:ListBucketauthorizes the list-objects calls.
Resource
The resource is the thing the action targets, identified by ARN. The same task can touch different resource ARNs depending on the action:
s3:GetObjectands3:PutObjectact on an object ARN, such asarn:aws:s3:::example-reports-bucket/2026/summary.csv.s3:ListBucketacts on the bucket ARN,arn:aws:s3:::example-reports-bucket, with no trailing/*.
This is why a policy with "Resource": "arn:aws:s3:::example-reports-bucket/*" allows reading objects but not listing the bucket. The list request targets a different resource, and the statement does not cover it.
Some actions do not support resource-level permissions. For those, the policy must use "Resource": "*". The IAM Service Authorization Reference lists, for each action, which resource types it supports.
Context
The context is a collection of key-value pairs called condition keys. They let a policy depend on more than who, what, and where. There are three families:
- Global keys start with
aws:and exist for requests to any service. Examples areaws:PrincipalArn,aws:PrincipalTag/key,aws:SourceIp,aws:CurrentTime,aws:SecureTransport, andaws:PrincipalOrgID. - Service keys start with the service prefix, such as
s3:prefixorec2:InstanceType. Each service defines its own. - Tag keys carry tags from the principal (
aws:PrincipalTag/...), from the resource (s3:ExistingObjectTag/...,aws:ResourceTag/...), or from the request (aws:RequestTag/...).
A key is only present when it applies to the request. A request signed from inside a VPC through a VPC endpoint does not carry aws:SourceIp the same way an internet request does. You would use aws:VpcSourceIp or aws:SourceVpce instead. A request made by an AWS service on your behalf shows the service's IP address, not yours. Many surprising denials come from conditions that test keys the request never had.
From request to decision
Here is the flow, from the caller to the allow or deny result.
The "gather applicable policies" step depends on the request context. AWS looks at the principal to find its identity-based policies, any permission boundary, and any session policy. It looks at the resource to find a resource-based policy. It looks at the account of the principal to find Organizations policies such as service control policies. Each later chapter covers one of these sources. All of them evaluate against the same context.
Connecting a policy to the request
A policy statement is a set of tests against the request context. The elements map to the four parts like this:
Actionis matched against the requested action.Resourceis matched against the target resource ARN.Principal, in resource-based policies only, is matched against the caller.Conditionis tested against the context keys.
Look at this statement from the identity-based policy used throughout the tutorial:
{
"Sid": "ReadWriteReports",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}Suppose a role session sends s3:GetObject for arn:aws:s3:::example-reports-bucket/2026/summary.csv. The action is in the list. The resource matches the wildcard pattern. The statement has no Condition, so nothing else is tested. The statement applies. The principal is not named in the statement, because the policy is attached to the principal. Whoever holds the policy is the principal the statement covers.
Now suppose the same session sends s3:ListBucket for arn:aws:s3:::example-reports-bucket. The action is not in the list, and the resource does not match example-reports-bucket/*. The statement does not apply, so it contributes nothing to this request. Whether the request is then denied depends on the core rule from the next chapters, but you can already see why this request gets no help from this statement.
Common mistakes
- Reading the policy and ignoring the request. People ask whether the policy looks right. The better question is what the request actually contained: which action name, which resource ARN, which keys.
- Confusing role ARN and session ARN.
aws sts get-caller-identityshows the session form. Policies andaws:PrincipalArnconditions use the role form for assumed roles. - Forgetting that one task means many requests. A tool that lists, reads, and tags objects needs permissions for each action on each resource type.
- Assuming a key is present. Check the Service Authorization Reference and the documentation for the condition key before relying on it.
- Treating authentication errors as permission errors. If the message mentions a token or signature, the credentials are the problem.
Where you can see the request
You do not have to guess what a request contained. AWS CloudTrail records management API calls and includes the fields userIdentity (the principal), eventSource and eventName (the action), and requestParameters (which usually identifies the resource). The errorCode and errorMessage fields show a denied request. The final chapter covers CloudTrail and the IAM policy simulator in depth. The point for now is that every request you debug has a recorded context you can read.
Exercise
A role session runs aws s3 ls s3://example-reports-bucket and gets AccessDenied. The role's only policy has one Allow statement with "Action": ["s3:GetObject", "s3:PutObject"] and "Resource": "arn:aws:s3:::example-reports-bucket/*". Name the action and the resource in the request, and explain why the statement does not apply to it.
Show answer
The request is s3:ListBucket on the bucket ARN arn:aws:s3:::example-reports-bucket. The statement lists only s3:GetObject and s3:PutObject, so the action does not match. Its resource pattern ends in /*, which matches objects but not the bucket itself, so the resource does not match either. The statement contributes nothing to the request, and nothing else allows it, so the request is denied.
Exercise
Why can aws sts get-caller-identity return an ARN containing assumed-role/ReportWriter/my-session while a bucket policy names arn:aws:iam::111122223333:role/ReportWriter, and why does that not mean the bucket policy is wrong?
Show answer
The first value is the ARN of the role session, which is what the credentials identify. The second is the ARN of the role itself. A Principal element naming the role matches sessions of that role, and aws:PrincipalArn also holds the role form for an assumed-role caller. The two forms refer to the same role at different levels, so the bucket policy is written correctly.