SNS topic policies must not allow any principal (*). Making a topic public permits unauthorized publishing or subscription, which can lead to message injection, data exfiltration, or unintended triggering of downstream systems.
In Ansible tasks using the community.aws.sns_topic or sns_topic modules, check the policy property and flag any Statement with "Effect": "Allow" where Principal is the wildcard ("*") or contains "AWS": "*", unless the statement includes a Condition that genuinely scopes the caller to a specific identity or resource — such as aws:SourceArn, aws:SourceAccount, or aws:PrincipalOrgID. Conditions that only restrict how a call is made (e.g. aws:SecureTransport) or check key presence (e.g. Null) are not considered scoping and are still flagged.
Secure configuration example for an Ansible task (explicit principal):
- name:create sns topic with restricted policycommunity.aws.sns_topic:name:my-topicpolicy:Version:"2012-10-17"Statement:- Sid:AllowSpecificAccountEffect:AllowPrincipal:AWS:"arn:aws:iam::123456789012:root"Action:"SNS:Publish"Resource:"arn:aws:sns:us-east-1:123456789012:my-topic"
Compliant Code Examples
- name:Create alarm SNS topic communitycommunity.aws.sns_topic:name:alarmsstate:presentdisplay_name:alarm SNS topicdelivery_policy:http:defaultHealthyRetryPolicy:minDelayTarget:2maxDelayTarget:4numRetries:3numMaxDelayRetries:5backoffFunction:<linear|arithmetic|geometric|exponential>disableSubscriptionOverrides:truedefaultThrottlePolicy:maxReceivesPerSecond:10policy:Version:'2022-05-02'Statement:- Effect:AllowAction:PublishPrincipal:NotAll- name:Create alarm SNS topicsns_topic:name:alarmsstate:presentdisplay_name:alarm SNS topicdelivery_policy:http:defaultHealthyRetryPolicy:minDelayTarget:2maxDelayTarget:4numRetries:3numMaxDelayRetries:5backoffFunction:<linear|arithmetic|geometric|exponential>disableSubscriptionOverrides:truedefaultThrottlePolicy:maxReceivesPerSecond:10policy:Version:'2022-05-02'Statement:- Effect:AllowAction:PublishPrincipal:NotAll# Principal "*" but limited to account ID via Condition - should NOT be flagged (is_access_limited_to_an_account_id)- name:SNS topic with star principal but aws:SourceAccount conditioncommunity.aws.sns_topic:name:account-scoped-topicstate:presentpolicy:Version:'2012-10-17'Statement:- Effect:AllowAction:sns:PublishPrincipal:"*"Resource:"*"Condition:StringEquals:aws:SourceAccount:"123456789012"