fix(core): route a Query action by its service's botocore model (#5879)

A Query request without a usable credential scope is routed by its
Action and Version, and IAM enforcement authorizes it under the service
that routing picks. The names each service routed were kept by hand in
AwsQueryController and had drifted from what the services serve: 170
names Floci dispatches, across eight services, reached no service and
fell through to SQS. They answered UnsupportedOperation in SQS's
namespace and were authorized as SQS actions.

Each Query service's API versions and operations now come from its
botocore models: tools/aws/regen_query_services.py writes them, from the
pinned botocore, to aws/query-services.json, and make aws-data-check
fails when the file is stale. Every name a service defines reaches it,
implemented here or not. Floci keeps the list of services and their
order, Cognito's names, which no Query model holds, and ElastiCache's
ValidateIamAuthToken, which no model defines.

A name several services define goes to the first of them when the
request names no Version. Ten such names get a pinned owner instead,
the service that serves them here, where the order would pick an
earlier one that does not. The routing parity test checks every
dispatched action with and without a Version and no longer needs its
list of known gaps.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-17 10:17:18 -05:00
1 parent 4f4db89d8f
commit 30d8d3ff5c
8 files changed
+2325 -705

No files matched your search

@@ -7,7 +7,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -20,9 +19,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Guards the rule that an action a Query handler dispatches is an action routing sends to that
* handler. The two lists are maintained by hand in different files, so they drift: #5032 was 28
* IAM operations that had drifted out, and the same gap exists today for most other Query
* services, which is what this test makes visible and stops growing.
* handler. Routing knows each service's actions from its botocore models
* ({@code aws/query-services.json}, generated by {@code tools/aws/regen_query_services.py}) and the
* handlers dispatch what Floci implements, so the two are kept apart; before they were generated,
* the hand-kept routing sets drifted: #5032 was 28 IAM operations that had drifted out, and 170
* names across eight services were unrouted when the sets were replaced.
*
* <p>Routing only decides anything when a request arrives without a usable credential scope,
* because otherwise the service comes from the SigV4 scope. On that path there is the action name
@@ -33,15 +34,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* is the part worth a test.
*
* <p>Each action is routed with its own service's {@code Version}, as any Query client sends it,
* and again without one, as a hand-rolled request may leave it out. Without it a name two services
* share goes to whichever is tried first, so that path is only held to reaching a service that
* dispatches the name.
*
* <p>The known gaps live in {@code src/test/resources/query-routing-known-gaps.tsv} rather than
* here, so that fixing one is a line removed from a data file. The list is checked both ways: a new
* gap fails {@link #everyDispatchedActionRoutesToItsOwnService} or
* {@link #withoutAVersionEveryActionReachesAServiceThatDispatchesIt}, and a gap that has been fixed
* without delisting fails {@link #theKnownGapListHasNoStaleEntries}.
* and again without one, as a hand-rolled request may leave it out. Without it a name several
* services define goes to the first that defines it, or to the one
* {@code AwsQueryController.UNVERSIONED_OWNERS} names, so that path is held to reaching a service
* that dispatches the name.
*/
class AwsQueryActionRoutingParityTest {
@@ -53,27 +49,6 @@ class AwsQueryActionRoutingParityTest {
}
}
/** A heading in the gap file: what it labels, and the three counts it claims for its rows. */
private record GapHeading(String label, String line, int total, int unrouted, int claimed) {
private static GapHeading of(String label, Matcher heading, int firstCount) {
return new GapHeading(label, heading.group(),
Integer.parseInt(heading.group(firstCount)),
Integer.parseInt(heading.group(firstCount + 1)),
Integer.parseInt(heading.group(firstCount + 2)));
}
/** Records a mismatch when the unrouted and claimed rows counted under it disagree with it. */
private void check(int[] rows, List<String> wrong) {
int rowTotal = rows[0] + rows[1];
if (total != rowTotal || unrouted != rows[0] || claimed != rows[1]) {
wrong.add("the " + label + " heading says " + total + " (" + unrouted + " unrouted, "
+ claimed + " claimed) but the rows under it are " + rowTotal + " ("
+ rows[0] + " unrouted, " + rows[1] + " claimed): " + line);
}
}
}
private static final String HANDLERS_ROOT = "src/main/java/io/github/hectorvent/floci/services/";
/**
@@ -137,8 +112,6 @@ class AwsQueryActionRoutingParityTest {
Map.entry("elasticbeanstalk", "2010-12-01"),
Map.entry("redshift", "2012-12-01"));
private static final Path KNOWN_GAPS = Path.of("src/test/resources/query-routing-known-gaps.tsv");
/**
* A {@code case} arm's label list, which may carry several names and may wrap across lines.
* Only quoted labels are taken, so a {@code case} on an enum constant contributes nothing.
@@ -147,23 +120,14 @@ class AwsQueryActionRoutingParityTest {
Pattern.compile("case\\s+((?:\"[A-Za-z0-9]+\"\\s*,?\\s*)+)\\s*(?:->|:)");
private static final Pattern QUOTED_LABEL = Pattern.compile("\"([A-Za-z0-9]+)\"");
/** {@code # 189 entries: 171 unrouted, 18 claimed by another service.} */
private static final Pattern TOTAL_HEADING = Pattern.compile(
"^#\\s*(\\d+) entries: (\\d+) unrouted, (\\d+) claimed by another service\\.?$");
/** {@code # autoscaling: 17 (13 unrouted, 4 claimed elsewhere)} */
private static final Pattern SERVICE_HEADING = Pattern.compile(
"^#\\s*([a-z0-9-]+): (\\d+) \\((\\d+) unrouted, (\\d+) claimed elsewhere\\)$");
@Test
void everyDispatchedActionRoutesToItsOwnService() throws IOException {
Set<String> known = knownGaps();
List<String> unexpected = new ArrayList<>();
for (QueryHandler handler : HANDLERS) {
for (String action : dispatchedActions(handler)) {
String reached = reached(handler, action);
if (!handler.service().equals(reached)
&& !known.contains(gapKey(handler.service(), action, reached))) {
if (!handler.service().equals(reached)) {
unexpected.add(handler.service() + " dispatches " + action
+ " but a request for it reaches " + reached);
}
@@ -173,9 +137,9 @@ class AwsQueryActionRoutingParityTest {
assertTrue(unexpected.isEmpty(),
"An action a handler dispatches has to route to that handler, or a request without "
+ "a credential scope answers in the wrong namespace and is authorized "
+ "under it too. Add the name to its service's set in AwsQueryController; "
+ "a name another service also defines is then told apart by the request's "
+ "Version. New: " + unexpected);
+ "under it too. A name the service's botocore model defines comes in with "
+ "'make aws-data-sync'; one no model defines is added to its service in "
+ "AwsQueryController.QUERY_SERVICES. New: " + unexpected);
}
/**
@@ -187,15 +151,13 @@ class AwsQueryActionRoutingParityTest {
*/
@Test
void withoutAVersionEveryActionReachesAServiceThatDispatchesIt() throws IOException {
Set<String> known = knownGaps();
Map<String, Set<String>> dispatched = dispatchedByService();
List<String> unexpected = new ArrayList<>();
for (QueryHandler handler : HANDLERS) {
for (String action : dispatchedActions(handler)) {
String reached = reachedWithoutVersion(action);
if (!dispatched.getOrDefault(reached, Set.of()).contains(action)
&& !known.contains(gapKey(handler.service(), action, reached))) {
if (!dispatched.getOrDefault(reached, Set.of()).contains(action)) {
unexpected.add(handler.service() + " dispatches " + action
+ " but without a Version a request for it reaches " + reached);
}
@@ -204,39 +166,35 @@ class AwsQueryActionRoutingParityTest {
assertTrue(unexpected.isEmpty(),
"Without a Version an action has to reach a service that dispatches it, or the "
+ "request answers UnsupportedOperation in a namespace it was never for. "
+ "A set in AwsQueryController claims a name its handler does not "
+ "dispatch, ahead of the service that does: " + unexpected);
+ "request answers UnsupportedOperation from a service that does not serve "
+ "it. A service tried earlier defines the name too: name the one that "
+ "dispatches it in AwsQueryController.UNVERSIONED_OWNERS. " + unexpected);
}
/**
* The other direction, which is what keeps the list honest: once a gap is fixed its line has to
* go, or the file slowly stops describing the tree and a later regression hides behind a stale
* entry.
* An entry in {@code UNVERSIONED_OWNERS} only decides between services that all define the
* name, so it has to name one of them, and the name has to have more than one: an owner that
* does not define the name sends a request where it can never be served, and a name only one
* service defines needs no owner.
*/
@Test
void theKnownGapListHasNoStaleEntries() throws IOException {
Map<String, Set<String>> dispatched = dispatchedByService();
Set<String> live = new LinkedHashSet<>();
for (QueryHandler handler : HANDLERS) {
for (String action : dispatchedActions(handler)) {
String reached = reached(handler, action);
if (!handler.service().equals(reached)) {
live.add(gapKey(handler.service(), action, reached));
}
String reachedWithoutVersion = reachedWithoutVersion(action);
if (!dispatched.getOrDefault(reachedWithoutVersion, Set.of()).contains(action)) {
live.add(gapKey(handler.service(), action, reachedWithoutVersion));
void everyUnversionedOwnerIsOneOfTheServicesThatDefineTheName() {
List<String> wrong = new ArrayList<>();
AwsQueryController.UNVERSIONED_OWNERS.forEach((action, owner) -> {
List<String> definers = new ArrayList<>();
for (Map.Entry<String, String> service : API_VERSIONS.entrySet()) {
if (service.getKey().equals(AwsQueryController.inferServiceFromAction(action, service.getValue()))) {
definers.add(service.getKey());
}
}
}
if (!definers.contains(owner)) {
wrong.add(action + " is owned by " + owner + ", which does not define it; " + definers + " do");
} else if (definers.size() < 2) {
wrong.add(action + " is defined only by " + definers + ", so it needs no owner");
}
});
List<String> stale = new ArrayList<>(knownGaps());
stale.removeAll(live);
assertTrue(stale.isEmpty(),
"These are listed as known routing gaps but route correctly now, so the lines "
+ "should come out of " + KNOWN_GAPS + ": " + stale);
assertTrue(wrong.isEmpty(), "AwsQueryController.UNVERSIONED_OWNERS: " + wrong);
}
/**
@@ -264,77 +222,6 @@ class AwsQueryActionRoutingParityTest {
+ "Unregistered: " + unregistered);
}
/**
* The headings in the gap file count the rows under them, and a fix that removes rows makes
* them wrong. They are worth keeping, because the scale and the split between the two kinds of
* gap are the first thing a reader wants, so the test keeps them honest instead.
*
* <p>Every heading is checked, not just the total: a per-service fix is exactly the change that
* invalidates its own service heading. The headings must also be present, so deleting one
* cannot make this pass by having nothing left to compare.
*
* <p>The file is walked in order, so a service heading is held to the rows physically below it,
* up to the next heading, rather than to its service's rows wherever they sit. Each row has to
* sit under its own service's heading, and a service gets one heading, so a misplaced row or a
* section split in two fails even when every service's overall count still adds up.
*/
@Test
void theKnownGapHeadingsCountTheRowsBelowThem() throws IOException {
List<String> wrong = new ArrayList<>();
Set<String> headed = new TreeSet<>();
int[] allRows = new int[2];
GapHeading total = null;
GapHeading section = null;
int[] sectionRows = new int[2];
for (String raw : Files.readAllLines(KNOWN_GAPS)) {
String line = raw.strip();
Matcher totalHeading = TOTAL_HEADING.matcher(line);
Matcher serviceHeading = SERVICE_HEADING.matcher(line);
if (totalHeading.matches()) {
if (total != null) {
wrong.add("the total heading appears twice: " + line);
}
total = GapHeading.of("total", totalHeading, 1);
} else if (serviceHeading.matches()) {
if (section != null) {
section.check(sectionRows, wrong);
}
section = GapHeading.of(serviceHeading.group(1), serviceHeading, 2);
sectionRows = new int[2];
if (!headed.add(section.label())) {
wrong.add("the " + section.label() + " heading appears twice, splitting its rows: " + line);
}
} else if (!line.isEmpty() && !line.startsWith("#")) {
String[] columns = line.split("\t");
int column = "sqs".equals(columns[2]) ? 0 : 1;
allRows[column]++;
if (section == null) {
wrong.add(line + " comes before any service heading");
} else {
sectionRows[column]++;
if (!section.label().equals(columns[0])) {
wrong.add(line + " sits under the " + section.label() + " heading, not its own");
}
}
}
}
if (section != null) {
section.check(sectionRows, wrong);
}
if (total == null) {
wrong.add("the total heading is missing, so nothing states the overall count");
} else {
total.check(allRows, wrong);
}
assertTrue(wrong.isEmpty(),
"A heading in " + KNOWN_GAPS + " no longer counts the rows under it, or a row is not "
+ "under its own service's heading. Removing a gap means updating the heading "
+ "that counted it, including the total. " + wrong);
}
/**
* Where an unsigned request for the action goes, carrying the handler's own {@code Version} the
* way every Query client sends it.
@@ -363,23 +250,6 @@ class AwsQueryActionRoutingParityTest {
return dispatched;
}
/** One line of the known-gap file: the service, the action, and what it reaches instead. */
private static String gapKey(String service, String action, String reached) {
return service + "\t" + action + "\t" + reached;
}
private static Set<String> knownGaps() throws IOException {
Set<String> gaps = new LinkedHashSet<>();
for (String line : Files.readAllLines(KNOWN_GAPS)) {
String trimmed = line.strip();
if (trimmed.isEmpty() || trimmed.startsWith("#")) {
continue;
}
gaps.add(trimmed);
}
return gaps;
}
/**
* The action names a handler dispatches, read from its own dispatch switch and nothing else.
*