For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/ansible-aws-sns-topic-is-publicly-accessible.md.
A documentation index is available at /llms.txt.
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": "*". Policy statements must instead specify explicit principals such as AWS account IDs, ARNs, or service principals. Statements that use a wildcard principal or are not limited to a specific account ID are 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"