Description
When an SNS topic policy uses a wildcard Principal, check Action, Resource, conditions and other applicable policies. Review publishing, subscription and administration separately.
Potential impact
Unintended publishers can trigger false alerts or automation. Excess subscription or administration permissions can also change who receives messages or how the topic operates.
Remediation
- Grant each publisher and operator only the actions and topic ARNs they need. An account’s
:rootARN delegates authority to that account. Its administrators can grant the permission to identities within it. - For supported service-to-service requests,
aws:SourceAccountidentifies the source resource’s owner.aws:ResourceAccountidentifies the target resource’s owner. Use a separate principal restriction for ordinary callers. - If using a module, check how that version selects and merges policies. Test that the resulting policy accepts required requests and denies unapproved ones.
Examples
Supply topic_name and the actual publishing role ARN in publisher_role_arn. For an existing topic, review the Terraform state and plan. Manage the policy in one place, either inline or with a separate policy resource.
Before
resource "aws_sns_topic" "public_topic" {
name = var.topic_name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": "*",
"Principal": {
"AWS": "*"
},
"Resource": "*"
}
]
}
EOF
}
The first statement sets the principal, actions and resources to *. Its effective scope still depends on the operations SNS supports and other applicable policies.
After
resource "aws_sns_topic" "public_topic" {
name = var.topic_name
}
resource "aws_sns_topic_policy" "restricted_policy" {
arn = aws_sns_topic.public_topic.arn
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Sid = "AllowApprovedPublisher"
Effect = "Allow"
Principal = { AWS = var.publisher_role_arn }
Action = "sns:Publish"
Resource = aws_sns_topic.public_topic.arn
}]
})
}
The revised statement grants the specified role only sns:Publish on this topic. Configure and test any subscription or administration permissions separately.