fix(glue): check the Iceberg REST endpoint's routes under IAM enforcement (#8548)

No botocore model describes AWS Glue's Iceberg REST endpoint, so no
vendored route mapped its paths to an action, and the endpoint refused
every IAM principal under enforcement, letting only root credentials
and Floci's own query engine through.

- regen_rest_routes.py reads an endpoint botocore does not model from
  the AWS page documenting it (DOCUMENTED): Glue's "REST APIs for Apache
  Iceberg specifications" gives each operation's REST path, IAM action,
  CloudTrail event and a link to its definition in the Apache Iceberg
  REST catalog OpenAPI specification. Each row of the Iceberg REST
  Catalog API is the Glue operation its IAM action and CloudTrail event
  name, refused when they differ, on the method and path of the
  definition it links, under the root and the catalogs/{catalog} prefix
  the page's path gives. Rows of one operation are its route and its
  alternatives. Where the page's own path differs from the definition
  (DeleteNamespace's "namespces", CreateTable's GET), the definition is
  taken and the difference recorded. Nothing is typed by hand.
- Reading the page needs the network, so a regeneration carries the
  routes over from the vendored file, --fetch-documented reads them
  again, and --verify checks them against the page;
  documented-routes-verify runs in iam-data-verify.
- rest-routes.json gains the endpoint's ten Glue operations under the
  glue scope, and iam-authorized-actions.json lists glue's actions of
  no resource type, as it does for every routed scope. The same
  regeneration takes the actions AWS has added since: GuardDuty's
  ListInvestigationRecords and Route 53's IP guardrail policy actions.
- The controller's refusal of IAM principals goes. Each route is now
  checked as its Glue operation, on the account's Data Catalog whichever
  catalog the prefix names: the request-resource table reads no Glue
  member from an Iceberg request, so a grant or deny scoped to a
  federated catalog, a database or a table does not apply here.
  Floci's own engine's token is not checked again.
- A request a documented route takes is another API's, so it carries
  none of its operation's members: the enforcement filter has every
  member reader (request resources, condition keys, tag-on-create,
  passed roles) read none from it, so a Glue member a caller adds to an
  Iceberg body, such as Tags or DatabaseInput, names no resource and
  gives no condition key a value.

GlueIcebergIamIntegrationTest checks a principal allowed GetCatalog and
GetDatabase reading the configuration and the namespaces and refused
creating a namespace or loading a table, by GET or HEAD, a deny on the
catalog holding under an allow on everything, and root credentials and
a minted token answered, and a Glue member added to an Iceberg body
neither satisfying an aws:RequestTag condition nor naming a database.
glue.md and iam.md say so.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-16 00:45:42 -04:00
1 parent 9392bd54af
commit 0b6077d374
15 files changed
+754 -138

No files matched your search

@@ -2,6 +2,7 @@ package io.floci.aws.core.common;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsCrossAccountService;
@@ -80,6 +81,8 @@ public class IamConditionContextResolver {
/** Set by {@code ResourceArnBuilder.readJsonBody}, which runs earlier in the same filter pass. */
static final String BUFFERED_JSON_BODY = "floci.bufferedJsonBody";
private static final String BUFFERED_FORM_BODY = "floci.bufferedFormBody";
/** Set on a request that carries none of its operation's members, see {@link #readNoMembers}. */
private static final String NO_MEMBERS = "floci.noRequestMembers";
/** Prefixes the action whose numbered EC2 targets {@link #heldTargets} looked up for the request. */
private static final String HELD_TARGETS = "floci.heldTargets.";
private static final String REQUEST_TAG_PREFIX = "aws:RequestTag/";
@@ -1195,6 +1198,21 @@ public class IamConditionContextResolver {
// ── Request body access ─────────────────────────────────────────────────────
/**
* Has every reader of the request's members read none from it: its JSON body reads as one naming nothing, and its
* form, its raw body and a Query request's parameters as absent. A request a route AWS documents outside botocore
* takes is another API's, so a member its body gives was added by the caller, naming a resource or giving a
* condition key a value its handler never acts on.
*/
static void readNoMembers(ContainerRequestContext ctx) {
ctx.setProperty(NO_MEMBERS, Boolean.TRUE);
ctx.setProperty(BUFFERED_JSON_BODY, JsonNodeFactory.instance.objectNode());
}
private static boolean carriesNoMembers(ContainerRequestContext ctx) {
return Boolean.TRUE.equals(ctx.getProperty(NO_MEMBERS));
}
/**
* The decoded form parameters of a Query-protocol request, buffered once per request and
* restored for the controller that reads the form next. A repeated key keeps its first
@@ -1203,6 +1221,9 @@ public class IamConditionContextResolver {
*/
@SuppressWarnings("unchecked")
static Map<String, String> formParameters(ContainerRequestContext ctx) {
if (carriesNoMembers(ctx)) {
return Map.of();
}
if ("GET".equalsIgnoreCase(ctx.getMethod()) && IamActionRegistry.isQueryRequest(ctx)) {
Map<String, String> parameters = new LinkedHashMap<>();
ctx.getUriInfo().getQueryParameters().forEach((key, values) -> {
@@ -1242,8 +1263,14 @@ public class IamConditionContextResolver {
return parameters;
}
/** Reads the entity fully and puts an equivalent stream back for downstream readers. */
/**
* Reads the entity fully and puts an equivalent stream back for downstream readers; none for a request that
* carries no members, whose entity is left to its handler.
*/
static byte[] bufferEntity(ContainerRequestContext ctx) {
if (carriesNoMembers(ctx)) {
return null;
}
InputStream in = ctx.getEntityStream();
if (in == null) {
return null;
@@ -399,6 +399,11 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
ResolvedAuthorization resolvedAuthorization = resolveAuthorization(auth, claimedScope, ctx);
String credentialScope = resolvedAuthorization.credentialScope();
String action = resolvedAuthorization.action();
if (IamActionRegistry.takenByDocumentedRoute(credentialScope, ctx)) {
// Another API's request (Glue's Iceberg REST endpoint takes Apache Iceberg's) carries none of the
// operation's members, so none is read from it: not its resources, condition keys, tags or roles.
IamConditionContextResolver.readNoMembers(ctx);
}
if (action == null) {
if (!"OPTIONS".equalsIgnoreCase(ctx.getMethod())
&& iamService.presignedScope(akid).isPresent()) {
@@ -2,8 +2,6 @@ package io.floci.aws.services.glue.iceberg;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.RequestContext;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
@@ -23,11 +21,10 @@ import jakarta.ws.rs.core.Response;
* Apache Iceberg REST catalog specification AWS lists for it, under the {@code /v1/catalogs/{catalog}} prefix.
* {@link GlueIcebergRouteFilter} moves requests signed for Glue onto {@link GlueIcebergRouteFilter#INTERNAL_PREFIX}.
*
* <p>Under IAM enforcement, no rule maps these routes to the Glue actions AWS checks for them yet, and an unmapped REST
* route is allowed, so an IAM principal is refused here rather than let through unchecked: only the account's root
* credentials, and a bearer token Floci minted for its own query engine, reach the catalog then. The check sits at
* this entry point, not in {@link GlueIcebergCatalog}, because Floci's Athena calls the catalog directly for a caller
* IAM already checked.
* <p>Under IAM enforcement each route is checked as the Glue operation AWS's Glue Developer Guide documents it as, its
* IAM action and CloudTrail event, from the routes vendored in {@code aws/rest-routes.json}, before it reaches this
* controller. A bearer token Floci minted for its own query engine is not checked again: Floci's Athena hands it to
* the engine for a caller IAM already checked.
*/
@Path(GlueIcebergRouteFilter.INTERNAL_PREFIX + GlueIcebergRouteFilter.ICEBERG_PATH + "/v1")
@ApplicationScoped
@@ -36,80 +33,76 @@ import jakarta.ws.rs.core.Response;
public class GlueIcebergController {
private final GlueIcebergCatalog catalog;
private final EmulatorConfig config;
private final RequestContext requestContext;
@Inject
public GlueIcebergController(GlueIcebergCatalog catalog, EmulatorConfig config, RequestContext requestContext) {
public GlueIcebergController(GlueIcebergCatalog catalog) {
this.catalog = catalog;
this.config = config;
this.requestContext = requestContext;
}
@GET
@Path("/config")
public ObjectNode getConfig(@QueryParam("warehouse") String warehouse) {
return catalog().config(warehouse);
return catalog.config(warehouse);
}
@GET
@Path("/catalogs/{catalog}/namespaces")
public ObjectNode listNamespaces(@PathParam("catalog") String catalogId, @QueryParam("parent") String parent) {
return catalog().listNamespaces(catalogId, parent);
return catalog.listNamespaces(catalogId, parent);
}
@POST
@Path("/catalogs/{catalog}/namespaces")
public ObjectNode createNamespace(@PathParam("catalog") String catalogId, JsonNode request) {
return catalog().createNamespace(catalogId, request);
return catalog.createNamespace(catalogId, request);
}
@GET
@Path("/catalogs/{catalog}/namespaces/{namespace}")
public ObjectNode loadNamespaceMetadata(@PathParam("catalog") String catalogId,
@PathParam("namespace") String namespace) {
return catalog().loadNamespace(catalogId, namespace);
return catalog.loadNamespace(catalogId, namespace);
}
@POST
@Path("/catalogs/{catalog}/namespaces/{namespace}/properties")
public ObjectNode updateNamespaceProperties(@PathParam("catalog") String catalogId,
@PathParam("namespace") String namespace, JsonNode request) {
return catalog().updateNamespaceProperties(catalogId, namespace, request);
return catalog.updateNamespaceProperties(catalogId, namespace, request);
}
@DELETE
@Path("/catalogs/{catalog}/namespaces/{namespace}")
public Response dropNamespace(@PathParam("catalog") String catalogId, @PathParam("namespace") String namespace) {
catalog().dropNamespace(catalogId, namespace);
catalog.dropNamespace(catalogId, namespace);
return Response.noContent().build();
}
@GET
@Path("/catalogs/{catalog}/namespaces/{namespace}/tables")
public ObjectNode listTables(@PathParam("catalog") String catalogId, @PathParam("namespace") String namespace) {
return catalog().listTables(catalogId, namespace);
return catalog.listTables(catalogId, namespace);
}
@POST
@Path("/catalogs/{catalog}/namespaces/{namespace}/tables")
public ObjectNode createTable(@PathParam("catalog") String catalogId, @PathParam("namespace") String namespace,
JsonNode request) {
return catalog().createTable(catalogId, namespace, request);
return catalog.createTable(catalogId, namespace, request);
}
@GET
@Path("/catalogs/{catalog}/namespaces/{namespace}/tables/{table}")
public ObjectNode loadTable(@PathParam("catalog") String catalogId, @PathParam("namespace") String namespace,
@PathParam("table") String table, @QueryParam("snapshots") String snapshots) {
return catalog().loadTable(catalogId, namespace, table, snapshots);
return catalog.loadTable(catalogId, namespace, table, snapshots);
}
@HEAD
@Path("/catalogs/{catalog}/namespaces/{namespace}/tables/{table}")
public Response tableExists(@PathParam("catalog") String catalogId, @PathParam("namespace") String namespace,
@PathParam("table") String table) {
catalog().tableExists(catalogId, namespace, table);
catalog.tableExists(catalogId, namespace, table);
return Response.noContent().build();
}
@@ -117,28 +110,14 @@ public class GlueIcebergController {
@Path("/catalogs/{catalog}/namespaces/{namespace}/tables/{table}")
public ObjectNode updateTable(@PathParam("catalog") String catalogId, @PathParam("namespace") String namespace,
@PathParam("table") String table, JsonNode request) {
return catalog().commitTable(catalogId, namespace, table, request);
return catalog.commitTable(catalogId, namespace, table, request);
}
@DELETE
@Path("/catalogs/{catalog}/namespaces/{namespace}/tables/{table}")
public Response dropTable(@PathParam("catalog") String catalogId, @PathParam("namespace") String namespace,
@PathParam("table") String table) {
catalog().dropTable(catalogId, namespace, table);
catalog.dropTable(catalogId, namespace, table);
return Response.noContent().build();
}
/** The catalog, once the caller is one this endpoint can answer under IAM enforcement. */
private GlueIcebergCatalog catalog() {
if (config.services().iam().enforcementEnabled()) {
String accessKeyId = requestContext.getAccessKeyId();
if (accessKeyId != null && !"test".equals(accessKeyId)
&& !accessKeyId.equals(requestContext.getAccountId())) {
throw new IcebergRestException(403, "ForbiddenException",
"AWS Glue's Iceberg REST endpoint does not check IAM policies in Floci yet, so under IAM "
+ "enforcement it answers only the account's root credentials");
}
}
return catalog;
}
}
@@ -738,9 +738,28 @@ public class IamActionRegistry {
if (credentialScope == null || !routes.routes(credentialScope)) {
return Map.of();
}
return matchedRoute(routes, credentialScope, ctx).map(IamRestRoutes.Match::labels).orElse(Map.of());
}
/**
* Whether a request of the credential scope is taken by a route of a model AWS documents on a page of its own
* rather than in botocore, as Glue's Iceberg REST endpoint is: such a request is another API's, Apache Iceberg's
* REST catalog, so it carries none of its operation's members, and one its body gives was added by the caller.
*/
public static boolean takenByDocumentedRoute(String credentialScope, ContainerRequestContext ctx) {
IamRestRoutes routes = IamRestRoutes.vendored();
return credentialScope != null && routes.documents(credentialScope)
&& matchedRoute(routes, credentialScope, ctx).map(IamRestRoutes.Match::documented).orElse(false);
}
/**
* The vendored route of the credential scope a request's method, path and query match, as {@link #resolveRoute}
* matches it.
*/
private static Optional<IamRestRoutes.Match> matchedRoute(IamRestRoutes routes, String credentialScope,
ContainerRequestContext ctx) {
return routes.match(credentialScope, ctx.getMethod().toUpperCase(), withoutInternalPrefix(ctx, routedPath(ctx)),
ctx.getUriInfo() == null ? null : ctx.getUriInfo().getQueryParameters(), movedUnderPrefix(ctx))
.map(IamRestRoutes.Match::labels).orElse(Map.of());
ctx.getUriInfo() == null ? null : ctx.getUriInfo().getQueryParameters(), movedUnderPrefix(ctx));
}
/**
@@ -12,6 +12,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -44,6 +45,11 @@ import java.util.regex.Pattern;
* 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>A model AWS documents on a page of its own rather than in botocore (its {@code documented} block, Glue's Iceberg
* REST endpoint) routes another API's requests: Apache Iceberg's REST catalog, whose bodies carry none of the Glue
* operation's members. A request one of its routes takes is {@link Match#documented}, so nothing reads a member from
* it.
*
* <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
@@ -64,16 +70,19 @@ final class IamRestRoutes {
private static final int ONE_SEGMENT = 1;
private static final int REST_OF_PATH = 0;
/** A matched operation, decoded path labels, and generated alternative member locations. */
record Match(String operation, Map<String, String> labels, Map<String, String> located) {
/**
* A matched operation, decoded path labels, generated alternative member locations, and whether the route is a
* documented model's, whose request carries none of the operation's members.
*/
record Match(String operation, Map<String, String> labels, Map<String, String> located, boolean documented) {
}
/**
* A route: its operation, its path as a pattern capturing each label in turn, the labels' names, each segment's
* rank, and the query it names.
* rank, the query it names, the members its alternative locates, and whether its model is a documented one.
*/
private record Route(String operation, Pattern path, Pattern spanning, List<String> labels, int[] ranks,
Map<String, String> query, Map<String, String> located) {
Map<String, String> query, Map<String, String> located, boolean documented) {
/** The route's pattern: each label taking one segment, or, spanning, the segments its value spans. */
Pattern pattern(boolean spanned) {
@@ -122,10 +131,14 @@ final class IamRestRoutes {
/** Each credential scope's routes, by method. */
private final Map<String, Map<String, List<Route>>> routes;
private final Map<String, Integer> accessDeniedStatuses;
/** The credential scopes a documented model routes. */
private final Set<String> documentedScopes;
private IamRestRoutes(Map<String, Map<String, List<Route>>> routes, Map<String, Integer> accessDeniedStatuses) {
private IamRestRoutes(Map<String, Map<String, List<Route>>> routes, Map<String, Integer> accessDeniedStatuses,
Set<String> documentedScopes) {
this.routes = routes;
this.accessDeniedStatuses = accessDeniedStatuses;
this.documentedScopes = documentedScopes;
}
/** The vendored routes. */
@@ -172,7 +185,8 @@ final class IamRestRoutes {
}
}
return best == null ? Optional.empty()
: Optional.of(new Match(best.operation(), best.labelValues(requestPath, spanned), best.located()));
: Optional.of(new Match(best.operation(), best.labelValues(requestPath, spanned), best.located(),
best.documented()));
}
/** The modelled denial status, or the existing protocol default when the model declares none. */
@@ -185,6 +199,11 @@ final class IamRestRoutes {
return routes.containsKey(scope);
}
/** Whether a documented model routes requests of the credential scope. */
boolean documents(String scope) {
return documentedScopes.contains(scope);
}
/**
* Whether a route of the credential scope, of any method, takes the path and query: the path is one of its
* model's, whatever method a request sends to it.
@@ -204,6 +223,7 @@ final class IamRestRoutes {
Set<String> skipped = Set.copyOf(handRouted.propertyStream().map(Map.Entry::getKey).toList());
Map<String, Map<String, List<Route>>> routes = new HashMap<>();
Map<String, Integer> denialStatuses = new HashMap<>();
Set<String> documentedScopes = new HashSet<>();
models.properties().forEach(model -> {
String scope = model.getValue().path("credentialScope").asText("");
JsonNode operations = model.getValue().path("operations");
@@ -226,6 +246,15 @@ final class IamRestRoutes {
if (skipped.contains(scope)) {
return;
}
JsonNode documentation = model.getValue().path("documented");
if (!documentation.isMissingNode() && !documentation.isObject()) {
throw new IllegalStateException(RESOURCE_NAME + " gives model " + model.getKey()
+ " an invalid documented block");
}
boolean documented = documentation.isObject();
if (documented) {
documentedScopes.add(scope);
}
operations.properties().forEach(operation -> {
String method = operation.getValue().path("method").asText("");
String requestUri = operation.getValue().path("requestUri").asText("");
@@ -235,7 +264,7 @@ final class IamRestRoutes {
}
routes.computeIfAbsent(scope, ignored -> new HashMap<>())
.computeIfAbsent(method, ignored -> new ArrayList<>())
.add(route(operation.getKey(), requestUri, Map.of()));
.add(route(operation.getKey(), requestUri, Map.of(), documented));
JsonNode alternatives = operation.getValue().path("alternatives");
if (!alternatives.isMissingNode() && !alternatives.isArray()) {
throw new IllegalStateException(RESOURCE_NAME + " gives " + operation.getKey()
@@ -260,7 +289,7 @@ final class IamRestRoutes {
located.put(member.getKey(), source);
});
routes.get(scope).computeIfAbsent(alternativeMethod, ignored -> new ArrayList<>())
.add(route(operation.getKey(), uri, Map.copyOf(located)));
.add(route(operation.getKey(), uri, Map.copyOf(located), documented));
});
});
});
@@ -270,11 +299,11 @@ final class IamRestRoutes {
byMethod.forEach((method, list) -> methods.put(method, List.copyOf(list)));
copied.put(scope, Map.copyOf(methods));
});
return new IamRestRoutes(Map.copyOf(copied), Map.copyOf(denialStatuses));
return new IamRestRoutes(Map.copyOf(copied), Map.copyOf(denialStatuses), Set.copyOf(documentedScopes));
}
/** A route of the operation from its request URI, its path's segments and the query after its {@code ?}. */
private static Route route(String operation, String requestUri, Map<String, String> located) {
private static Route route(String operation, String requestUri, Map<String, String> located, boolean documented) {
int question = requestUri.indexOf('?');
String path = IamActionRegistry.withoutTrailingSlash(question < 0 ? requestUri : requestUri.substring(0, question));
List<String> segments = path.equals("/") ? List.of() : List.of(path.substring(1).split("/", -1));
@@ -317,6 +346,6 @@ final class IamRestRoutes {
}
return new Route(operation, Pattern.compile(pattern.isEmpty() ? "/" : pattern.toString()),
Pattern.compile(spanning.isEmpty() ? "/" : spanning.toString()), List.copyOf(labels), ranks,
Map.copyOf(query), located);
Map.copyOf(query), located, documented);
}
}