SQS queue policy grants broad actions

Allow only the message operations and producers or consumers that are needed.

Description

Grant producers sqs:SendMessage and give consumers only the receive or delete actions they need. Encrypted queues reject anonymous SendMessage and ReceiveMessage requests, but a wildcard principal can still include unintended authenticated callers.

Potential impact

Unwanted messages can trigger downstream work. Excess receive or delete access can disclose messages or remove them before processing.

Remediation

Limit Principal to approved callers. For SNS, specify sns.amazonaws.com and restrict aws:SourceArn to the actual topic ARN. Keep queue encryption and required KMS permissions in place. Test the intended message flow and denial of unapproved operations.

Examples

The second policy narrows only Action to sqs:SendMessage on the same queue. It keeps Principal: "*", so restrict the producer before deploying.

Before

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

resource "aws_sqs_queue_policy" "app_queue_policy" {
  queue_url = aws_sqs_queue.app_queue.id

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

After

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

resource "aws_sqs_queue_policy" "app_queue_policy" {
  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
}

References