Sub topic 4
The core rule: default deny, explicit deny, allow
This chapter assumes you know what an IAM principal is (a user, role, or the account root user), what an API action looks like (s3:GetObject), and what an ARN is. You should also be able to read a JSON policy. The chapter covers the one rule that every other IAM policy mechanism plugs into. Later chapters add resource policies, boundaries and SCPs. They all follow the logic described here.
Three possible outcomes
Every request to an AWS service ends in one of three internal states:
| Outcome | Meaning | Final result |
|---|---|---|
| Implicit deny | No policy mentioned the request, so nothing granted it. | Denied |
| Explicit allow | A statement with `"Effect": "Allow"` matched the request. | Allowed, unless something else denies it |
| Explicit deny | A statement with `"Effect": "Deny"` matched the request. | Denied, always |
The rule has three parts:
- Default deny. Everything is denied unless something allows it. The only exception is the account root user, which has full access to its own account's resources by default.
- Allow. An Allow statement can turn the default deny into access. IAM grants permissions only through Allow statements in identity-based policies and resource-based policies.
- Explicit deny wins. A matching Deny statement in any applicable policy ends the evaluation with a denial. No Allow anywhere can override it.
Some policy types never grant anything. Permission boundaries, session policies, and service control policies (SCPs) only limit what an Allow can do. They make the effective result narrower, never wider.
What "matches" means
A statement only affects a request if it matches. A statement matches when all of these are true:
- The request's action is listed in
Action(or is not listed inNotAction). - The request's resource is listed in
Resource(or is not listed inNotResource). - For resource-based policies, the caller is covered by
Principal. - Every
Conditionblock evaluates to true for the request context.
A statement that does not match is ignored. It does not count as a deny. This detail causes many mistakes, and a later section shows one.
Walking through the decision
The following diagram shows the core decision. It is simplified: it treats "an Allow exists" as one step, and later chapters split that step into the identity, resource, boundary, session, and SCP checks.
The order matters. AWS looks for explicit denies first, regardless of how many Allow statements exist. Ten Allows and one Deny give a denial.
A worked example
Two statements apply to the same principal. The first is an identity-based policy that allows reads and writes on a bucket's objects.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadWriteReports",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}
]
}The second is a bucket policy statement that denies any request not sent over TLS.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyInsecureTransport",
"Effect": "Deny",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::example-reports-bucket",
"arn:aws:s3:::example-reports-bucket/*"
],
"Condition": { "Bool": { "aws:SecureTransport": "false" } }
}
]
}Consider four requests from the principal that has the first policy attached:
| Request | Evaluation | Result |
|---|---|---|
| `s3:GetObject` on `example-reports-bucket/a.csv` over HTTPS | The Deny condition is false, so that statement does not match. The Allow matches. | Allowed |
| `s3:GetObject` on `example-reports-bucket/a.csv` over plain HTTP | The Deny matches (`aws:SecureTransport` is `false`). | Denied (explicit deny) |
| `s3:DeleteObject` on `example-reports-bucket/a.csv` over HTTPS | The Deny does not match. No Allow lists `s3:DeleteObject`. | Denied (implicit deny) |
| `s3:GetObject` on a different bucket over HTTPS | No statement matches. | Denied (implicit deny) |
The second row is the explicit deny case. The Allow in the identity policy matches, but the Deny takes precedence. The third and fourth rows show the default deny: nothing granted the request, so it fails without anything ever refusing it.
Implicit deny versus explicit deny
Both produce an AccessDenied error, but they differ in how you fix them.
- Implicit deny means something is missing. Add an Allow in an identity-based or resource-based policy, and make sure no boundary, session policy, or SCP removes it.
- Explicit deny means something is present. You must find the Deny statement and change it, or change the request so the statement's condition no longer matches. Adding more Allows does nothing.
For same-account requests, AWS error messages often say which kind occurred. Typical phrases are "no identity-based policy allows the action" (implicit) and "with an explicit deny in a service control policy" (explicit). Read the message before you edit any policy.
Why a condition on a Deny can mislead you
A Deny only applies when it matches. Suppose you want to deny everything outside a region and write a Deny with a condition on aws:RequestedRegion. For a request in an allowed region, that statement does not match. It is not a "pass". The request still needs an Allow from somewhere else.
This leads to a common design rule:
- Use Allow statements to say what is permitted.
- Use Deny statements for guardrails that must hold no matter what other policies say.
A Deny with a negative condition, such as "deny unless the request uses TLS", is a typical guardrail. Write it so the condition is true only for the bad case. The aws:SecureTransport example above does this: the condition is true only when the transport is insecure.
Common wildcard and negation mistakes
Several patterns change which statements match, and they interact with the deny-wins rule.
"Action": "*"with"Effect": "Deny"blocks every action the policy covers, for every principal it applies to. Check theResourceandPrincipalclosely before you attach it.NotActionwith Allow grants everything except the listed actions. It does not deny the listed actions. They stay under the default deny only if nothing else allows them.NotActionwith Deny denies everything except the listed actions. This is a strong pattern, and a mistake can lock out a whole account's users.- Overlapping resources.
arn:aws:s3:::example-reports-bucket/*matches objects only. Bucket-level actions such ass3:ListBucketapply toarn:aws:s3:::example-reports-bucket, with no/*. An Allow written for only the object ARN does not grant listing.
Where the other policy types fit
The core rule stays the same as more policy types join in. The later chapters fill in these details:
- Identity-based and resource-based policies are the only places an Allow can come from.
- A permission boundary, a session policy, or an SCP can each remove permissions that an Allow would otherwise provide. If one of them lacks an Allow for the request, the result is an implicit deny. If one of them contains a matching Deny, the result is an explicit deny.
- A matching Deny in any one of these policies, or in an identity-based or resource-based policy, denies the request.
The simplest way to remember it: a request must pass every applicable layer, and any single explicit deny stops it.
Checking a decision yourself
You can ask the IAM policy simulator to evaluate a request and show which statements matched. This command evaluates two actions for a role against one object.
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::111122223333:role/ReportWriter \
--action-names s3:GetObject s3:PutObject \
--resource-arns arn:aws:s3:::example-reports-bucket/2026/summary.csvFor each action, the output has an EvalDecision of allowed, implicitDeny, or explicitDeny. These are the same three outcomes described above. For denials, MatchedStatements lists the statements that took part, with the source policy and statement positions. An implicitDeny with an empty MatchedStatements list means no statement matched at all, so you need to add an Allow. An explicitDeny names the Deny that you need to change.
Summary of the rule
- Requests start denied.
- An Allow in an identity-based or resource-based policy can grant access.
- A matching Deny anywhere overrides every Allow.
- A statement that does not match is ignored, not treated as allow or deny.
- Other policy types can only limit what Allow statements grant.
Exercise
A role has an identity-based policy that allows s3:GetObject and s3:PutObject on arn:aws:s3:::example-reports-bucket/*. The bucket policy contains only the DenyInsecureTransport statement shown in this chapter. The role calls s3:DeleteObject on an object in that bucket over HTTPS. What is the result, and what must change for the request to succeed?
Show answer
The result is an implicit deny. The Deny statement does not match because the request uses TLS, so aws:SecureTransport is "true". No Allow lists s3:DeleteObject, so the default deny stays in place. To fix it, add s3:DeleteObject to an Allow in the role's identity-based policy (or in a bucket policy that names the role), and confirm that no permission boundary, session policy, or SCP removes it.
Exercise
A developer has an Allow for s3:* on all resources in an identity policy. An SCP on the account contains a Deny for s3:DeleteBucket. The developer calls s3:DeleteBucket. Is the call allowed, and which outcome name describes the decision?
Show answer
The call is denied. The SCP's matching Deny is an explicit deny, and an explicit deny overrides any Allow, including the developer's s3:*. Adding or widening Allow statements cannot fix it. Only changing or removing the SCP statement, or changing the request so the statement no longer matches, can.