fix(iam): check PutEvents on each entry's event bus (#6704)

PutEvents was checked on `*`: the request-resources table gave it no
resources, as its bus is a field of each entry, which no rule read. A
policy allowing or denying events:PutEvents on one event bus therefore
did not hold for publishing.

Each entry's EventBusName is "the name or ARN of the event bus to
receive the event", and "if you omit this, the default event bus is
used". Bus policies grant events:PutEvents on `event-bus/<name>`. The
EventBridge User Guide checks events:PutEvents against "the bus, once
per entry in the request", and says "Publishing is authorized against
the bus ARN for every entry in the request. If one entry fails an
authorization condition, EventBridge denies the whole request." It says
so in its section on the Custom Event Bus, which keeps the events: IAM
namespace of the Classic one; nothing in the guide says otherwise for a
Classic bus, whose API model lists AccessDeniedException among the error
codes of an entry without saying when.

The table now reads PutEvents' `Entries[].EventBusName`, a field of each
of a list's structures, one resource for each entry:

- The generator takes a correction filling a variable from such a field,
  and finds a field whose pattern takes an ARN before a name inside a
  list's structures, as it does a top-level member, so the field gets
  `arnOf` from botocore.
- The loader reads `Name[].Field` in `fill`, and in `absent` and `arnOf`
  when it fills a variable.
- The reader gives one value for each entry, the `absent` value for an
  entry that names no bus, gives a null or a blank, as the handler's
  `asText(null)` does, and none for no entries, which stay on `*`. Each
  value that is an ARN puts its own entry's bus in that ARN's account and
  Region, checked as given and as the caller's, which the handler
  publishes to; until now the first ARN a request gave set the account
  and Region of every value.

The filter checks every resource, so one entry for a bus the caller may
not publish to refuses the whole request, as the guide gives it.

Not in this change: the events:source and events:detail-type condition
keys (Floci supplies neither), EndpointId (the handler ignores it), and
PutPartnerEvents, which stays on `*`.

The upstream drift check on a pull request now verifies only the
vendored IAM files the pull request changes, each with its generator,
its tests and the modules that generator imports. It verified all six
files whichever one a pull request touched, so this change, which
touches only the table of the resources requests name, failed on the
service namespace list, which AWS's index stopped matching when it
dropped `codestar`: drift in a file the change leaves alone. The
pull request's job passes the paths its merge commit changes to
`make iam-data-verify CHANGED=...`, which names each check it skips;
the weekly and manual runs, and a diff that cannot be read, still
check every file, so the namespace list's drift is reported there.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-26 21:52:09 -05:00
1 parent 5c9eb3eb30
commit 0410a2b4ea
11 files changed
+384 -62

No files matched your search

@@ -100,10 +100,25 @@ class RequestResourceMembersTest {
+ "{\"resources\":[],\"creates\":[{\"type\":\"part\",\"parent\":\"thing\",\"arn\":\"ThingArn\"}]}}}"),
part);
}
// A member past one structure, or a structure's member filling a variable.
// A member past one structure, or filling a variable from a lone structure's member or a list in a list.
assertThrows(IllegalStateException.class, () -> parse(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].B.ThingArn\"}")));
assertThrows(IllegalStateException.class, () -> parse(document(formats,
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"A[].Name\"}}")));
for (String bad : List.of("A.Name", "A[].Names[]", "A[].B.Name")) {
assertThrows(IllegalStateException.class, () -> parse(document(formats,
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"" + bad + "\"}}")), bad);
}
// A field of each of a list's structures fills a variable, read as given when absent or as an ARN, which
// only a member filling a variable is.
Member each = new Member("A", true, new Member("Name", false));
assertEquals(List.of(new Resource(List.of("thing"), null, Map.of("ThingName", each), Map.of(), Map.of(),
Map.of("A[].Name", "default"), Map.of("A[].Name", "thing"), null, null)),
parseUnchecked(document(formats, "{\"type\":\"thing\",\"fill\":{\"ThingName\":\"A[].Name\"},"
+ "\"absent\":{\"A[].Name\":\"default\"},\"arnOf\":{\"A[].Name\":\"thing\"}}"))
.operations().get("a:Op"));
assertEquals("A[].Name", each.path());
for (String bad : List.of("\"absent\":{\"A[].Name\":\"default\"}", "\"arnOf\":{\"A[].Name\":\"thing\"}")) {
assertThrows(IllegalStateException.class, () -> parse(document(formats,
"{\"type\":\"thing\",\"fill\":{\"ThingName\":\"Name\"}," + bad + "}")), bad);
}
assertEquals(List.of(new Resource(List.of("thing"), new Member("A", true, new Member("ThingArns", true)), Map.of(),
Map.of(), Map.of(), Map.of(), Map.of(), null, null)), parseUnchecked(document(formats, "{\"types\":[\"thing\"],\"arn\":\"A[].ThingArns[]\"}"))
.operations().get("a:Op"));
@@ -292,6 +292,38 @@ class RequestResourcesTest {
assertEquals(List.of(events + "event-bus/default"), of("events:DescribeEventBus", json("{\"Name\":null}")));
}
/**
* Each {@code PutEvents} entry is published to the event bus it names, by name or ARN, in the account and Region
* that ARN gives, or to the default one when it names none, gives a null or a blank; a request publishing nothing
* names no bus.
*/
@Test
void eachEntryIsOnTheEventBusItNames() {
String events = "arn:aws:events:us-east-1:000000000000:";
assertEquals(List.of(events + "event-bus/orders", events + "event-bus/default", events + "event-bus/audit"),
of("events:PutEvents", json("{\"Entries\":[{\"EventBusName\":\"orders\"},{\"Source\":\"s\"},"
+ "{\"EventBusName\":\"audit\"},{\"EventBusName\":\"orders\"}]}")));
assertEquals(List.of(events + "event-bus/default"), of("events:PutEvents",
json("{\"Entries\":[{\"EventBusName\":null},{\"EventBusName\":\"\"},{\"EventBusName\":\" \"}]}")));
// Each ARN puts its entry's bus in its own account and Region, checked as the caller's too.
assertEquals(List.of("arn:aws:events:eu-west-1:111122223333:event-bus/orders",
"arn:aws:events:us-east-1:111122223333:event-bus/orders",
"arn:aws:events:eu-west-1:000000000000:event-bus/orders", events + "event-bus/orders",
events + "event-bus/audit", "arn:aws:events:us-east-1:444455556666:event-bus/billing",
events + "event-bus/billing"), of("events:PutEvents", json("{\"Entries\":["
+ "{\"EventBusName\":\"arn:aws:events:eu-west-1:111122223333:event-bus/orders\"},"
+ "{\"EventBusName\":\"audit\"},"
+ "{\"EventBusName\":\"arn:aws:events:us-east-1:444455556666:event-bus/billing\"}]}")));
assertEquals(List.of(events + "event-bus/orders"), of("events:PutEvents",
json("{\"Entries\":[{\"EventBusName\":\"arn:aws:events:::event-bus/orders\"}]}")));
assertEquals(List.of(), of("events:PutEvents", json("{\"Entries\":[]}")));
assertEquals(List.of(), of("events:PutEvents", json("{}")));
// A form's entries run from 1 to the first it gives nothing of.
assertEquals(List.of(events + "event-bus/orders", events + "event-bus/default"), of("events:PutEvents",
form("Action=PutEvents&Entries.member.1.EventBusName=orders&Entries.member.2.Source=s"
+ "&Entries.member.4.EventBusName=late")));
}
/**
* A connection or an API destination, whose ARN EventBridge follows with an id it mints after the name, is the
* one stored under the name the request gives, and has that id open when none is or nothing looks it up.
@@ -23,6 +23,7 @@ import java.util.Map;
import static io.github.hectorvent.floci.testing.EnforcementFixtures.auth;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -374,6 +375,36 @@ class IamRequestResourceEnforcementIntegrationTest {
.then(), "events:DescribeEventBus");
}
/**
* Publishing is authorized on the bus of every entry, the one it names by name or ARN or the default one when
* it names none, so a grant on one bus refuses a batch with an entry for another, and a deny on one bus holds
* however many entries go elsewhere.
*/
@Test
void eachEventIsCheckedOnTheBusItsEntryNames() {
String bus = "res-bus-" + suffix();
admin("events").header("X-Amz-Target", "AWSEvents.CreateEventBus").contentType("application/x-amz-json-1.1")
.body("{\"Name\":\"" + bus + "\"}").post("/").then().statusCode(200);
cleanup.register(() -> admin("events").header("X-Amz-Target", "AWSEvents.DeleteEventBus")
.contentType("application/x-amz-json-1.1").body("{\"Name\":\"" + bus + "\"}").post("/"));
String byName = ",\"EventBusName\":\"" + bus + "\"";
String byArn = ",\"EventBusName\":\"" + EVENTS + "event-bus/" + bus + "\"";
User user = user("res-put-events");
user.policy(allowOn("events:PutEvents", EVENTS + "event-bus/" + bus));
putEvents(user, byName, byArn).statusCode(200).body("FailedEntryCount", equalTo(0));
refusedJson(putEvents(user, byName, ""), "events:PutEvents");
refusedJson(putEvents(user, ""), "events:PutEvents");
user.policy(allowOn("events:PutEvents", EVENTS + "event-bus/" + bus) + ","
+ allowOn("events:PutEvents", EVENTS + "event-bus/default"));
putEvents(user, byName, "").statusCode(200).body("FailedEntryCount", equalTo(0));
user.policy(allowOn("events:PutEvents", "*") + ",{\"Effect\":\"Deny\",\"Action\":\"events:PutEvents\","
+ "\"Resource\":\"" + EVENTS + "event-bus/" + bus + "\"}");
refusedJson(putEvents(user, "", "", byArn), "events:PutEvents");
putEvents(user, "", ",\"EventBusName\":null").statusCode(200).body("FailedEntryCount", equalTo(0));
}
@Test
void aUserPoolIsCheckedOnTheArnItsIdNames() {
String id = admin("cognito-idp").header("X-Amz-Target", "AWSCognitoIdentityProviderService.CreateUserPool")
@@ -522,6 +553,17 @@ class IamRequestResourceEnforcementIntegrationTest {
.post("/").then();
}
/** Publishes an event for each of {@code buses}, the bus of its entry as a JSON member or none. */
private static ValidatableResponse putEvents(User user, String... buses) {
StringBuilder entries = new StringBuilder();
for (String bus : buses) {
entries.append(entries.isEmpty() ? "" : ",")
.append("{\"Source\":\"res.test\",\"DetailType\":\"t\",\"Detail\":\"{}\"").append(bus).append('}');
}
return user.json("events", "AWSEvents.PutEvents", "1.1").body("{\"Entries\":[" + entries + "]}")
.post("/").then();
}
private static String publishVersion(String arn) {
return admin("states").header("X-Amz-Target", "AWSStepFunctions.PublishStateMachineVersion")
.contentType("application/x-amz-json-1.0").body("{\"stateMachineArn\":\"" + arn + "\"}")