mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check SNS requests on the topics they name, from the generated table (#8971)
SNS was built by hand: ResourceArnBuilder read a request's TopicArn and checked everything else on the account's open topic ARN, the request resources table held no SNS operation, and nothing gave a policy condition a topic's tags. sns moves from HAND_BUILT to NAMESPACES, so the table gives each operation the topics botocore's members name (TopicArn, ResourceArn, TargetArn, and CreateTopic's Name), and its ResourceArnBuilder branch goes. Only SNS's operations change in the table. SnsStoredResourceArns answers a topic's stored tags; TagResource and UntagResource give the topic a new map one call at a time, and its tags field is volatile.
This commit is contained in:
1 parent
96015e7532
commit
aabe2247c5
11 files changed
+207
-45
No files matched your search
+34
@@ -1007,6 +1007,40 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* An SNS request is checked on the topic its TopicArn names, from the generated table, so a grant on one topic
|
||||
* does not reach another; and an {@code aws:ResourceTag} condition reads the tags SNS holds on that topic, as
|
||||
* TagResource leaves them.
|
||||
*/
|
||||
@Test
|
||||
void anSnsRequestIsCheckedOnTheTopicItNamesWithItsTags() {
|
||||
String tagged = snsTopic("res-topic-" + suffix());
|
||||
String other = snsTopic("res-topic-" + suffix());
|
||||
admin("sns").formParam("Action", "TagResource").formParam("ResourceArn", tagged)
|
||||
.formParam("Tags.member.1.Key", "team").formParam("Tags.member.1.Value", "data").post("/").then()
|
||||
.statusCode(200);
|
||||
|
||||
User user = user("res-topic");
|
||||
user.policy(allowOn("sns:Publish", tagged) + ",{\"Effect\":\"Allow\",\"Action\":\"sns:GetTopicAttributes\","
|
||||
+ "\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
user.query("sns", "Publish").formParam("TopicArn", tagged).formParam("Message", "x").post("/").then()
|
||||
.statusCode(200);
|
||||
refused(user.query("sns", "Publish").formParam("TopicArn", other).formParam("Message", "x").post("/")
|
||||
.then(), "sns:Publish");
|
||||
user.query("sns", "GetTopicAttributes").formParam("TopicArn", tagged).post("/").then().statusCode(200);
|
||||
refused(user.query("sns", "GetTopicAttributes").formParam("TopicArn", other).post("/").then(),
|
||||
"sns:GetTopicAttributes");
|
||||
}
|
||||
|
||||
/** An SNS topic an administrator creates, deleted after the test; its ARN. */
|
||||
private String snsTopic(String name) {
|
||||
String arn = admin("sns").formParam("Action", "CreateTopic").formParam("Name", name).post("/").then()
|
||||
.statusCode(200).extract().path("CreateTopicResponse.CreateTopicResult.TopicArn");
|
||||
cleanup.register(() -> admin("sns").formParam("Action", "DeleteTopic").formParam("TopicArn", arn).post("/")
|
||||
.then().statusCode(200));
|
||||
return arn;
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCloudMapNamespaceAndServiceAreCheckedOnTheArnsTheirIdsGive() {
|
||||
String namespaceId = cloudMapNamespace("res-ns-" + suffix());
|
||||
|
||||
@@ -1885,20 +1885,35 @@ class ResourceArnBuilderTest {
|
||||
|
||||
// ── SNS ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* A Query request is checked on the topic its body's TopicArn names, read from the generated table; the handler
|
||||
* acts on the body's TopicArn, so a decoy in the query string is not checked.
|
||||
*/
|
||||
@Test
|
||||
void snsBuildsArnFromFormBodyTopicArn() {
|
||||
void snsChecksTheTopicAFormBodysTopicArnNames() {
|
||||
queryParams.add("TopicArn", "arn:aws:sns:us-east-1:000000000000:allowed");
|
||||
setFormBody("Action=Publish&TopicArn=arn%3Aaws%3Asns%3Aus-east-1%3A000000000000%3Aalerts&Message=hi");
|
||||
String arn = builder.build("sns", ctx, "us-east-1", "000000000000");
|
||||
assertEquals("arn:aws:sns:us-east-1:000000000000:alerts", arn);
|
||||
assertEquals(List.of("arn:aws:sns:us-east-1:000000000000:alerts"),
|
||||
builder.buildResources("sns", "sns:Publish", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void snsBuildsArnFromJsonTopicArn() {
|
||||
void snsChecksTheTopicAJsonBodysTopicArnNames() {
|
||||
String topicArn = "arn:aws:sns:us-east-1:000000000000:alerts";
|
||||
setJsonBody("{\"TopicArn\":\"" + topicArn + "\"}");
|
||||
String arn = builder.build("sns", ctx, "us-east-1", "000000000000");
|
||||
assertEquals(topicArn, arn);
|
||||
assertEquals(List.of(topicArn), builder.buildResources("sns", "sns:GetTopicAttributes", ctx, "us-east-1",
|
||||
ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
/** A new topic is checked on the ARN its name gives, and a tag call on the topic its ResourceArn names. */
|
||||
@Test
|
||||
void snsChecksANewTopicOnItsNameAndATagCallOnItsResourceArn() {
|
||||
setJsonBody("{\"Name\":\"alerts\"}");
|
||||
assertEquals(List.of("arn:aws:sns:us-east-1:000000000000:alerts"),
|
||||
builder.buildResources("sns", "sns:CreateTopic", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
setJsonBody("{\"ResourceArn\":\"arn:aws:sns:us-east-1:000000000000:alerts\",\"Tags\":[]}");
|
||||
assertEquals(List.of("arn:aws:sns:us-east-1:000000000000:alerts"),
|
||||
builder.buildResources("sns", "sns:TagResource", ctx, "us-east-1", ACCOUNT, "aws"));
|
||||
}
|
||||
|
||||
// ── S3 ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user