Other Articles

SNS Topic – Restrict Topic Policy Access

Secure Configuration Checks > AWS

This check ensures that no Amazon SNS topic policy gives access to everyone. A wildcard principal is allowed only when a condition limits who can call the topic.

Check Details

  • Resource: SNS Topic
  • Check: Restrict SNS topic policy access (NotPublic)
  • Risk: Anyone on the internet can publish to the topic or subscribe to its messages.

Example of a restricted policy

The first statement lets one AWS service publish from one source in your account. The second statement lets one other account subscribe.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowS3BucketToPublish",
      "Effect": "Allow",
      "Principal": {"Service": "s3.amazonaws.com"},
      "Action": "SNS:Publish",
      "Resource": "arn:aws:sns:<region>:<account-id>:<topic-name>",
      "Condition": {
        "ArnLike": {"aws:SourceArn": "arn:aws:s3:::<bucket-name>"},
        "StringEquals": {"aws:SourceAccount": "<account-id>"}
      }
    },
    {
      "Sid": "AllowPartnerAccountToSubscribe",
      "Effect": "Allow",
      "Principal": {"AWS": "arn:aws:iam::<partner-account-id>:root"},
      "Action": "SNS:Subscribe",
      "Resource": "arn:aws:sns:<region>:<account-id>:<topic-name>"
    }
  ]
}

Remediation via AWS Console

  1. Log in to the AWS Management Console and open the Amazon SNS console.

    Amazon SNS Console
  2. In the left navigation pane, click Topics and select the affected topic.
  3. Open the Access policy tab. Look for an Allow statement with "Principal": "*" or "AWS": "*" and no limiting condition.

    SNS Access policy tab
  4. Click Edit. In the Access policy editor, replace the wildcard with a named principal, or add a limiting condition.

    Edit SNS access policy
  5. Click Save changes.
  6. Repeat steps 2 to 5 for every affected topic.

Remediation via AWS CLI

  1. Log in to the AWS Management Console and click the CloudShell icon (>_) in the top-right corner.

    AWS CloudShell
  2. List the topics that have a wildcard principal without a limiting condition:

    for ARN in $(aws sns list-topics \
      --query 'Topics[].TopicArn' --output text); do
      aws sns get-topic-attributes \
        --topic-arn "$ARN" \
        --query 'Attributes.Policy' --output text | \
      jq -r --arg arn "$ARN" '
        [.Statement] | flatten | .[]
        | select(.Effect == "Allow")
        | select(
            (.Principal
              | if type == "string" then [.]
                else ([.AWS] | flatten) end)
            | index("*") != null)
        | select(
            [(.Condition // {}) | to_entries[].value | keys[] | ascii_downcase]
            | any(IN("aws:sourceowner", "aws:sourceaccount",
                     "aws:sourcearn", "aws:sourceip"))
            | not)
        | $arn'
    done
    

    The command flags the clear cases. Review each policy by hand, because it cannot judge the condition values.

  3. Download the policy of an affected topic:

    aws sns get-topic-attributes \
    --topic-arn <topic-arn> \
    --query 'Attributes.Policy' \
    --output text | jq . > policy.json
    

    Edit policy.json with nano policy.json. Replace the wildcard principal or add a condition.

  4. Apply the updated policy:

    aws sns set-topic-attributes \
    --topic-arn <topic-arn> \
    --attribute-name Policy \
    --attribute-value file://policy.json
    
  5. Verify the policy on the topic:

    aws sns get-topic-attributes \
    --topic-arn <topic-arn> \
    --query 'Attributes.Policy' \
    --output text | jq .
    

Replace <topic-arn> with the topic ARN, for example arn:aws:sns:us-east-1:123456789012:my-topic. Run the step 2 command again. It should no longer list the topic.

Updated on 04 November, 2026