fix(dsql): enforce IAM and the cluster's policy on the control plane (#6328)

* fix(dsql): enforce IAM and the cluster's policy on the control plane

A cluster's resource-based policy governs DSQL's control plane as well as
its connections (measured, eu-west-1): a Deny of dsql:GetCluster,
UpdateCluster, TagResource or GetVpcEndpointServiceName refuses that call,
and a call it does not name still answers. With IAM enforcement on, Floci
left every DSQL control plane route unchecked: no rule in
IamActionRegistry mapped one, so the policies, identity or resource, were
never read there.

IamActionRegistry maps every operation of DSQL's model to its action, the
stream operations Floci does not serve included, and
IamRestRouteCoverageTest now checks all of them against botocore's routes,
vendored for DSQL by regen_rest_routes.py. ResourceArnBuilder names the
resource each call is checked against, as the Service Authorization
Reference gives it: the cluster, the stream, or the ARN a tagging route
names, minted in the request's partition. CreateCluster and ListClusters
are checked against cluster/*, as DSQL checks them (measured; the
reference lists ListClusters with no resource). The enforcement filter
then reads the cluster's policy through DsqlResourcePolicyProvider, as it
reads a topic's or a function's.

* fix(dsql): check tagging at /tags too, where the ARN is in the query or body

Asked in review: Floci serves DSQL's tagging at /tags as well as at
/tags/{arn}, naming the ARN in the resourceArn query parameter or body field,
and the rules matched only the path form, so a bare /tags call reached DSQL's
tag handler unchecked. The rules now match both, as Scheduler's do, and the
control plane test tags, lists and untags through each form.
This commit is contained in:
Alessandro Lattao authored and GitHub committed 2026-10-23 06:51:19 -04:00
1 parent eea87ca998
commit 3944d6edc2
11 files changed
+193 -13

No files matched your search

@@ -1516,7 +1516,7 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
if ("secretsmanager".equals(credentialScope)) {
return arnBuilder.buildSecretsManagerResources(action, ctx, region, accountId, requestPartition());
}
if ("scheduler".equals(credentialScope) || "pipes".equals(credentialScope)) {
if ("scheduler".equals(credentialScope) || "pipes".equals(credentialScope) || "dsql".equals(credentialScope)) {
return arnBuilder.buildResources(credentialScope, ctx, region, accountId, requestPartition());
}
return arnBuilder.buildResources(credentialScope, ctx, region, accountId);
@@ -256,6 +256,25 @@ public class IamActionRegistry {
rule("scheduler", "POST", "^/tags(/.+)?$", "scheduler:TagResource"),
rule("scheduler", "DELETE", "^/tags(/.+)?$", "scheduler:UntagResource"),
// ── Aurora DSQL ────────────────────────────────────────────────────────
rule("dsql", "POST", "^/cluster$", "dsql:CreateCluster"),
rule("dsql", "GET", "^/cluster$", "dsql:ListClusters"),
rule("dsql", "GET", "^/cluster/[^/]+$", "dsql:GetCluster"),
rule("dsql", "POST", "^/cluster/[^/]+$", "dsql:UpdateCluster"),
rule("dsql", "DELETE", "^/cluster/[^/]+$", "dsql:DeleteCluster"),
rule("dsql", "POST", "^/cluster/[^/]+/policy$", "dsql:PutClusterPolicy"),
rule("dsql", "GET", "^/cluster/[^/]+/policy$", "dsql:GetClusterPolicy"),
rule("dsql", "DELETE", "^/cluster/[^/]+/policy$", "dsql:DeleteClusterPolicy"),
rule("dsql", "GET", "^/clusters/[^/]+/vpc-endpoint-service-name$", "dsql:GetVpcEndpointServiceName"),
rule("dsql", "POST", "^/stream/[^/]+$", "dsql:CreateStream"),
rule("dsql", "GET", "^/stream/[^/]+$", "dsql:ListStreams"),
rule("dsql", "GET", "^/stream/[^/]+/[^/]+$", "dsql:GetStream"),
rule("dsql", "DELETE", "^/stream/[^/]+/[^/]+$", "dsql:DeleteStream"),
// Tagging is served at /tags/<arn> and at /tags, naming the ARN in the query or the body.
rule("dsql", "GET", "^/tags(/.+)?$", "dsql:ListTagsForResource"),
rule("dsql", "POST", "^/tags(/.+)?$", "dsql:TagResource"),
rule("dsql", "DELETE", "^/tags(/.+)?$", "dsql:UntagResource"),
// ── EventBridge Pipes ──────────────────────────────────────────────────
rule("pipes", "POST", "^/v1/pipes/[^/]+/start$", "pipes:StartPipe"),
rule("pipes", "POST", "^/v1/pipes/[^/]+/stop$", "pipes:StopPipe"),
@@ -107,9 +107,9 @@ public class ResourceArnBuilder {
}
/**
* The resources a request is checked against. Scheduler and Pipes ARNs are minted in {@code partition},
* the request's, as those services mint theirs, so a Region no partition publishes gets the deployment's
* partition rather than {@code aws}.
* The resources a request is checked against. Scheduler, Pipes and DSQL ARNs are minted in
* {@code partition}, the request's, as those services mint theirs, so a Region no partition publishes gets
* the deployment's partition rather than {@code aws}.
*/
public List<String> buildResources(String credentialScope, ContainerRequestContext ctx,
String region, String accountId, String partition) {
@@ -130,6 +130,7 @@ public class ResourceArnBuilder {
case "resource-groups" -> List.of(buildResourceGroupArn(ctx, region, accountId));
case "scheduler" -> List.of(buildSchedulerArn(path, ctx, region, accountId, partition));
case "pipes" -> List.of(buildPipesArn(path, ctx, region, accountId, partition));
case "dsql" -> List.of(buildDsqlArn(path, ctx, region, accountId, partition));
default -> List.of("*");
};
}
@@ -984,6 +985,29 @@ public class ResourceArnBuilder {
return taggedResource(ctx);
}
/**
* The resource of an Aurora DSQL route, as the Service Authorization Reference names it: the cluster
* a cluster route names, the stream a stream route names (its cluster, to create or list streams), or
* the ARN a tagging route names. CreateCluster and ListClusters are checked against
* {@code cluster/*}, as DSQL checks them (measured).
*/
private String buildDsqlArn(String path, ContainerRequestContext ctx, String region, String accountId,
String partition) {
String cluster = "/cluster".equals(path) ? "*" : segmentAfterPrefix(path, "/cluster/");
if (cluster == null) {
cluster = segmentAfterPrefix(path, "/clusters/");
}
String streamCluster = segmentAfterPrefix(path, "/stream/");
if (streamCluster != null) {
String stream = segmentAfterPrefix(path, "/stream/" + streamCluster + "/");
cluster = stream == null ? streamCluster : streamCluster + "/stream/" + stream;
}
if (cluster != null) {
return new AwsArnUtils.Arn(partition, "dsql", region, accountId, "cluster/" + cluster).toString();
}
return taggedResource(ctx);
}
/** The resource of an EventBridge Pipes route: {@code pipe/<name>}, or the ARN a tagging route names. */
private String buildPipesArn(String path, ContainerRequestContext ctx, String region, String accountId,
String partition) {