feat(iam): check API Gateway's routes by botocore's models (#8060)

API Gateway was the one REST service besides S3 that the registry
authorized by hand: seven rules gave every management route its HTTP
method's action, apigateway:GET, apigateway:POST and so on, with two
named exceptions written in. Its routes were vendored for the coverage
test only.

The developer guide gives the management API's actions as the HTTP
verbs, and the Service Reference lists most API Gateway operations the
action of their route's method beside permissions AWS checks only when
the request carries what they guard, such as UpdateRestApiPolicy for a
resource policy or iam:PassRole for a role. The authorized-actions
table now lists those operations, 55 of them, under authorizedByMethod,
and a request on such an operation's route is checked as the action its
own method names: TagResource is a PUT in v1 and a POST in v2. The
other 132 are the single-action renames the table already held,
RejectDomainNameAccessAssociation and PutRoutingRule among them, or
keep the action of their own name, as the portal, portal product and
routing rule operations do.

So the rules go and API Gateway leaves the hand-routed scopes. Every
route Floci serves is checked as before. Its v1 tag routes are the
shared tags controller's, so they take an ARN sent unencoded and keep
the bare /tags forms, whose tagging form is a POST although v1 tags
with a PUT. v2's tag routes take an unencoded ARN too, as its
controller does.

The routes Floci does not serve, those of portals, portal products and
routing rules, are now checked as the actions AWS names for them rather
than as their method. A path no route of either model has, such as a
deployed API's execute path signed for apigateway, is no longer checked
as a management action: AWS authorizes an invocation as
execute-api:Invoke, which the execute path checks itself.

Regenerating the authorized-actions table also brings in two Lake
Formation operations AWS has added since,
GetGlueFunctionSessionContext and GetTemporaryGlueFunctionCredentials,
both authorized as lakeformation:GetDataAccess. Floci serves neither.

The passed-role generator imports the authorized-actions one, so the
online IAM gate checks the passed-role table for this change too, and
the table no longer held: AWS now passes EMR StartSession's role to
managed-compute.elasticmapreduce alone. Syncing it had failed since AWS
listed iam:PassRole for three more operations the generator found no
role member on, and asks a reason for.

CloudWatch Logs StartQuery names no role at any depth, in the pinned
botocore or the newest, so it is not read for that reason. SSM
RegisterDefaultHostManagementConfiguration and Kinesis Analytics
ImportSnapshot are newer than the pinned botocore, so their requests
cannot be read yet. They get a reason the sync and the offline gate
both refuse once the pinned models carry the operation, so a bump
cannot leave their roles unread. Floci serves StartQuery and neither of
the others.

That refusal caught two entries the pin had already outgrown. ECS
CreateGateway and UpdateGateway were excused as operations botocore
does not model, from the day the table was generated, and the pin has
had both for a while, each naming the infrastructureRoleArn of "the IAM
role that the gateway assumes to create and manage infrastructure on
your behalf". The reference passes it to ecs.amazonaws.com, so the
table reads it for both now. StartSession's role goes where the
reference sends it, and the hand mapping that picked elasticmapreduce
out of its two services is gone. Floci serves neither ECS gateway
operation nor StartSession.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-12 16:07:36 -04:00
1 parent ab794d914c
commit 81894c545d
18 files changed
+708 -122

No files matched your search

@@ -290,19 +290,6 @@ public class IamActionRegistry {
rule("rds-data", "POST", "^/CommitTransaction/?$", "rds-data:CommitTransaction"),
rule("rds-data", "POST", "^/RollbackTransaction/?$", "rds-data:RollbackTransaction"),
// ── API Gateway ────────────────────────────────────────────────────────
// The management API, v1 and v2, is authorized by HTTP method on the resource path:
// apigateway:GET, POST, PUT, PATCH or DELETE. Two operations have an action of their own. The
// others AWS authorizes only by an action of their own name, the v2 routing rules, portals and
// portal products, are not served by Floci and need their own rules when they are.
rule("apigateway", "POST", "^/rejectdomainnameaccessassociations$", "apigateway:RejectAccessAssociation"),
rule("apigateway", "PUT", "^/v2/domainnames/[^/]+/routingrules/[^/]+$", "apigateway:UpdateRoutingRule"),
rule("apigateway", "GET", ".*", "apigateway:GET"),
rule("apigateway", "POST", ".*", "apigateway:POST"),
rule("apigateway", "PUT", ".*", "apigateway:PUT"),
rule("apigateway", "PATCH", ".*", "apigateway:PATCH"),
rule("apigateway", "DELETE", ".*", "apigateway:DELETE"),
// ── EventBridge Scheduler ──────────────────────────────────────────────
rule("scheduler", "GET", "^/schedules/[^/]+$", "scheduler:GetSchedule"),
rule("scheduler", "POST", "^/schedules/[^/]+$", "scheduler:CreateSchedule"),
@@ -694,13 +681,15 @@ public class IamActionRegistry {
* from the request URI because RESTEasy Reactive does not serve {@code UriInfo.getPath(false)}.
*
* <p>A request no rule matches is the operation whose route, in botocore's model of its service, it
* matches, and is checked as that operation's action ({@link IamAuthorizedActions#actionFor}), as a
* request naming its operation is, when Floci can check it as AWS does ({@code checkedAsAws}). One it
* cannot is left unmapped rather than checked on {@code *}, which would refuse a grant scoped to the
* matches, and is checked as that operation's action for the request's method
* ({@link IamAuthorizedActions#actionFor(String, String, String)}): the one a request naming the operation
* is checked as, or, for an operation AWS authorizes by method as it does API Gateway's management API,
* {@code apigateway:PUT} for a PUT. That is when Floci can check it as AWS does ({@code checkedAsAws}). One
* it cannot is left unmapped rather than checked on {@code *}, which would refuse a grant scoped to the
* resource AWS checks it on. A request a route filter moved under an internal prefix is matched on its
* path without the prefix ({@link #withoutInternalPrefix}), the path the model gives it. The scopes the
* vendored routes list as hand-routed, S3's and API Gateway's, have their rules alone. Returns
* {@code null} when nothing maps the request (caller treats this as ALLOW).
* path without the prefix ({@link #withoutInternalPrefix}), the path the model gives it. S3, the scope the
* vendored routes list as hand-routed, has its rules alone. Returns {@code null} when nothing maps the
* request (caller treats this as ALLOW).
*/
public String resolveRoute(String credentialScope, ContainerRequestContext ctx) {
String method = ctx.getMethod().toUpperCase();
@@ -736,7 +725,7 @@ public class IamActionRegistry {
Optional<String> operation = restRoutes.operation(credentialScope, method, withoutInternalPrefix(ctx, path),
ctx.getUriInfo() == null ? null : ctx.getUriInfo().getQueryParameters(), movedUnderPrefix(ctx));
if (operation.isPresent()) {
String action = IamAuthorizedActions.actionFor(credentialScope, operation.get());
String action = IamAuthorizedActions.actionFor(credentialScope, operation.get(), method);
if (checkedAsAws(credentialScope, operation.get(), action)) {
return action;
}
@@ -38,7 +38,10 @@ import java.util.Set;
*
* <p>The file also lists, for each credential scope whose REST routes {@code aws/rest-routes.json} reads, the
* actions the Service Reference gives no resource type ({@link #actsOnNoResourceType}): AWS authorizes them on
* {@code *}, which is what Floci checks a REST request on until it reads the resources in its path.
* {@code *}, which is what Floci checks a REST request on until it reads the resources in its path. And it lists
* the operations of those scopes a request on whose route is checked as the action its HTTP method names
* ({@link #actionFor(String, String, String)}): API Gateway's management API is authorized as
* {@code apigateway:GET}, {@code apigateway:POST} and so on, and {@code TagResource} is a PUT in v1 and a POST in v2.
*
* <p>A missing or malformed resource is a build defect, not a runtime condition, so loading fails
* with {@link IllegalStateException} rather than degrading to an empty map, which would silently put
@@ -63,10 +66,11 @@ public final class IamAuthorizedActions {
private static final ObjectMapper MAPPER = new ObjectMapper();
/**
* The file: the action of each operation it names, keyed by {@code <namespace>:<Operation>}, and the actions of
* no resource type, as {@code <namespace>:<Action>} in lower case.
* The file: the action of each operation it names, keyed by {@code <namespace>:<Operation>}, the actions of
* no resource type, as {@code <namespace>:<Action>} in lower case, and the operations authorized by method, as
* {@code <namespace>:<Operation>}.
*/
record Table(Map<String, String> actions, Set<String> withoutResourceTypes) {
record Table(Map<String, String> actions, Set<String> withoutResourceTypes, Set<String> byMethod) {
}
private static final class Holder {
@@ -89,6 +93,17 @@ public final class IamAuthorizedActions {
return Holder.TABLE.actions().getOrDefault(own, own);
}
/**
* The action AWS checks for a request of {@code method} on a route of {@code operation} under {@code namespace}:
* the one that method names, {@code <namespace>:<METHOD>}, for an operation the file lists as authorized by
* method, or else {@link #actionFor(String, String)}'s.
*/
public static String actionFor(String namespace, String operation, String method) {
return Holder.TABLE.byMethod().contains(namespace + ":" + operation)
? namespace + ":" + method.toUpperCase(Locale.ROOT)
: actionFor(namespace, operation);
}
/**
* Whether AWS authorizes {@code action}, as {@code <namespace>:<Action>}, on no resource type: one the file lists
* for a credential scope whose REST routes are read, matched without regard to case, as IAM matches action
@@ -122,7 +137,30 @@ public final class IamAuthorizedActions {
actions.put(namespace.getKey() + ":" + operation.getKey(), action);
});
});
return new Table(Map.copyOf(actions), withoutResourceTypes(document.path("actionsWithoutResourceTypes")));
return new Table(Map.copyOf(actions), withoutResourceTypes(document.path("actionsWithoutResourceTypes")),
byMethod(document.path("authorizedByMethod")));
}
/** The operations authorized by method, each scope's a list of operation names. */
private static Set<String> byMethod(JsonNode scopes) {
if (!scopes.isObject()) {
throw new IllegalStateException(RESOURCE_NAME + " carries no authorizedByMethod");
}
Set<String> operations = new HashSet<>();
scopes.properties().forEach(scope -> {
if (!scope.getValue().isArray()) {
throw new IllegalStateException(RESOURCE_NAME + " has authorizedByMethod."
+ scope.getKey() + " as something other than a list");
}
scope.getValue().forEach(operation -> {
if (!operation.isTextual() || operation.textValue().isBlank()) {
throw new IllegalStateException(RESOURCE_NAME + " lists " + operation + " among "
+ scope.getKey() + "'s operations authorized by method");
}
operations.add(scope.getKey() + ":" + operation.textValue());
});
});
return Set.copyOf(operations);
}
/** The actions of no resource type, each scope's a list of action names. */
@@ -40,6 +40,10 @@ import java.util.regex.Pattern;
* route takes them: a path that matches no route with each label taking one segment is matched again with each
* label taking as many as its value spans.
*
* <p>An operation may have alternative routes, the bare paths a shared controller also serves it on, with where
* the request carries the members the path no longer holds, and the alternative's own method when it is not the
* operation's: API Gateway v1 tags with a PUT, and the shared tags controller's bare path tags with a POST.
*
* <p>The file is generated by {@code tools/aws/regen_rest_routes.py}, which fails when one route names two
* operations of a credential scope read here. The scopes it lists as {@code handRouted} are not read: the
* registry's rules authorize them alone. A missing or malformed resource is a build defect, so loading fails with
@@ -230,8 +234,9 @@ final class IamRestRoutes {
}
alternatives.forEach(alternative -> {
String uri = alternative.path("requestUri").asText("");
String alternativeMethod = alternative.has("method") ? alternative.get("method").asText("") : method;
JsonNode members = alternative.path("located");
if (!uri.startsWith("/") || !members.isObject()) {
if (!uri.startsWith("/") || !members.isObject() || !METHODS.contains(alternativeMethod)) {
throw new IllegalStateException(RESOURCE_NAME + " gives " + operation.getKey()
+ " an invalid alternative route");
}
@@ -245,7 +250,8 @@ final class IamRestRoutes {
}
located.put(member.getKey(), source);
});
routes.get(scope).get(method).add(route(operation.getKey(), uri, Map.copyOf(located)));
routes.get(scope).computeIfAbsent(alternativeMethod, ignored -> new ArrayList<>())
.add(route(operation.getKey(), uri, Map.copyOf(located)));
});
});
});