SQS queue policy specifies Action '*'

Restrict blanket SQS queue permissions to required message operations and approved principals.

Description

A send-only producer needs the sqs:SendMessage action on the queue. Giving it Action: "*" can also permit it to read or delete messages. A queue encrypted with a customer managed KMS key also requires the producer to have key permissions.

Potential impact

A producer with receive access can read message bodies. Delete access can remove messages before processing. Cross-account queue policies can grant DeleteMessage, but SQS reserves DeleteQueue and SetQueueAttributes for the owning account.

Remediation

Name the approved role in Principal and the queue ARN in Resource. Grant the consumer its own receive and delete actions as needed. Review conditions, IAM permissions and explicit denies, then test permitted and denied operations for each role. In community.aws 1.5.0, omitting policy leaves an existing queue policy in place.

Examples

Supply the queue name, owning account, Region and existing producer role ARN. A role in another account also needs an IAM policy that allows the operation.

Before

yaml
- name: SQS queue with broad policy
  community.aws.sqs_queue:
    name: "{{ queue_name }}"
    region: "{{ aws_region }}"
    policy:
      Version: "2012-10-17"
      Statement:
        - Effect: Allow
          Principal:
            AWS: "{{ producer_role_arn }}"
          Action: "*"
          Resource: "arn:aws:sqs:{{ aws_region }}:{{ aws_account_id }}:{{ queue_name }}"
    state: present

After

yaml
- name: SQS queue with limited policy
  community.aws.sqs_queue:
    name: "{{ queue_name }}"
    region: "{{ aws_region }}"
    policy:
      Version: "2012-10-17"
      Statement:
        - Effect: Allow
          Principal:
            AWS: "{{ producer_role_arn }}"
          Action: sqs:SendMessage
          Resource: "arn:aws:sqs:{{ aws_region }}:{{ aws_account_id }}:{{ queue_name }}"
    state: present

References