For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/ansible-aws-sqs-policy-with-public-access.md.
A documentation index is available at /llms.txt.
SQS queue policies must not grant Allow permissions to a wildcard principal (*) combined with wildcard actions, as this gives any principal unrestricted ability to send, receive, delete, or otherwise manipulate queue messages, risking data exposure, message loss, or unauthorized message injection. In Ansible tasks using the community.aws.sqs_queue or sqs_queue module, inspect the policy property for policy statements where Effect is "Allow", Principal is "*" (either Principal == "*" or Principal.AWS contains "*"), and Action contains "*". Such statements are flagged.
Define explicit principals (AWS account ARNs, IAM role/user ARNs, or service principals) and restrict Action to the minimal SQS actions required (for example, sqs:SendMessage, sqs:ReceiveMessage). You can optionally add conditions (source ARN/IP, VPC) to further limit access.
Secure configuration example:
- name:Create SQS queue with restricted policycommunity.aws.sqs_queue:name:my-queuepolicy:Version:"2012-10-17"Statement:- Sid:AllowSpecificAccountEffect:AllowPrincipal:AWS:"arn:aws:iam::123456789012:root"Action:- "sqs:SendMessage"- "sqs:ReceiveMessage"Resource:"arn:aws:sqs:us-east-1:123456789012:my-queue"
Compliant Code Examples
- name:First SQS queue with policycommunity.aws.sqs_queue:name:my-queue1region:ap-southeast-1default_visibility_timeout:120message_retention_period:86400maximum_message_size:1024delivery_delay:30receive_message_wait_time:20policy:Version:'2012-10-17'Statement:- Effect:AllowAction:sqs:*Resource:'*'Principal:Principalmake_default:falsestate:present
Non-Compliant Code Examples
- name:First SQS queue with policycommunity.aws.sqs_queue:name:my-queue1region:ap-southeast-1default_visibility_timeout:120message_retention_period:86400maximum_message_size:1024delivery_delay:30receive_message_wait_time:20policy:Version:"2012-10-17"Statement:- Effect:"Allow"Action:"sqs:*"Resource:"*"Principal:"*"make_default:falsestate:present- name:Second SQS queue with policycommunity.aws.sqs_queue:name:my-queue2region:ap-southeast-3default_visibility_timeout:120message_retention_period:86400maximum_message_size:1024delivery_delay:30receive_message_wait_time:20policy:Version:"2012-10-17"Statement:- Effect:"Allow"Action:"*"Resource:"*"Principal:AWS:"*"make_default:falsestate:present
1
2
rulesets:- Ansible / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.