SQS queue policy uses Principal '*'

Restrict a wildcard SQS queue principal to required accounts, roles or services and appropriate source conditions.

Description

When an SQS queue policy uses Principal: "*", check Action, Resource, conditions and other policies to see which operations are allowed. Sending alone grants no read, delete or queue-administration access.

Potential impact

Unwanted messages can affect consumer processing. If reading or deletion is also allowed, messages may be disclosed or removed before processing. The impact depends on how the consumer validates messages.

Remediation

  • Set Principal to the required account, role or service, Action to the needed operations and Resource to the queue ARN. Check other policies for conditions and denies.
  • Keep server-side encryption (SSE) enabled. Encrypted queues require HTTPS and Signature Version 4 and reject anonymous SendMessage and ReceiveMessage. Restrict authenticated senders and check the service’s required KMS permissions.

Examples

Set queue_arn to the ARN of my-queue in the target account and Region, and sns_topic_arn to the approved source topic. Create the SNS subscription separately.

Before

yaml
- name: example
  community.aws.sqs_queue:
    name: my-queue
    region: ap-southeast-2
    policy:
      Version: "2012-10-17"
      Statement:
        Sid: First
        Effect: Allow
        Principal: "*"
        Action: sqs:SendMessage
        Resource: "{{ queue_arn }}"

The first statement grants sqs:SendMessage to wildcard principals.

After

yaml
- name: example
  community.aws.sqs_queue:
    name: my-queue
    region: ap-southeast-2
    policy:
      Version: "2012-10-17"
      Statement:
        Sid: First
        Effect: Allow
        Principal:
          Service: sns.amazonaws.com
        Action: sqs:SendMessage
        Resource: "{{ queue_arn }}"
        Condition:
          ArnEquals:
            aws:SourceArn: "{{ sns_topic_arn }}"

The revised statement grants sending to sns.amazonaws.com only when aws:SourceArn matches the approved topic. For cross-Region delivery involving an opt-in Region, use the appropriate regional service principal. Test delivery from the approved topic and rejection from other sources.

References