fix(athena): read and check a request naming no catalog as AwsDataCatalog (#7061)

Athena's GetDataCatalog, ListDatabases, ListTableMetadata and
GetTableMetadata handlers read the catalog name with has() and
asText(), so a JSON null became a catalog named `null`: GetDataCatalog
then answered InvalidRequestException rather than the AwsDataCatalog
it answers for a request naming none. They now read it through the
handler's text(), as GetWorkGroup and StartQueryExecution read
WorkGroup, so a JSON null names no catalog.

Under IAM enforcement, a GetDataCatalog naming no catalog was checked
on `*` though Floci answers AwsDataCatalog, so a grant on that catalog
was refused and a deny on it did not apply, and the three catalog
reads given a JSON null CatalogName were checked on `datacatalog/null`
as well as on AwsDataCatalog. The request-resources table now reads a
request naming none, or a JSON null, as naming AwsDataCatalog for all
four, as it reads Athena's primary workgroup.

The table's regeneration also takes up drift in AWS's Service
Reference since the last sync, which the online check of both IAM
tables fails on: AWS now lists cognito-idp:DescribeTermsByClient among
the actions it authorizes DescribeTermsByClient as, so the
authorized-actions map no longer maps it to DescribeTerms and the
request-resources table checks it as its own action, and the map
gains MediaConnect's new BatchGetDestinationEndpoint and
BatchGetSourceEndpoint. Floci serves none of these operations.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-31 10:27:14 -05:00
1 parent f40d784f66
commit bfd3bcbbce
8 files changed
+69 -21

No files matched your search

+2
View File
@@ -36,6 +36,8 @@ Floci emulates Amazon Athena with **real SQL execution** powered by a [floci-duc
`ListDataCatalogs` accepts `MaxResults` from 2 to 50. Floci uses 50 when it is
omitted, since the API reference does not document a default. The built-in
`AwsDataCatalog` stays first, followed by registered catalogs in name order.
`GetDataCatalog`, `ListDatabases`, `ListTableMetadata` and `GetTableMetadata`
read `AwsDataCatalog` when the request names no catalog or a JSON null.
Pass the opaque `NextToken` to continue; final pages omit it. Tokens are scoped
to the action, caller account, and request region and remain resumable after a
cursor catalog is deleted. Malformed tokens, tokens outside the 1-to-1024
+2 -1
View File
@@ -1636,7 +1636,8 @@ naming no workgroup is checked on `workgroup/primary`, where `StartQueryExecutio
`ListQueryExecutions` and `ListNamedQueries` list, and `GetWorkGroup` answers. Athena's
`ListDatabases`, `ListTableMetadata` and `GetTableMetadata` are checked on the catalog their
`CatalogName` names and on `datacatalog/AwsDataCatalog`, the Glue Data Catalog Floci reads whichever
catalog they name. Cost Explorer's cost and usage reads are checked on `*`, not on the billing view
catalog they name, and a `GetDataCatalog` naming no catalog on `datacatalog/AwsDataCatalog`, the one it
answers. Cost Explorer's cost and usage reads are checked on `*`, not on the billing view
their `BillingViewArn` gives: Floci serves no billing views and answers the account's costs whichever
one is named. Data Exports' `CreateExport` is not checked on the
ARN its `Export.ExportArn` gives, which is the new export's own. CloudTrail's `StartLogging`,
@@ -124,10 +124,8 @@ public class AthenaJsonHandler {
}
yield Response.ok(response).build();
}
case "GetDataCatalog" -> {
String name = request.has("Name") ? request.get("Name").asText() : AthenaService.DEFAULT_CATALOG;
yield Response.ok(Map.of("DataCatalog", athenaService.getDataCatalog(region, name))).build();
}
case "GetDataCatalog" -> Response.ok(
Map.of("DataCatalog", athenaService.getDataCatalog(region, text(request, "Name")))).build();
case "CreateDataCatalog" -> {
Map<String, Object> catalog = athenaService.createDataCatalog(region,
text(request, "Name"),
@@ -156,16 +154,16 @@ public class AthenaJsonHandler {
yield Response.ok(Map.of()).build();
}
case "ListDatabases" -> {
String catalog = request.has("CatalogName") ? request.get("CatalogName").asText() : AthenaService.DEFAULT_CATALOG;
String catalog = catalogName(request);
yield Response.ok(Map.of("DatabaseList", athenaService.listDatabases(catalog))).build();
}
case "ListTableMetadata" -> {
String catalog = request.has("CatalogName") ? request.get("CatalogName").asText() : AthenaService.DEFAULT_CATALOG;
String catalog = catalogName(request);
String database = request.path("DatabaseName").asText(request.path("Database").asText(""));
yield Response.ok(Map.of("TableMetadataList", athenaService.listTableMetadata(catalog, database))).build();
}
case "GetTableMetadata" -> {
String catalog = request.has("CatalogName") ? request.get("CatalogName").asText() : AthenaService.DEFAULT_CATALOG;
String catalog = catalogName(request);
String database = request.path("DatabaseName").asText(request.path("Database").asText(""));
String tableName = request.get("TableName").asText();
yield Response.ok(Map.of("TableMetadata", athenaService.getTableMetadata(catalog, database, tableName))).build();
@@ -194,6 +192,11 @@ public class AthenaJsonHandler {
return node == null || node.isNull() ? null : node.asText();
}
private static String catalogName(JsonNode request) {
String named = text(request, "CatalogName");
return named != null ? named : AthenaService.DEFAULT_CATALOG;
}
private static Map<String, String> parameters(JsonNode request) {
JsonNode node = request.get("Parameters");
if (node == null || !node.isObject()) {
@@ -2,7 +2,7 @@
"_source": {
"generator": "tools/aws/regen_iam_authorized_actions.py",
"reference": "https://servicereference.us-east-1.amazonaws.com/",
"retrieved": "2026-10-24",
"retrieved": "2026-10-31",
"note": "make iam-authorized-actions-verify checks every entry against AWS."
},
"authorizedActions": {
@@ -165,9 +165,6 @@
"ListTables": "cassandra:Select",
"ListTypes": "cassandra:Select"
},
"cognito-idp": {
"DescribeTermsByClient": "cognito-idp:DescribeTerms"
},
"connect": {
"UpdateUserConfig": "connect:UpdateUserPhoneConfig"
},
@@ -227,9 +224,11 @@
"ListUtteranceMetrics": "lex:ListAggregatedUtterances"
},
"mediaconnect": {
"BatchGetDestinationEndpoint": "mediaconnect:GetDestinationEndpoint",
"BatchGetRouterInput": "mediaconnect:GetRouterInput",
"BatchGetRouterNetworkInterface": "mediaconnect:GetRouterNetworkInterface",
"BatchGetRouterOutput": "mediaconnect:GetRouterOutput"
"BatchGetRouterOutput": "mediaconnect:GetRouterOutput",
"BatchGetSourceEndpoint": "mediaconnect:GetSourceEndpoint"
},
"qapps": {
"CreatePresignedUrl": "qapps:ImportDocument"
@@ -1,5 +1,5 @@
{
"_source": {"generator": "tools/aws/regen_iam_request_resources.py", "reference": "https://servicereference.us-east-1.amazonaws.com/", "botocore": "botocore 1.43.113 (installed package)", "retrieved": "2026-10-30", "note": "make iam-request-resources-check re-derives every operation's resources from botocore; make iam-request-resources-verify checks every action, type and format against AWS."},
"_source": {"generator": "tools/aws/regen_iam_request_resources.py", "reference": "https://servicereference.us-east-1.amazonaws.com/", "botocore": "botocore 1.43.113 (installed package)", "retrieved": "2026-10-31", "note": "make iam-request-resources-check re-derives every operation's resources from botocore; make iam-request-resources-verify checks every action, type and format against AWS."},
"namespaces": {"acm": ["acm"], "athena": ["athena"], "bcm-data-exports": ["bcm-data-exports"], "bcm-pricing-calculator": ["bcm-pricing-calculator"], "budgets": ["budgets"], "ce": ["ce"], "cloudtrail": ["cloudtrail"], "codebuild": ["codebuild"], "codepipeline": ["codepipeline"], "cognito-identity": ["cognito-identity"], "cognito-idp": ["cognito-idp"], "cur": ["cur"], "ecr": ["ecr"], "elasticloadbalancing": ["elb", "elbv2"], "events": ["events"], "firehose": ["firehose"], "globalaccelerator": ["globalaccelerator"], "kinesisanalytics": ["kinesisanalyticsv2"], "servicediscovery": ["servicediscovery"], "servicequotas": ["service-quotas"], "states": ["stepfunctions"], "textract": ["textract"], "timestream-influxdb": ["timestream-influxdb"], "translate": ["translate"]},
"clientsNotRead": {"eventbridgev2": "EventBridge V2, the AWSEventsV2 target over Smithy RPC v2 CBOR on the eventsv2 endpoint, which Floci does not serve; its operations share EventBridge's names and name their resources by other members", "kinesisanalytics": "Kinesis Data Analytics v1, SQL applications on the KinesisAnalytics_20150814 target, which Floci does not serve (it serves v2, kinesisanalyticsv2); its operations share v2's names and name their resources by other members"},
"handBuilt": ["apigateway", "dsql", "dynamodb", "eks", "iam", "kinesis", "kms", "lambda", "logs", "pipes", "resource-groups", "s3", "scheduler", "secretsmanager", "sns", "sqs", "ssm", "sts"],
@@ -72,7 +72,7 @@
"athena:GetCalculationExecutionStatus": {"action": "athena:GetCalculationExecutionStatus", "types": ["workgroup"], "resources": []},
"athena:GetCapacityAssignmentConfiguration": {"action": "athena:GetCapacityAssignmentConfiguration", "types": ["capacity-reservation"], "resources": [{"type": "capacity-reservation", "fill": {"CapacityReservationName": "CapacityReservationName"}}]},
"athena:GetCapacityReservation": {"action": "athena:GetCapacityReservation", "types": ["capacity-reservation"], "resources": [{"type": "capacity-reservation", "fill": {"CapacityReservationName": "Name"}}]},
"athena:GetDataCatalog": {"action": "athena:GetDataCatalog", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "Name"}}]},
"athena:GetDataCatalog": {"action": "athena:GetDataCatalog", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "Name"}, "absent": {"Name": "AwsDataCatalog"}}]},
"athena:GetDatabase": {"action": "athena:GetDatabase", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}}]},
"athena:GetNamedQuery": {"action": "athena:GetNamedQuery", "types": ["workgroup"], "resources": []},
"athena:GetNotebookMetadata": {"action": "athena:GetNotebookMetadata", "types": ["workgroup"], "resources": []},
@@ -84,14 +84,14 @@
"athena:GetSession": {"action": "athena:GetSession", "types": ["session", "workgroup"], "resources": [{"type": "session", "fill": {"SessionId": "SessionId"}}]},
"athena:GetSessionEndpoint": {"action": "athena:GetSessionEndpoint", "types": ["session", "workgroup"], "resources": [{"type": "session", "fill": {"SessionId": "SessionId"}}]},
"athena:GetSessionStatus": {"action": "athena:GetSessionStatus", "types": ["session", "workgroup"], "resources": [{"type": "session", "fill": {"SessionId": "SessionId"}}]},
"athena:GetTableMetadata": {"action": "athena:GetTableMetadata", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}}, {"type": "datacatalog", "fill": {}, "fixed": {"DataCatalogName": "AwsDataCatalog"}}]},
"athena:GetTableMetadata": {"action": "athena:GetTableMetadata", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}, "absent": {"CatalogName": "AwsDataCatalog"}}, {"type": "datacatalog", "fill": {}, "fixed": {"DataCatalogName": "AwsDataCatalog"}}]},
"athena:GetWorkGroup": {"action": "athena:GetWorkGroup", "types": ["workgroup"], "resources": [{"type": "workgroup", "fill": {"WorkGroupName": "WorkGroup"}, "absent": {"WorkGroup": "primary"}}]},
"athena:ImportNotebook": {"action": "athena:ImportNotebook", "types": ["workgroup"], "resources": [{"type": "workgroup", "fill": {"WorkGroupName": "WorkGroup"}}]},
"athena:ListApplicationDPUSizes": {"action": "athena:ListApplicationDPUSizes", "types": [], "resources": []},
"athena:ListCalculationExecutions": {"action": "athena:ListCalculationExecutions", "types": ["workgroup"], "resources": []},
"athena:ListCapacityReservations": {"action": "athena:ListCapacityReservations", "types": [], "resources": []},
"athena:ListDataCatalogs": {"action": "athena:ListDataCatalogs", "types": [], "resources": []},
"athena:ListDatabases": {"action": "athena:ListDatabases", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}}, {"type": "datacatalog", "fill": {}, "fixed": {"DataCatalogName": "AwsDataCatalog"}}]},
"athena:ListDatabases": {"action": "athena:ListDatabases", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}, "absent": {"CatalogName": "AwsDataCatalog"}}, {"type": "datacatalog", "fill": {}, "fixed": {"DataCatalogName": "AwsDataCatalog"}}]},
"athena:ListEngineVersions": {"action": "athena:ListEngineVersions", "types": [], "resources": []},
"athena:ListExecutors": {"action": "athena:ListExecutors", "types": [], "resources": []},
"athena:ListNamedQueries": {"action": "athena:ListNamedQueries", "types": ["workgroup"], "resources": [{"type": "workgroup", "fill": {"WorkGroupName": "WorkGroup"}, "absent": {"WorkGroup": "primary"}}]},
@@ -100,7 +100,7 @@
"athena:ListPreparedStatements": {"action": "athena:ListPreparedStatements", "types": ["workgroup"], "resources": [{"type": "workgroup", "fill": {"WorkGroupName": "WorkGroup"}}]},
"athena:ListQueryExecutions": {"action": "athena:ListQueryExecutions", "types": ["workgroup"], "resources": [{"type": "workgroup", "fill": {"WorkGroupName": "WorkGroup"}, "absent": {"WorkGroup": "primary"}}]},
"athena:ListSessions": {"action": "athena:ListSessions", "types": ["workgroup"], "resources": [{"type": "workgroup", "fill": {"WorkGroupName": "WorkGroup"}}]},
"athena:ListTableMetadata": {"action": "athena:ListTableMetadata", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}}, {"type": "datacatalog", "fill": {}, "fixed": {"DataCatalogName": "AwsDataCatalog"}}]},
"athena:ListTableMetadata": {"action": "athena:ListTableMetadata", "types": ["datacatalog"], "resources": [{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}, "absent": {"CatalogName": "AwsDataCatalog"}}, {"type": "datacatalog", "fill": {}, "fixed": {"DataCatalogName": "AwsDataCatalog"}}]},
"athena:ListTagsForResource": {"action": "athena:ListTagsForResource", "types": ["capacity-reservation", "datacatalog", "session", "workgroup"], "resources": [{"types": ["capacity-reservation", "datacatalog", "session", "workgroup"], "arn": "ResourceARN"}]},
"athena:ListWorkGroups": {"action": "athena:ListWorkGroups", "types": [], "resources": []},
"athena:PutCapacityAssignmentConfiguration": {"action": "athena:PutCapacityAssignmentConfiguration", "types": ["capacity-reservation", "workgroup"], "resources": [{"type": "capacity-reservation", "fill": {"CapacityReservationName": "CapacityReservationName"}}]},
@@ -491,7 +491,7 @@
"cognito-idp:DescribeResourceServer": {"action": "cognito-idp:DescribeResourceServer", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
"cognito-idp:DescribeRiskConfiguration": {"action": "cognito-idp:DescribeRiskConfiguration", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
"cognito-idp:DescribeTerms": {"action": "cognito-idp:DescribeTerms", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
"cognito-idp:DescribeTermsByClient": {"action": "cognito-idp:DescribeTerms", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
"cognito-idp:DescribeTermsByClient": {"action": "cognito-idp:DescribeTermsByClient", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
"cognito-idp:DescribeUserImportJob": {"action": "cognito-idp:DescribeUserImportJob", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
"cognito-idp:DescribeUserPool": {"action": "cognito-idp:DescribeUserPool", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
"cognito-idp:DescribeUserPoolClient": {"action": "cognito-idp:DescribeUserPoolClient", "types": ["userpool"], "resources": [{"type": "userpool", "fill": {"UserPoolId": "UserPoolId"}}]},
@@ -486,4 +486,19 @@ class AthenaDataCatalogIntegrationTest {
.statusCode(400)
.body("__type", equalTo("InvalidRequestException"));
}
@Test
@Order(19)
void getDataCatalogNamingNullServesTheBuiltInGlueCatalog() {
given()
.header("X-Amz-Target", "AmazonAthena.GetDataCatalog")
.contentType(CONTENT_TYPE)
.body("{ \"Name\": null }")
.when()
.post("/")
.then()
.statusCode(200)
.body("DataCatalog.Name", equalTo("AwsDataCatalog"))
.body("DataCatalog.Type", equalTo("GLUE"));
}
}
@@ -818,6 +818,28 @@ class IamRequestResourceEnforcementIntegrationTest {
"athena:ListDatabases");
}
/**
* An Athena catalog request naming no catalog, or a JSON null, is checked on {@code AwsDataCatalog}, the one
* {@code GetDataCatalog} answers and the catalog reads read, so a grant on it reaches them and a deny on it applies.
*/
@Test
void aCatalogRequestNamingNoCatalogIsCheckedOnTheGlueOne() {
String glue = "arn:aws:athena:" + REGION + ":" + ACCOUNT + ":datacatalog/AwsDataCatalog";
User user = user("res-glue-catalog");
user.policy(allowOn("athena:GetDataCatalog", glue) + "," + allowOn("athena:ListDatabases", glue));
send(user, "athena", "AmazonAthena.GetDataCatalog", "1.1", "{}").statusCode(200)
.body("DataCatalog.Name", equalTo("AwsDataCatalog"));
send(user, "athena", "AmazonAthena.GetDataCatalog", "1.1", "{\"Name\":null}").statusCode(200)
.body("DataCatalog.Name", equalTo("AwsDataCatalog"));
send(user, "athena", "AmazonAthena.ListDatabases", "1.1", "{\"CatalogName\":null}").statusCode(200);
refusedJson(send(user, "athena", "AmazonAthena.GetDataCatalog", "1.1", "{\"Name\":\"res-other\"}"),
"athena:GetDataCatalog");
User denied = user("res-glue-denied");
denied.policy(allowOn("athena:GetDataCatalog", "*") + ",{\"Effect\":\"Deny\",\"Action\":"
+ "\"athena:GetDataCatalog\",\"Resource\":\"" + glue + "\"}");
refusedJson(send(denied, "athena", "AmazonAthena.GetDataCatalog", "1.1", "{}"), "athena:GetDataCatalog");
}
/**
* A Data Exports export is checked on its ARN, and a create not on the ARN its {@code Export.ExportArn} gives,
* which is the new export's own, so a table's there checks nothing.
+8 -2
View File
@@ -338,10 +338,16 @@ CORRECTIONS: dict[str, tuple[list[dict], str]] = {
"workgroup 'continue running queries in the primary workgroup'), and Floci's "
"GetWorkGroup answers the primary one for a request naming none")
for operation in ("GetWorkGroup", "ListNamedQueries", "ListQueryExecutions", "StartQueryExecution")},
**{f"athena:{operation}": ([{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"}},
"athena:GetDataCatalog": ([{"type": "datacatalog", "fill": {"DataCatalogName": "Name"},
"absent": {"Name": "AwsDataCatalog"}}],
"Floci's GetDataCatalog answers the account's Glue Data Catalog, AwsDataCatalog, for a "
"request naming no catalog, so that is the one checked"),
**{f"athena:{operation}": ([{"type": "datacatalog", "fill": {"DataCatalogName": "CatalogName"},
"absent": {"CatalogName": "AwsDataCatalog"}},
{"type": "datacatalog", "fill": {}, "fixed": {"DataCatalogName": "AwsDataCatalog"}}],
"Floci's handler reads the account's Glue Data Catalog, AwsDataCatalog, whichever "
"catalog CatalogName names, so that one is checked as well as the one named")
"catalog CatalogName names, so that one is checked as well as the one named, and a "
"request naming none is read as naming it")
for operation in ("GetTableMetadata", "ListDatabases", "ListTableMetadata")},
**{f"ce:{operation}": ([], "Floci serves no billing views: it answers the account's costs whichever view "
"BillingViewArn names, so the request is checked on `*`, as one naming no view, and a "