Sub topic 4
The core rule: default deny, explicit deny, allow
This chapter assumes you can read IAM policy JSON, know what an action and an ARN are, and have used IAM users and roles. Every request to AWS ends in one of two outcomes: allowed or denied. The core rule decides which.
The three outcomes
AWS applies the same logic to every request, after it has collected all the policies that apply.
- Implicit deny. Every request starts out denied. If no policy mentions the request, it stays denied.
- Explicit deny. If any applicable policy has a statement with
"Effect": "Deny"that matches the request, the request is denied. Nothing can override this. - Allow. If no explicit deny matches, and the policies that apply contain a matching
"Effect": "Allow"statement, the request is allowed.
Order matters: AWS checks for an explicit deny first. An Allow only counts when no Deny matched.
Why an explicit deny always wins
Suppose a role has an identity policy that allows s3:*, and the bucket has a policy with a Deny for requests that do not use TLS. A request over plain HTTP matches both statements. The Deny wins, and the Allow is ignored.
{
"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" } }
}
]
}This statement matches only when aws:SecureTransport is false. A request over HTTPS does not match it, so it is not denied by this statement. It is then allowed only if some other policy contains a matching Allow. A Deny statement never grants anything. It only removes access.
Implicit deny versus explicit deny
The two denials look the same to the caller, but they behave differently.
| Row | Implicit deny | Explicit deny |
|---|---|---|
| Cause | No statement matches | A Deny statement matches |
| Fixed by | Adding an Allow somewhere | Removing or narrowing the Deny |
| Can another policy override it? | Yes, an Allow changes the outcome | No |
This is why adding more Allow statements does not fix a denial caused by an explicit Deny. You have to find the Deny.
A worked example
A role ReportWriter has this identity policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadWriteReports",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::example-reports-bucket/*"
}
]
}Consider three requests made over HTTPS:
s3:GetObjectonexample-reports-bucket/2026/summary.csv: the Allow matches and nothing denies it. Allowed.s3:DeleteObjecton the same object: no statement matches the action. Implicit deny.s3:GetObjectonother-bucket/file.txt: the resource does not match. Implicit deny.
Now make the same GetObject request over HTTP while the TLS-deny bucket policy is in place. The Deny matches, so the result is an explicit deny, even though the identity policy still allows the action.
Common mistakes
- Assuming "no Deny" means allowed. Without an Allow, the request is still denied by default.
- Trying to fix an explicit deny by adding an Allow. The Allow has no effect. Look for the Deny in every policy type that applies.
- Forgetting the condition. A broad Deny with a condition only blocks the requests that meet the condition.
Exercise
A user's identity policy allows s3:GetObject on arn:aws:s3:::example-reports-bucket/*. The bucket policy has a Deny on s3:GetObject for requests where aws:SecureTransport is false. The user makes a GetObject request over HTTPS. What is the result, and what is it over HTTP?
Show answer
Over HTTPS the Deny condition is false, so the Deny does not match. The identity policy's Allow matches, so the request is allowed. Over HTTP the Deny matches, so the request is explicitly denied, and the Allow cannot override it.
Exercise
A role has no policy that mentions dynamodb:GetItem. A teammate says the role "isn't denied", so the call should work. What is the outcome, and what type of denial is it?
Show answer
The call is denied. With no matching Allow, the request is an implicit deny, because every request is denied by default.