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

@@ -67,6 +67,10 @@ public final class DsqlClusterFixture {
return host;
}
public String identifier() {
return identifier;
}
public String arn() {
return "arn:aws:dsql:" + REGION + ":" + ACCOUNT + ":cluster/" + identifier;
}
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.testing.EnforcementFixtures;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.specification.RequestSpecification;
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.AfterAll;
@@ -17,20 +18,26 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.postgresql.util.PSQLException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.time.Instant;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A cluster's resource-based policy on connect, with IAM enforcement on, as Aurora DSQL evaluates it
* (measured, eu-west-1, 2026-10-22): an explicit Deny that applies to the caller refuses the
* connection, with a hint naming the caller, the action and the cluster, under the conditions the
* statement sets; a statement that does not apply leaves the decision to the caller's own policies.
* A cluster's resource-based policy, with IAM enforcement on, as Aurora DSQL evaluates it (measured,
* eu-west-1, 2026-10-22 and 23): an explicit Deny that applies to the caller refuses the connection,
* with a hint naming the caller, the action and the cluster, under the conditions the statement sets,
* and refuses the control plane calls on the cluster it names; a statement that does not apply leaves
* the decision to the caller's own policies.
*/
@QuarkusTest
@TestProfile(DsqlEnforcementProfile.class)
@@ -118,6 +125,67 @@ class DsqlClusterPolicyIntegrationTest {
}
}
@Test
void anExplicitDenyRefusesTheControlPlaneCallsOnTheClusterItNames() {
String userName = "dsql-" + Long.toString(System.nanoTime(), 36);
String authorization = EnforcementFixtures.auth(ACCOUNT, "iam");
EnforcementFixtures.UserCredentials user = EnforcementFixtures.createUser(cleanup, httpPort, authorization,
userName);
EnforcementFixtures.putUserPolicy(httpPort, authorization, userName, "manage", """
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"dsql:*","Resource":"*"}]}""");
String clusterPath = "/cluster/" + cluster.identifier();
String tagsPath = "/tags/" + URLEncoder.encode(cluster.arn(), StandardCharsets.UTF_8);
String vpcEndpointPath = "/clusters/" + cluster.identifier() + "/vpc-endpoint-service-name";
as(user).get(clusterPath).then().statusCode(200);
cluster.putPolicy("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Deny\",\"Principal\":{\"AWS\":"
+ "\"arn:aws:iam::" + ACCOUNT + ":root\"},\"Action\":[\"dsql:GetCluster\",\"dsql:UpdateCluster\","
+ "\"dsql:TagResource\",\"dsql:UntagResource\",\"dsql:ListTagsForResource\","
+ "\"dsql:GetVpcEndpointServiceName\"],\"Resource\":\"*\"}]}");
as(user).get(clusterPath).then().statusCode(403).body("__type", equalTo("AccessDeniedException"));
as(user).body(Map.of("deletionProtectionEnabled", false)).post(clusterPath).then().statusCode(403);
as(user).urlEncodingEnabled(false).body(Map.of("tags", Map.of("team", "data"))).post(tagsPath)
.then().statusCode(403);
as(user).urlEncodingEnabled(false).get(tagsPath).then().statusCode(403);
// The same tagging is served at /tags, naming the ARN in the query or the body.
as(user).body(Map.of("resourceArn", cluster.arn(), "tags", Map.of("team", "data"))).post("/tags")
.then().statusCode(403);
as(user).queryParam("resourceArn", cluster.arn()).get("/tags").then().statusCode(403);
as(user).queryParam("resourceArn", cluster.arn()).queryParam("tagKeys", "team").delete("/tags")
.then().statusCode(403);
as(user).get(vpcEndpointPath).then().statusCode(403);
// The calls the policy does not name answer.
as(user).get(clusterPath + "/policy").then().statusCode(200);
as(user).get("/cluster").then().statusCode(200);
cluster.removePolicy();
as(user).get(clusterPath).then().statusCode(200);
}
/**
* The control plane is checked against the resources DSQL names (Service Authorization Reference):
* each cluster call against the cluster, and CreateCluster and ListClusters against
* {@code cluster/*} (measured).
*/
@Test
void theControlPlaneIsCheckedAgainstTheClusterItNames() {
String userName = "dsql-" + Long.toString(System.nanoTime(), 36);
String authorization = EnforcementFixtures.auth(ACCOUNT, "iam");
EnforcementFixtures.UserCredentials user = EnforcementFixtures.createUser(cleanup, httpPort, authorization,
userName);
EnforcementFixtures.putUserPolicy(httpPort, authorization, userName, "read", """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"dsql:GetCluster","Resource":"%s"},
{"Effect":"Allow","Action":"dsql:ListClusters","Resource":"arn:aws:dsql:%s:%s:cluster/*"}]}"""
.formatted(cluster.arn(), DsqlClusterFixture.REGION, ACCOUNT));
as(user).get("/cluster/" + cluster.identifier()).then().statusCode(200);
as(user).get("/cluster").then().statusCode(200);
as(user).get("/cluster/abcdefghijklmnopqrstuvwxyz").then().statusCode(403)
.body("__type", equalTo("AccessDeniedException"));
as(user).get("/cluster/" + cluster.identifier() + "/policy").then().statusCode(403);
}
/** A new IAM user whose own policy lets it connect as {@code admin}. */
private EnforcementFixtures.UserCredentials adminUser(String userName) {
String authorization = EnforcementFixtures.auth(ACCOUNT, "iam");
@@ -129,6 +197,12 @@ class DsqlClusterPolicyIntegrationTest {
return user;
}
/** A control plane request signed with {@code user}'s key. */
private RequestSpecification as(EnforcementFixtures.UserCredentials user) {
return given().port(httpPort).contentType("application/json")
.header("Authorization", EnforcementFixtures.auth(user.accessKeyId(), DsqlClusterFixture.REGION, "dsql"));
}
private Connection connect(EnforcementFixtures.UserCredentials user) throws Exception {
return cluster.connect("admin", cluster.token("DbConnectAdmin", user.accessKeyId(), user.secretAccessKey(),
Instant.now(), 900, null));
@@ -53,7 +53,7 @@ class IamRestRouteCoverageTest {
/** Models every operation of which is checked: the services whose routes the registry maps in full. */
private static final Set<String> FULLY_ROUTED_MODELS =
Set.of("scheduler", "pipes", "lambda", "lambda-microvms", "lambda-core");
Set.of("scheduler", "pipes", "lambda", "lambda-microvms", "lambda-core", "dsql");
private final IamActionRegistry registry = new IamActionRegistry();
@@ -1371,6 +1371,37 @@ class ResourceArnBuilderTest {
assertEquals("*", backed.build("lambda", ctx, "us-east-1", "000000000000"));
}
@Test
void dsqlRoutesResolveTheClusterTheTaggedArnOrNone() {
String cluster = "arn:aws:dsql:eu-west-1:000000000000:cluster/abcdefghijklmnopqrstuvwxyz";
for (String path : List.of("/cluster/abcdefghijklmnopqrstuvwxyz", "/cluster/abcdefghijklmnopqrstuvwxyz/policy",
"/clusters/abcdefghijklmnopqrstuvwxyz/vpc-endpoint-service-name", "/tags/" + cluster)) {
when(uriInfo.getPath()).thenReturn(path);
assertEquals(List.of(cluster), builder.buildResources("dsql", ctx, "eu-west-1", "000000000000"), path);
}
// The same tagging is served at /tags, the ARN in the resourceArn query parameter or body field.
when(uriInfo.getPath()).thenReturn("/tags");
queryParams.putSingle("resourceArn", cluster);
assertEquals(List.of(cluster), builder.buildResources("dsql", ctx, "eu-west-1", "000000000000"));
queryParams.clear();
when(ctx.getMethod()).thenReturn("POST");
setJsonBody("{\"resourceArn\":\"" + cluster + "\",\"tags\":{}}");
assertEquals(List.of(cluster), builder.buildResources("dsql", ctx, "eu-west-1", "000000000000"));
when(ctx.getMethod()).thenReturn("GET");
// A stream route names the stream, or its cluster to create or list streams.
when(uriInfo.getPath()).thenReturn("/stream/abcdefghijklmnopqrstuvwxyz");
assertEquals(List.of(cluster), builder.buildResources("dsql", ctx, "eu-west-1", "000000000000"));
when(uriInfo.getPath()).thenReturn("/stream/abcdefghijklmnopqrstuvwxyz/s1");
assertEquals(List.of(cluster + "/stream/s1"), builder.buildResources("dsql", ctx, "eu-west-1", "000000000000"));
// CreateCluster and ListClusters are checked against every cluster, as DSQL checks them (measured).
when(uriInfo.getPath()).thenReturn("/cluster");
assertEquals(List.of("arn:aws:dsql:eu-west-1:000000000000:cluster/*"),
builder.buildResources("dsql", ctx, "eu-west-1", "000000000000"));
when(uriInfo.getPath()).thenReturn("/cluster/abcdefghijklmnopqrstuvwxyz");
assertEquals(List.of("arn:aws-cn:dsql:polygondwanaland-west-1:000000000000:cluster/abcdefghijklmnopqrstuvwxyz"),
builder.buildResources("dsql", ctx, "polygondwanaland-west-1", "000000000000", "aws-cn"));
}
@Test
void schedulerRoutesResolveTheScheduleInItsGroupTheGroupOrTheTaggedArn() {
when(uriInfo.getPath()).thenReturn("/schedules/nightly");