SNS topic policy has a wildcard or missing principal

Review SNS topic principals, permitted actions, and service-integration conditions to restrict unintended message publication.

Description

If an SNS topic policy has Principal: "*", review Action, Resource, conditions and other applicable policies together. Omitting Principal from an incomplete statement does not grant access to everyone.

Potential impact

Unnecessary sns:Publish access can send unwanted messages to subscribers, trigger automation or raise false alerts. An incorrect condition can also block a required integration.

Remediation

  • Name the required accounts, roles or services in Principal. Limit actions to the required operations on the target topic ARN.
  • aws:ResourceAccount identifies the target resource’s owner. In supported service-to-service requests, aws:SourceAccount identifies the source resource’s owner. It cannot identify an ordinary IAM caller’s account.
  • Check the operators and values for the aws:SourceArn or aws:SourceAccount conditions your service supports. Avoid the deprecated aws:SourceOwner in new integrations, then test publishing and delivery.

Examples

The first excerpt has an unsupported Version: "2022-05-02", an unprefixed Publish action and no Resource. For deployment, use 2012-10-17, sns:Publish and the actual topic ARN.

Before

yaml
- name: Create alarm SNS topic community
  community.aws.sns_topic:
    name: "alarms"
    state: present
    display_name: "alarm SNS topic"
    policy:
      Version: "2022-05-02"
      Statement:
        - Action: Publish
          Effect: Allow
          Principal:
            AWS: "*"

After

yaml
- name: Create SNS topic with safe policy
  community.aws.sns_topic:
    name: secure-topic
    display_name: "Secure SNS Topic"
    state: present
    policy:
      Id: secure-topic-policy
      Version: "2012-10-17"
      Statement:
        - Sid: AllowPublishFromSpecificAccount
          Effect: Allow
          Resource: "arn:aws:sns:*:*:secure-topic"
          Principal: "*"
          Action: sns:Publish
          Condition:
            StringEquals:
              aws:SourceAccount: "123456789012"

The second excerpt still uses Principal: "*". Specify the intended service principal and set aws:SourceAccount to the source resource owner’s account. Replace the Region and account wildcards in the topic ARN with the actual values.

References