mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check EventBridge Pipes requests on the pipes they name, from the generated table (#9000)
Pipes was built by hand: ResourceArnBuilder read a pipe's name from its path or a tagging route's ARN, IamEnforcementFilter sent Pipes requests there without their operation, the request resources table held no Pipes operation, and nothing gave a policy condition a pipe's tags. pipes moves from HAND_BUILT to NAMESPACES, so the table gives each operation the pipe its path's Name names, or the ARN a tagging route carries, from botocore's REST model, and ResourceArnBuilder's Pipes branch and the filter's Pipes case go. Only Pipes' operations change in the table. PipesStoredResourceArns answers a pipe's stored tags; TagResource and UntagResource give the pipe a new map one call at a time, and its tags field is volatile.
This commit is contained in:
1 parent
d8a638e4af
commit
56d8b9aedc
12 files changed
+168
-55
No files matched your search
@@ -17,11 +17,11 @@ import static org.mockito.Mockito.when;
|
||||
class TagDispatcherTest {
|
||||
|
||||
private static final String GROUP = "arn:aws:scheduler:us-east-1:000000000000:schedule-group/reports";
|
||||
private static final String PIPE = "arn:aws:pipes:us-east-1:000000000000:pipe/orders";
|
||||
private static final String REST_API = "arn:aws:apigateway:us-east-1::/restapis/abc123";
|
||||
|
||||
private final TagHandler scheduler = handler("scheduler");
|
||||
private final TagHandler pipes = handler("pipes");
|
||||
private final TagDispatcher dispatcher = new TagDispatcher(List.of(scheduler, pipes),
|
||||
private final TagHandler apiGateway = handler("apigateway");
|
||||
private final TagDispatcher dispatcher = new TagDispatcher(List.of(scheduler, apiGateway),
|
||||
new RegionResolver("us-east-1", "000000000000"), new ObjectMapper());
|
||||
|
||||
/**
|
||||
@@ -41,11 +41,14 @@ class TagDispatcherTest {
|
||||
}
|
||||
}
|
||||
|
||||
/** Pipes is still built by hand, its tagged ARN read wherever the controller reads it, so every route serves it. */
|
||||
/**
|
||||
* API Gateway is still built by hand, its tagged ARN read wherever the controller reads it, so every route serves
|
||||
* it.
|
||||
*/
|
||||
@Test
|
||||
void aServiceBuiltByHandIsServedOnEveryRoute() {
|
||||
assertSame(pipes, dispatcher.resolveHandler(PIPE, sent("/tags")));
|
||||
assertSame(pipes, dispatcher.resolveHandler(PIPE, sent("/tags/" + PIPE)));
|
||||
assertSame(apiGateway, dispatcher.resolveHandler(REST_API, sent("/tags")));
|
||||
assertSame(apiGateway, dispatcher.resolveHandler(REST_API, sent("/tags/" + REST_API)));
|
||||
}
|
||||
|
||||
private static TagHandler handler(String serviceKey) {
|
||||
|
||||
@@ -247,6 +247,32 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
"pipes:TagResource");
|
||||
}
|
||||
|
||||
/**
|
||||
* A Pipes route is checked on the pipe its path names, from the generated table, and an {@code aws:ResourceTag}
|
||||
* condition reads the tags Pipes holds on it, so an allow on one team's tag lets the caller describe that team's
|
||||
* pipe and not another's.
|
||||
*/
|
||||
@Test
|
||||
void aPipesResourceTagConditionReadsTheTagsOfThePipe() {
|
||||
String tagged = pipe("route-pipe-" + suffix(), "data");
|
||||
String other = pipe("route-pipe-" + suffix(), "web");
|
||||
String user = user("route-pipe-tags");
|
||||
|
||||
policy(user, onTeam("Allow", "pipes:DescribePipe", "data"));
|
||||
request(user, "pipes", "GET", "/v1/pipes/" + tagged, null).statusCode(200);
|
||||
refused(request(user, "pipes", "GET", "/v1/pipes/" + other, null), "pipes:DescribePipe");
|
||||
}
|
||||
|
||||
/** A stopped pipe an administrator creates between two queue ARNs, tagged with {@code team}; its name. */
|
||||
private String pipe(String name, String team) {
|
||||
adminOf("pipes").body("{\"Source\":\"arn:aws:sqs:us-east-1:" + ACCOUNT + ":route-source\",\"Target\":"
|
||||
+ "\"arn:aws:sqs:us-east-1:" + ACCOUNT + ":route-target\",\"RoleArn\":\"arn:aws:iam::" + ACCOUNT
|
||||
+ ":role/route-pipe\",\"DesiredState\":\"STOPPED\",\"Tags\":{\"team\":\"" + team + "\"}}")
|
||||
.post("/v1/pipes/" + name).then().statusCode(200);
|
||||
cleanup.register(() -> adminOf("pipes").delete("/v1/pipes/" + name).then().statusCode(200));
|
||||
return name;
|
||||
}
|
||||
|
||||
@Test
|
||||
void sharedTaggingIsCheckedAsTheServiceItsArnNames() {
|
||||
// The shared tagging routes hand the request to the service its ARN names, whatever scope it is
|
||||
|
||||
@@ -2571,7 +2571,7 @@ class ResourceArnBuilderTest {
|
||||
"aws-cn"));
|
||||
request("/v1/pipes/orders");
|
||||
assertEquals(List.of("arn:aws-cn:pipes:xx-local-1:000000000000:pipe/orders"),
|
||||
builder.buildResources("pipes", ctx, "xx-local-1", "000000000000", "aws-cn"));
|
||||
builder.buildResources("pipes", "pipes:DescribePipe", ctx, "xx-local-1", "000000000000", "aws-cn"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2611,17 +2611,25 @@ class ResourceArnBuilderTest {
|
||||
assertEquals(List.of("*"), lambda("GET", "/2017-03-31/tags/shared", "ListTags"));
|
||||
}
|
||||
|
||||
/** A Pipes route is checked on the pipe its path names, or the ARN its tagging route names, from the table. */
|
||||
@Test
|
||||
void pipesRoutesResolveThePipeOrTheTaggedArn() {
|
||||
String pipe = "arn:aws:pipes:us-east-1:000000000000:pipe/orders";
|
||||
when(uriInfo.getPath()).thenReturn("/v1/pipes/orders");
|
||||
assertEquals(pipe, builder.build("pipes", ctx, "us-east-1", "000000000000"));
|
||||
when(uriInfo.getPath()).thenReturn("/v1/pipes/orders/start");
|
||||
assertEquals(pipe, builder.build("pipes", ctx, "us-east-1", "000000000000"));
|
||||
when(uriInfo.getPath()).thenReturn("/tags/" + pipe);
|
||||
assertEquals(pipe, builder.build("pipes", ctx, "us-east-1", "000000000000"));
|
||||
when(uriInfo.getPath()).thenReturn("/v1/pipes");
|
||||
assertEquals("*", builder.build("pipes", ctx, "us-east-1", "000000000000"));
|
||||
when(ctx.getMethod()).thenReturn("GET");
|
||||
request("/v1/pipes/orders");
|
||||
assertEquals(List.of(pipe), pipes("pipes:DescribePipe"));
|
||||
when(ctx.getMethod()).thenReturn("POST");
|
||||
request("/v1/pipes/orders/start");
|
||||
assertEquals(List.of(pipe), pipes("pipes:StartPipe"));
|
||||
when(ctx.getMethod()).thenReturn("GET");
|
||||
request("/tags/" + pipe.replace(":", "%3A").replace("/", "%2F"));
|
||||
assertEquals(List.of(pipe), pipes("pipes:ListTagsForResource"));
|
||||
request("/v1/pipes");
|
||||
assertEquals(List.of("*"), pipes("pipes:ListPipes"));
|
||||
}
|
||||
|
||||
private List<String> pipes(String operation) {
|
||||
return builder.buildResources("pipes", operation, ctx, "us-east-1", ACCOUNT, "aws");
|
||||
}
|
||||
|
||||
/** A durable execution's actions are checked on the execution its ARN names, which a client sends encoded. */
|
||||
|
||||
Reference in new issue
Block a user