Sub topic 15
How AWS evaluates a request: allow, deny, and implicit deny
This chapter assumes you can read IAM policy JSON and know the difference between an identity-based policy and a resource-based policy. It also assumes you know what a role is. It explains how AWS combines every applicable policy into one decision, and why a request that looks allowed is sometimes refused.
Every request starts denied
When a principal sends a request, AWS first authenticates it and gathers the request context: the principal, the action, the resource, and condition values such as the source IP or whether MFA was used. AWS then evaluates all the policies that apply to that request.
There are three possible outcomes:
- Explicit deny. A policy contains a matching
Denystatement. The request fails. - Allow. No explicit deny matches, and the required policies contain a matching
Allow. The request succeeds. - Implicit deny. Nothing matches at all. The request fails because access is denied by default.
An implicit deny is not a statement anyone wrote. It is the absence of an Allow. An explicit deny is a deliberate Deny statement.
The order of the decision
The simplest way to think about evaluation is as a series of questions. The first "no" or explicit deny ends it.
The diagram simplifies two details. If a session policy is present, it must also allow the action. In the resource-based branch, the shortcut applies only when the policy names the user or role directly, as the same-account section below explains.
- Explicit deny wins. AWS checks every policy type for a matching
Deny. A single one ends evaluation, whatever else saysAllow. - Service control policies (SCPs). If the account belongs to an organization, an SCP must allow the action. SCPs grant nothing. They set the maximum that identities in the account can ever receive. SCPs never apply to the organization's management account's resources in the way people often expect, and they do not affect service-linked roles. Check the AWS documentation for the full list of exemptions.
- Resource-based policies. These can allow access on their own in some cases.
- Permissions boundaries. A boundary on a user or role caps what its identity-based policies can grant.
- Session policies. When you assume a role or federate with an inline policy, that policy further narrows the session.
- Identity-based policies. Policies attached to the user, to the user's groups, or to the role must contain a matching
Allow.
Each layer that restricts must agree. A request is allowed only when no layer denies it and the required layers allow it.
Allow versus deny in one policy set
Suppose a role has an identity-based policy that allows ec2:* on everything. The role also receives this policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyStopWithoutMFA",
"Effect": "Deny",
"Action": "ec2:StopInstances",
"Resource": "*",
"Condition": {
"BoolIfExists": { "aws:MultiFactorAuthPresent": "false" }
}
}
]
}ec2:StartInstances is still allowed, because the deny names only ec2:StopInstances. ec2:StopInstances is denied when MFA information is absent or false. The condition operator matters here. With plain Bool, a request that carries no aws:MultiFactorAuthPresent key (long-term access keys never include it) would not match the condition, so the deny would not apply. BoolIfExists also matches when the key is missing, which makes the deny catch those requests.
Same-account access
Within a single account, an Allow from either an identity-based policy or a resource-based policy can be enough, as long as nothing denies the request. There is a refinement for resource-based policies. If the policy names the user or role by ARN as the Principal, that grant applies directly, and the identity does not also need an identity-based Allow.
If a policy names only the account root, such as arn:aws:iam::111122223333:root, it delegates the decision to that account. The identity still needs its own identity-based Allow.
Permissions boundaries still apply to the identity-based side. A boundary does not remove access that a resource-based policy grants directly to the user or role ARN.
Cross-account access
When the requester and the resource are in different accounts, both accounts must permit the request. This is an AND, not an OR.
- The resource account must allow it, through a resource-based policy or by a role the principal assumes there.
- The requester's account must allow it, through an identity-based policy that permits the action.
Consider this bucket policy in the account that owns the bucket:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPartnerRead",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::444455556666:root" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
}
]
}This trusts account 444455556666, but it does not give any identity there access by itself. An administrator in 444455556666 must also attach a policy to a specific user or role that allows s3:GetObject on that bucket. Without it, the result is an implicit deny, even though the bucket policy looks generous.
Assuming a role works differently. After the caller assumes a role in the resource account, the caller acts as that role. Evaluation then uses the role's policies and the resource account's rules, as if the request were same-account.
Checking which policy decided
Several kinds of mistakes produce the same "AccessDenied" message, so you need to know which layer refused. Work through them in this order:
| Question | What to check |
|---|---|
| Is there an explicit deny? | Search all policies, including SCPs, boundaries, and session policies, for matching `Deny` statements |
| Does an SCP limit the account? | The organization's policies attached to the account or its OU |
| Does a boundary exist? | The principal's permissions boundary, if one is set |
| Is there a matching allow? | Action, resource ARN, and conditions in the identity-based policy |
| Are the ARNs right? | Bucket-level actions such as `s3:ListBucket` need the bucket ARN. Object actions such as `s3:GetObject` need `bucket/*` |
The last row is a frequent cause of implicit denies. In the first example from this tutorial, s3:ListBucket is paired with arn:aws:s3:::amzn-s3-demo-bucket, and s3:GetObject with arn:aws:s3:::amzn-s3-demo-bucket/*. Swap them and neither statement matches the request.
Common mistakes
- Expecting two Allows to combine across a boundary. An action must be allowed by the identity-based policy and by the boundary. Allowing it in only one is an implicit deny.
- Treating an SCP as a grant. An SCP with
"Action": "*"allowed does not give anyone permissions. It only removes the ceiling. - Forgetting the second half of cross-account access. Both accounts must allow the request.
- Using
NotActionorNotResourcewithAllow. These match everything except what you list, which often grants far more than you intended. - Testing a deny with the wrong credentials. The deny condition may depend on MFA, source IP, or tags, and your test session may not carry them.
Exercise
A role in account 444455556666 has an identity-based policy allowing s3:GetObject on arn:aws:s3:::amzn-s3-demo-bucket/*. The bucket is in account 111122223333, and its bucket policy has no statement that mentions account 444455556666. A user assumes the role and calls GetObject. What is the result, and what must change?
Show answer
The result is an implicit deny. In a cross-account request, both accounts must allow it. The role's identity-based policy allows it, but the resource account has granted nothing. The bucket policy needs an Allow for the role, or for the account 444455556666, so that both sides agree. An explicit deny is not involved, because no Deny statement matched.
Exercise
A user has an identity-based policy with Allow on ec2:StopInstances, and a separate policy with a Deny on ec2:StopInstances using Bool with aws:MultiFactorAuthPresent set to "false". The user signs in with long-term access keys and no MFA, then calls the action. Is it denied? How would you make sure it is?
Show answer
It is probably allowed. Requests made with long-term access keys do not carry aws:MultiFactorAuthPresent. With plain Bool, a missing key makes the condition false, so the deny does not match and the identity-based Allow wins. Changing the operator to BoolIfExists makes the condition match when the key is absent, so the explicit deny applies.