AWS SQS queue policy access needs review

Allow only the SQS access required by approved producers and consumers.

Description

Principal: "*" can apply an SQS queue policy to unintended senders. Check Action, Resource, conditions and explicit denies in other applicable policies. Server-side encryption rejects anonymous SendMessage and ReceiveMessage requests. Authenticated principals still need appropriately scoped permissions.

Potential impact

Unwanted messages can disrupt backend processing or increase costs. Excess read or delete access can expose messages or remove them before processing.

Remediation

Allow only the required actions on the destination queue ARN for each approved principal. For SNS delivery, use aws:SourceArn to restrict the source topic. Test that expected producer and consumer requests succeed and unapproved requests are denied.

Examples

Both examples attach a separate policy resource to the same queue to avoid an ARN self-reference. Supply the actual approved SNS topic resource omitted from the excerpt.

Before

hcl
resource "aws_sqs_queue" "app_queue" {
  name = "examplequeue"
}

resource "aws_sqs_queue_policy" "app_queue" {
  queue_url = aws_sqs_queue.app_queue.id
  policy = <<POLICY
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "sqs:SendMessage",
      "Resource": "${aws_sqs_queue.app_queue.arn}"
    }
  ]
}
POLICY
}

The first statement broadly grants sqs:SendMessage. Reading or deleting messages requires separate permissions.

After

hcl
resource "aws_sqs_queue" "app_queue" {
  name = "examplequeue"
}

resource "aws_sqs_queue_policy" "app_queue" {
  queue_url = aws_sqs_queue.app_queue.id
  policy = <<POLICY
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {"Service": "sns.amazonaws.com"},
      "Action": "sqs:SendMessage",
      "Resource": "${aws_sqs_queue.app_queue.arn}",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "${aws_sns_topic.notifications.arn}"
        }
      }
    }
  ]
}
POLICY
}

The revised statement permits sns.amazonaws.com to send from the specified topic. Use the appropriate regional service principal for cross-Region delivery involving an opt-in Region. Review other queue policy statements and relevant IAM and KMS permissions.

References