mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): refuse SNS requests with AuthorizationError (#6621)
Under IAM enforcement a refused SNS request answered `AccessDenied`, the
code Floci gives every Query service. SNS models no such error. Every
one of its 42 operations lists `AuthorizationError`, HTTP 403, a sender
fault ("Indicates that the user has been denied access to the requested
resource"), which SDKs raise as `AuthorizationErrorException`; the SNS
Developer Guide's own sample reads that code as an IAM permission
failure ("Authorization error listing topics - check IAM permissions").
An SDK caller catching `AuthorizationErrorException` therefore missed
Floci's refusal, which surfaced as a bare `SnsException`.
A Query denial now takes its code from the service that serves the
request: `AuthorizationError` for SNS, whichever action is denied (a
role it is passed as much as its own action), and `AccessDenied` for
every other Query service, as before. The status, the `Sender` type and
the message are unchanged.
Not in this change: Floci's SNS JSON surface (`SNS_20100331.*`
targets), which botocore does not model, keeps `AccessDeniedException`.
This commit is contained in:
1 parent
0a47ddd5e4
commit
7c0ee92480
6 files changed
+86
-37
No files matched your search
@@ -2024,6 +2024,27 @@ class IamEnforcementFilterTest {
|
||||
assertTrue(body.contains("<RequestId>"), body);
|
||||
}
|
||||
|
||||
/**
|
||||
* SNS refuses with its own {@code AuthorizationError}, the 403 every SNS operation lists, whichever action is
|
||||
* denied (a role it is passed as well as its own); another Query service still answers {@code AccessDenied}.
|
||||
*/
|
||||
@Test
|
||||
void snsRefusesWithItsAuthorizationError() {
|
||||
for (String action : List.of("sns:Publish", "iam:PassRole")) {
|
||||
Response r = IamEnforcementFilter.accessDeniedResponse(
|
||||
action, "sns", MediaType.APPLICATION_FORM_URLENCODED_TYPE);
|
||||
|
||||
assertEquals(403, r.getStatus());
|
||||
String body = entityString(r);
|
||||
assertTrue(body.contains("<Code>AuthorizationError</Code>"), body);
|
||||
assertTrue(body.contains("<Type>Sender</Type>"), body);
|
||||
assertTrue(body.contains("User is not authorized to perform: " + action), body);
|
||||
}
|
||||
String sqs = entityString(IamEnforcementFilter.accessDeniedResponse(
|
||||
"sqs:SendMessage", "sqs", MediaType.APPLICATION_FORM_URLENCODED_TYPE));
|
||||
assertTrue(sqs.contains("<Code>AccessDenied</Code>"), sqs);
|
||||
}
|
||||
|
||||
@Test
|
||||
void s3GetsS3FlavoredXmlError() {
|
||||
// S3 — credential-scope is "s3"; S3 errors are <Error>... at the root, no <ErrorResponse> wrapper.
|
||||
|
||||
+39
-29
@@ -88,41 +88,27 @@ class IamAuthorizedActionEnforcementIntegrationTest {
|
||||
|
||||
@Test
|
||||
void aBatchPublishIsGrantedByPublish() {
|
||||
String topicArn = given()
|
||||
.header("Authorization", auth(ACCOUNT_ID, "sns"))
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateTopic")
|
||||
.formParam("Version", "2010-03-31")
|
||||
.formParam("Name", "authorized-" + UUID.randomUUID())
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("CreateTopicResponse.CreateTopicResult.TopicArn");
|
||||
cleanup.register(() -> given()
|
||||
.header("Authorization", auth(ACCOUNT_ID, "sns"))
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteTopic")
|
||||
.formParam("Version", "2010-03-31")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.when().post("/").then().statusCode(200));
|
||||
String topicArn = createTopic();
|
||||
String accessKeyId = userAllowed("sns:Publish");
|
||||
|
||||
given()
|
||||
.header("Authorization", auth(accessKeyId, "sns"))
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "PublishBatch")
|
||||
.formParam("Version", "2010-03-31")
|
||||
.formParam("TopicArn", topicArn)
|
||||
.formParam("PublishBatchRequestEntries.member.1.Id", "one")
|
||||
.formParam("PublishBatchRequestEntries.member.1.Message", "hello")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
snsQuery(accessKeyId, "PublishBatch", publishBatch(topicArn))
|
||||
.statusCode(200)
|
||||
.body("PublishBatchResponse.PublishBatchResult.Successful.member.Id", equalTo("one"));
|
||||
}
|
||||
|
||||
/** SNS refuses with its own {@code AuthorizationError}, the 403 every SNS operation lists. */
|
||||
@Test
|
||||
void aPolicyNamingTheBatchPublishGrantsNothingAndSnsRefusesWithAuthorizationError() {
|
||||
String topicArn = createTopic();
|
||||
String accessKeyId = userAllowed("sns:PublishBatch");
|
||||
|
||||
snsQuery(accessKeyId, "PublishBatch", publishBatch(topicArn))
|
||||
.statusCode(403)
|
||||
.body("ErrorResponse.Error.Code", equalTo("AuthorizationError"))
|
||||
.body("ErrorResponse.Error.Type", equalTo("Sender"))
|
||||
.body(containsString("sns:Publish"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTransactGetIsCheckedItemByItemAgainstEachLeadingKey() {
|
||||
// AWS checks TransactGetItems as dynamodb:GetItem, and Floci checks each Get that way with
|
||||
@@ -211,6 +197,20 @@ class IamAuthorizedActionEnforcementIntegrationTest {
|
||||
return queueUrl;
|
||||
}
|
||||
|
||||
private String createTopic() {
|
||||
String topicArn = snsQuery(ACCOUNT_ID, "CreateTopic", Map.of("Name", "authorized-" + UUID.randomUUID()))
|
||||
.statusCode(200)
|
||||
.extract().xmlPath().getString("CreateTopicResponse.CreateTopicResult.TopicArn");
|
||||
cleanup.register(() -> snsQuery(ACCOUNT_ID, "DeleteTopic", Map.of("TopicArn", topicArn))
|
||||
.statusCode(200));
|
||||
return topicArn;
|
||||
}
|
||||
|
||||
private static Map<String, String> publishBatch(String topicArn) {
|
||||
return Map.of("TopicArn", topicArn, "PublishBatchRequestEntries.member.1.Id", "one",
|
||||
"PublishBatchRequestEntries.member.1.Message", "hello");
|
||||
}
|
||||
|
||||
private String userAllowed(String action) {
|
||||
return userWithPolicy("""
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
@@ -259,6 +259,16 @@ class IamAuthorizedActionEnforcementIntegrationTest {
|
||||
.then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse snsQuery(String accessKeyId, String action, Map<String, String> params) {
|
||||
RequestSpecification spec = given()
|
||||
.header("Authorization", auth(accessKeyId, "sns"))
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2010-03-31");
|
||||
params.forEach(spec::formParam);
|
||||
return spec.when().post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse sqsQuery(String accessKeyId, String action, Map<String, String> params) {
|
||||
RequestSpecification spec = given()
|
||||
.header("Authorization", auth(accessKeyId, "sqs"))
|
||||
|
||||
Reference in new issue
Block a user