fix(iam): read a statement that names no effect as stating nothing (#8268)

The policy evaluator defaulted a statement's Effect to Allow, so a statement
that named none granted what it described. The IAM guide says the element "is
required and specifies whether the statement results in an allow or an explicit
deny" and that "valid values for Effect are Allow and Deny", so a statement
naming neither describes no permission, and a document that describes no
permission is not a document that grants one. A resource policy whose statement
named a principal and an action but no effect allowed that call, and so did a
session policy, a service control policy and an identity policy: a statement is
held to naming an action and a resource when a document is stored, not to naming
an effect, so such a document is kept as written and was then read as a grant.

A statement names one of the two effects the policy language defines or it names
none, and one that names none states nothing. An Effect that is absent, that is
not a string, or that is some other word is read as neither now: the statement
grants nothing, denies nothing, and the request is decided by the rest of the
document. That is already this package's reading of a role trust policy, where a
statement whose Effect names neither effect matches nothing.

The service list behind GetOrganizationsAccessReport read the same default the
other way round. Walking the service control policy levels, every statement that
was not a Deny was counted as an allow, so a statement naming no effect, or
naming some word that is neither, left a service reachable through a statement
that permits nothing. Only an Allow counts there.

No document is held to a shape here: what is stored is read exactly as it was,
and this changes only what reading it comes to.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-14 01:07:34 -04:00
1 parent b658720afe
commit cb03bc373b
4 files changed
+116 -4

No files matched your search

@@ -0,0 +1,105 @@
package io.floci.aws.services.iam;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.services.iam.IamPolicyEvaluator.Decision;
import io.floci.aws.services.iam.IamPolicyEvaluator.ResourcePolicyDecision;
import io.floci.aws.services.iam.model.CallerContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A statement names one of the two effects the policy language defines or it names none, and one
* that names none states nothing: it grants nothing and denies nothing, whichever family of policy
* it was written in. A document that describes no permission must not be read as granting one.
*/
class IamStatementEffectTest {
private final IamPolicyEvaluator evaluator = new IamPolicyEvaluator(new ObjectMapper());
private static String identityStatement(String effectElement) {
return "{\"Version\":\"2012-10-17\",\"Statement\":[{" + effectElement
+ "\"Action\":\"s3:*\",\"Resource\":\"*\"}]}";
}
@Test
void aStatementCarryingNoEffectGrantsNothing() {
String document = identityStatement("");
assertEquals(Decision.DENY, evaluator.evaluate(
CallerContext.of(List.of(document)), null, "s3:GetObject", "arn:aws:s3:::b/k", null));
}
@ParameterizedTest
@ValueSource(strings = {
"\"Effect\":[\"Allow\"],",
"\"Effect\":{\"Allow\":true},",
"\"Effect\":1,",
"\"Effect\":true,",
"\"Effect\":null,",
})
void anEffectThatIsNoStringNamesNeitherOfThem(String effectElement) {
String document = identityStatement(effectElement);
assertEquals(Decision.DENY, evaluator.evaluate(
CallerContext.of(List.of(document)), null, "s3:GetObject", "arn:aws:s3:::b/k", null));
}
@ParameterizedTest
@ValueSource(strings = {"Permit", "Grant", "ALLOWED", "", " Allow"})
void aWordThatIsNeitherEffectGrantsNothing(String effect) {
String document = identityStatement("\"Effect\":\"" + effect + "\",");
assertEquals(Decision.DENY, evaluator.evaluate(
CallerContext.of(List.of(document)), null, "s3:GetObject", "arn:aws:s3:::b/k", null));
}
@Test
void aStatementThatStatesNothingLeavesTheRestOfTheDocumentReadable() {
String document = "{\"Version\":\"2012-10-17\",\"Statement\":["
+ "{\"Action\":\"*\",\"Resource\":\"*\"},"
+ "{\"Effect\":\"Allow\",\"Action\":\"s3:GetObject\",\"Resource\":\"*\"}]}";
assertEquals(Decision.ALLOW, evaluator.evaluate(
CallerContext.of(List.of(document)), null, "s3:GetObject", "arn:aws:s3:::b/k", null));
assertEquals(Decision.DENY, evaluator.evaluate(
CallerContext.of(List.of(document)), null, "s3:PutObject", "arn:aws:s3:::b/k", null));
}
@Test
void aResourcePolicyStatementCarryingNoEffectGrantsNothing() {
String bucketPolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[{"
+ "\"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}";
assertEquals(ResourcePolicyDecision.NEUTRAL, evaluator.evaluateResourcePolicy(
List.of(bucketPolicy), "arn:aws:iam::123456789012:user/alice", "s3:GetObject",
"arn:aws:s3:::b/k", null));
}
@Test
void aSimulatedStatementCarryingNoEffectGrantsNothing() {
assertEquals(Decision.DENY, evaluator.simulateCustomPolicy(
List.of(identityStatement("")), "s3:GetObject", "arn:aws:s3:::b/k", null));
}
@Test
void anScpStatementCarryingNoEffectReachesNoService() {
List<String> reachable =
evaluator.servicesAllowedByScpLevels(List.of(List.of(identityStatement(""))));
assertTrue(reachable.isEmpty(), () -> "reached " + reachable);
}
@Test
void anScpStatementThatAllowsIsStillRead() {
List<String> reachable = evaluator.servicesAllowedByScpLevels(
List.of(List.of(identityStatement("\"Effect\":\"Allow\","))));
assertEquals(List.of("s3"), reachable);
}
}