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

@@ -1,58 +0,0 @@
package io.floci.aws.services.glue.iceberg;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.RequestContext;
import io.floci.aws.services.glue.GlueService;
import io.floci.aws.services.s3.S3Service;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
/** Who the endpoint answers under IAM enforcement. */
class GlueIcebergControllerTest {
private EmulatorConfig config;
private RequestContext requestContext;
private GlueIcebergController controller;
@BeforeEach
void setUp() {
config = Mockito.mock(EmulatorConfig.class, Answers.RETURNS_DEEP_STUBS);
requestContext = Mockito.mock(RequestContext.class);
GlueIcebergCatalog catalog = new GlueIcebergCatalog(Mockito.mock(GlueService.class),
Mockito.mock(S3Service.class), new RegionResolver("us-east-1", "000000000000"), new ObjectMapper(),
null, null);
controller = new GlueIcebergController(catalog, config, requestContext);
}
@Test
void underIamEnforcementOnlyRootCredentialsAndFlocisOwnCallersReachTheCatalog() {
when(config.services().iam().enforcementEnabled()).thenReturn(true);
when(requestContext.getAccountId()).thenReturn("000000000000");
when(requestContext.getAccessKeyId()).thenReturn("AKIAEXAMPLEUSER0001");
IcebergRestException refused = assertThrows(IcebergRestException.class, () -> controller.getConfig(null));
assertEquals(403, refused.code());
assertEquals("ForbiddenException", refused.type());
for (String rootOrInternal : new String[] {"test", "000000000000", null}) {
when(requestContext.getAccessKeyId()).thenReturn(rootOrInternal);
assertEquals("catalogs/:", controller.getConfig(null).path("overrides").path("prefix").asText());
}
}
@Test
void withoutEnforcementAnyCallerReachesTheCatalog() {
when(config.services().iam().enforcementEnabled()).thenReturn(false);
when(requestContext.getAccessKeyId()).thenReturn("AKIAEXAMPLEUSER0001");
assertEquals("catalogs/:", controller.getConfig(null).path("overrides").path("prefix").asText());
}
}
@@ -7,22 +7,25 @@ import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
/**
* Under IAM enforcement, no rule maps the Glue Iceberg REST endpoint's routes to the Glue actions AWS checks for them
* yet, so the endpoint refuses an IAM principal, even one allowed every Glue action, rather than let it through
* unchecked; the account's root credentials still reach it, and so does a token Floci minted for its query engine,
* as the account and Region it was minted for.
* Under IAM enforcement, each route of the Glue Iceberg REST endpoint is checked as the Glue operation AWS's Glue
* Developer Guide documents it as, on the account's Data Catalog, the one resource the request-resource table reads
* for a request that carries no Glue member, as an Iceberg request does not; a token Floci minted for its query engine
* is answered as the account and Region it was minted for.
*/
@QuarkusTest
@TestProfile(SignedIamEnforcementProfile.class)
@@ -35,16 +38,53 @@ class GlueIcebergIamIntegrationTest {
GlueIcebergTokens tokens;
@Test
void anIamPrincipalIsRefusedAndRootCredentialsAreAnswered() throws Exception {
String allowEverything = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Action\":\"glue:*\",\"Resource\":\"*\"}]}";
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "glue-iceberg-", "glue", allowEverything)) {
get(user.signer("glue"), "/iceberg/v1/config").then().statusCode(403)
.body("error.type", equalTo("ForbiddenException"));
get(user.signer("glue"), "/iceberg/v1/catalogs/:/namespaces").then().statusCode(403);
void eachRouteIsCheckedAsTheGlueOperationAwsDocumentsItAs() throws Exception {
String catalog = "arn:aws:glue:us-east-1:000000000000:catalog";
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "glue-iceberg-", "glue",
policy(allow("glue:GetCatalog", catalog) + "," + allow("glue:GetDatabase", catalog)))) {
AwsRequestSigner signer = user.signer("glue");
send(signer, "GET", "/iceberg/v1/config", null).then().statusCode(200)
.body("overrides.prefix", equalTo("catalogs/:"));
send(signer, "GET", "/iceberg/v1/catalogs/:/namespaces", null).then().statusCode(200);
refused(send(signer, "POST", "/iceberg/v1/catalogs/:/namespaces", "{\"namespace\":[\"refused\"]}"),
"glue:CreateDatabase");
// An operation's alternative route of another method is checked as that operation too.
refused(send(signer, "HEAD", "/iceberg/v1/catalogs/:/namespaces/refused/tables/t", null), null);
refused(send(signer, "GET", "/iceberg/v1/catalogs/:/namespaces/refused/tables/t", null), "glue:GetTable");
}
get(AwsRequestSigner.signedAs("test", "test", "glue"), "/iceberg/v1/config").then().statusCode(200)
.body("overrides.prefix", equalTo("catalogs/:"));
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "glue-iceberg-", "glue",
policy(allow("glue:*", "*") + ",{\"Effect\":\"Deny\",\"Action\":\"glue:GetDatabase\","
+ "\"Resource\":\"" + catalog + "\"}"))) {
send(user.signer("glue"), "GET", "/iceberg/v1/config", null).then().statusCode(200);
refused(send(user.signer("glue"), "GET", "/iceberg/v1/catalogs/:/namespaces", null), "glue:GetDatabase");
}
send(AwsRequestSigner.signedAs("test", "test", "glue"), "GET", "/iceberg/v1/config", null).then()
.statusCode(200).body("overrides.prefix", equalTo("catalogs/:"));
}
/**
* A Glue member an Iceberg request's body carries is not read: the request is Apache Iceberg's, so a caller added
* it. It gives no condition key a value, as a tag the namespace never gets would, and names no resource, as a
* database other than the one the request creates would.
*/
@Test
void aGlueMemberAnIcebergBodyCarriesIsNotRead() throws Exception {
String catalog = "arn:aws:glue:us-east-1:000000000000:catalog";
String taggedCreate = "{\"Effect\":\"Allow\",\"Action\":[\"glue:CreateDatabase\",\"glue:TagResource\"],"
+ "\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"data\"}}}";
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "glue-iceberg-", "glue",
policy(allow("glue:GetCatalog", catalog) + "," + taggedCreate))) {
refused(send(user.signer("glue"), "POST", "/iceberg/v1/catalogs/:/namespaces",
"{\"namespace\":[\"tagged\"],\"Tags\":{\"team\":\"data\"}}"), "glue:CreateDatabase");
}
try (SignedIamUsers.User user = SignedIamUsers.createUser(endpoint, "glue-iceberg-", "glue",
policy(allow("glue:*", "*") + ",{\"Effect\":\"Deny\",\"Action\":\"glue:CreateDatabase\","
+ "\"Resource\":\"arn:aws:glue:us-east-1:000000000000:database/decoy\"}"))) {
send(user.signer("glue"), "POST", "/iceberg/v1/catalogs/:/namespaces",
"{\"namespace\":[\"named\"],\"DatabaseInput\":{\"Name\":\"decoy\"}}").then().statusCode(200);
}
send(AwsRequestSigner.signedAs("test", "test", "glue"), "DELETE", "/iceberg/v1/catalogs/:/namespaces/named",
null).then().statusCode(204);
}
@Test
@@ -67,9 +107,30 @@ class GlueIcebergIamIntegrationTest {
.get(endpoint.resolve(path));
}
private Response get(AwsRequestSigner signer, String path) throws Exception {
private Response send(AwsRequestSigner signer, String method, String path, String body) throws Exception {
URI uri = endpoint.resolve(path);
return given().urlEncodingEnabled(false).headers(signer.headersFor("GET", uri, Map.of(), new byte[0]))
.request("GET", uri);
byte[] bytes = body == null ? new byte[0] : body.getBytes(StandardCharsets.UTF_8);
RequestSpecification request = given().urlEncodingEnabled(false)
.headers(signer.headersFor(method, uri, Map.of(), bytes));
if (body != null) {
request = request.contentType("application/json").body(bytes);
}
return request.request(method, uri);
}
/** A refusal of the action, which a HEAD answers with its status alone. */
private static void refused(Response response, String action) {
response.then().statusCode(403);
if (action != null) {
response.then().body(containsString("not authorized to perform: " + action));
}
}
private static String policy(String statements) {
return "{\"Version\":\"2012-10-17\",\"Statement\":[" + statements + "]}";
}
private static String allow(String action, String resource) {
return "{\"Effect\":\"Allow\",\"Action\":\"" + action + "\",\"Resource\":\"" + resource + "\"}";
}
}
@@ -17,8 +17,10 @@ import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class IamRestRoutesTest {
@@ -105,6 +107,29 @@ class IamRestRoutesTest {
private final IamRestRoutes routes = routes(ROUTES);
/**
* A model AWS documents outside botocore routes another API's requests, which carry none of the operation's
* members: each of its routes, Glue's Iceberg REST endpoint's among the vendored ones, says so, and a botocore
* model's does not.
*/
@Test
void aDocumentedModelsRoutesTakeRequestsCarryingNoMembers() {
IamRestRoutes documented = routes(ROUTES.replace("\"svc\": {\"credentialScope\": \"svc\",",
"\"svc\": {\"credentialScope\": \"svc\", \"documented\": {\"page\": \"https://docs.example/svc\"},"));
assertTrue(documented.documents("svc"));
assertTrue(documented.match("svc", "GET", "/things/web", null).orElseThrow().documented());
assertFalse(routes.documents("svc"));
assertFalse(routes.match("svc", "GET", "/things/web", null).orElseThrow().documented());
IamRestRoutes vendored = IamRestRoutes.vendored();
assertTrue(vendored.match("glue", "POST", "/iceberg/v1/catalogs/:/namespaces/db/tables/t", null)
.orElseThrow().documented());
assertFalse(vendored.match("lambda", "GET", "/2015-03-31/functions/fn", null).orElseThrow().documented());
assertThrows(IllegalStateException.class, () -> routes(ROUTES.replace("\"svc\": {\"credentialScope\": \"svc\",",
"\"svc\": {\"credentialScope\": \"svc\", \"documented\": \"a page\",")));
}
@Test
void routeDataIsBundledWithTheApplicationRatherThanOnlyWithTests() throws Exception {
URL application = IamActionRegistry.class.getProtectionDomain().getCodeSource().getLocation();