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:
Priamo Germosen authored and GitHub committed 2026-10-26 19:16:56 -05:00
1 parent 0a47ddd5e4
commit 7c0ee92480
6 files changed
+86 -37

No files matched your search

@@ -10,8 +10,8 @@ import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.services.iam.IamClient;
import software.amazon.awssdk.services.iam.model.AccessKey;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.AuthorizationErrorException;
import software.amazon.awssdk.services.sns.model.PublishBatchResultEntry;
import software.amazon.awssdk.services.sns.model.SnsException;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.SendMessageBatchResultEntry;
import software.amazon.awssdk.services.sqs.model.SqsException;
@@ -125,13 +125,16 @@ class IamAuthorizedActionTest {
}
@Test
@DisplayName("a policy naming PublishBatch, which is no IAM action, grants nothing")
@DisplayName("a policy naming PublishBatch, which is no IAM action, grants nothing, refused as SNS's AuthorizationError")
void aPolicyNamingPublishBatchGrantsNothing() {
allow("sns:PublishBatch");
assertThatThrownBy(() -> sns.publishBatch(r -> r.topicArn(topicArn)
.publishBatchRequestEntries(e -> e.id("one").message("hello"))))
.isInstanceOfSatisfying(SnsException.class, error -> assertThat(error.statusCode()).isEqualTo(403));
.isInstanceOfSatisfying(AuthorizationErrorException.class, error -> {
assertThat(error.statusCode()).isEqualTo(403);
assertThat(error.awsErrorDetails().errorCode()).isEqualTo("AuthorizationError");
});
}
private void allow(String action) {