mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check Aurora DSQL requests on the clusters they name, from the generated table (#9011)
Aurora DSQL was built by hand: ResourceArnBuilder read a cluster or
stream from its path, or a tagging route's ARN, IamEnforcementFilter
sent DSQL requests there without their operation, the request resources
table held no DSQL operation, and nothing gave a policy condition a
cluster's tags. dsql moves from HAND_BUILT to NAMESPACES, so the table
gives each operation the cluster or stream its path names, or the ARN
its modeled /tags/{resourceArn} carries, from botocore's REST model;
ListClusters, for which the Service Reference lists no resource type, is
checked on cluster/* from a MEASURED entry citing the AccessDenied
message AWS returned in #6328. ResourceArnBuilder's DSQL branch, with
the path and tagged-ARN helpers only it still used, and the filter's
DSQL case go, and the shared tags controller now serves DSQL's
tagging on its modeled route only, refusing the bare /tags. Only DSQL's
operations change in the table. DsqlStoredResourceArns answers a
cluster's stored tags; TagResource and UntagResource give the cluster a
new map under its lock, and its tags field is volatile.
This commit is contained in:
1 parent
ede9601b82
commit
66dbdd2935
12 files changed
+185
-94
No files matched your search
@@ -148,12 +148,13 @@ class DsqlClusterPolicyIntegrationTest {
|
||||
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.
|
||||
// The bare /tags is no route of DSQL's model, as AWS gives it none: it is refused as an ARN that path does
|
||||
// not serve, 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);
|
||||
.then().statusCode(400).body("message", equalTo("Invalid resource ARN: " + cluster.arn()));
|
||||
as(user).queryParam("resourceArn", cluster.arn()).get("/tags").then().statusCode(400);
|
||||
as(user).queryParam("resourceArn", cluster.arn()).queryParam("tagKeys", "team").delete("/tags")
|
||||
.then().statusCode(403);
|
||||
.then().statusCode(400);
|
||||
as(user).get(vpcEndpointPath).then().statusCode(403);
|
||||
// The calls the policy does not name answer.
|
||||
as(user).get(clusterPath + "/policy").then().statusCode(200);
|
||||
|
||||
@@ -134,6 +134,28 @@ class DsqlServiceTest {
|
||||
assertEquals(0, service.listClusters(REGION, null, null).clusters().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void iamReadsTheTagsTheClusterItsArnNamesHoldsInTheRequestsAccount() {
|
||||
DsqlStoredResourceArns stored = new DsqlStoredResourceArns(service, new RegionResolver(REGION, ACCOUNT));
|
||||
DsqlCluster cluster = service.createCluster(REGION, false, null, Map.of("team", "data"), null, null, null,
|
||||
null, false);
|
||||
String arn = cluster.getArn();
|
||||
assertEquals(Map.of("team", "data"), stored.storedTags(arn));
|
||||
|
||||
service.tagResource(REGION, arn, Map.of("env", "test"));
|
||||
service.untagResource(REGION, arn, List.of("team"));
|
||||
assertEquals(Map.of("env", "test"), stored.storedTags(arn));
|
||||
// Another account's cluster, another Region's, a stream of the cluster or a cluster Floci does not hold
|
||||
// names no tags Floci holds.
|
||||
String id = cluster.getIdentifier();
|
||||
assertEquals(Map.of(), stored.storedTags("arn:aws:dsql:" + REGION + ":444455556666:cluster/" + id));
|
||||
assertEquals(Map.of(), stored.storedTags("arn:aws:dsql:eu-west-2:" + ACCOUNT + ":cluster/" + id));
|
||||
assertEquals(Map.of(), stored.storedTags(arn + "/stream/s1"));
|
||||
assertEquals(Map.of(), stored.storedTags("arn:aws:dsql:" + REGION + ":" + ACCOUNT
|
||||
+ ":cluster/aaaaaaaaaaaaaaaaaaaaaaaaaa"));
|
||||
assertEquals(Map.of(), stored.storedTags("arn:aws:sqs:" + REGION + ":" + ACCOUNT + ":cluster/" + id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTagCallRefusesWhatIsNoClusterOfTheRegion() {
|
||||
DsqlCluster cluster = cluster();
|
||||
|
||||
@@ -2358,35 +2358,41 @@ class ResourceArnBuilderTest {
|
||||
AwsRegions.partitionFor(region)).getFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* An Aurora DSQL route is checked on the cluster or stream its path names, or the ARN its tagging route names,
|
||||
* from the table; CreateCluster and ListClusters on every cluster, as DSQL checks them (measured).
|
||||
*/
|
||||
@Test
|
||||
void dsqlRoutesResolveTheClusterTheTaggedArnOrNone() {
|
||||
void dsqlRoutesResolveTheClusterTheStreamOrTheTaggedArn() {
|
||||
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");
|
||||
request("/cluster/abcdefghijklmnopqrstuvwxyz");
|
||||
assertEquals(List.of(cluster), dsql("dsql:GetCluster", "eu-west-1", "aws"));
|
||||
request("/cluster/abcdefghijklmnopqrstuvwxyz/policy");
|
||||
assertEquals(List.of(cluster), dsql("dsql:GetClusterPolicy", "eu-west-1", "aws"));
|
||||
request("/clusters/abcdefghijklmnopqrstuvwxyz/vpc-endpoint-service-name");
|
||||
assertEquals(List.of(cluster), dsql("dsql:GetVpcEndpointServiceName", "eu-west-1", "aws"));
|
||||
request("/tags/" + cluster.replace(":", "%3A").replace("/", "%2F"));
|
||||
assertEquals(List.of(cluster), dsql("dsql:ListTagsForResource", "eu-west-1", "aws"));
|
||||
// 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");
|
||||
request("/stream/abcdefghijklmnopqrstuvwxyz");
|
||||
assertEquals(List.of(cluster), dsql("dsql:ListStreams", "eu-west-1", "aws"));
|
||||
request("/stream/abcdefghijklmnopqrstuvwxyz/s1");
|
||||
assertEquals(List.of(cluster + "/stream/s1"), dsql("dsql:GetStream", "eu-west-1", "aws"));
|
||||
request("/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");
|
||||
dsql("dsql:ListClusters", "eu-west-1", "aws"));
|
||||
when(ctx.getMethod()).thenReturn("POST");
|
||||
assertEquals(List.of("arn:aws:dsql:eu-west-1:000000000000:cluster/*"),
|
||||
dsql("dsql:CreateCluster", "eu-west-1", "aws"));
|
||||
when(ctx.getMethod()).thenReturn("GET");
|
||||
request("/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"));
|
||||
dsql("dsql:GetCluster", "polygondwanaland-west-1", "aws-cn"));
|
||||
}
|
||||
|
||||
private List<String> dsql(String operation, String region, String partition) {
|
||||
return builder.buildResources("dsql", operation, ctx, region, "000000000000", partition);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user