Description
aws:SourceIp limits where a request comes from. With Principal: "*", other callers sharing an allowed address can also qualify. Encrypted queues reject anonymous SendMessage and ReceiveMessage requests.
Potential impact
A caller on the allowed path with effective send, receive or delete access could add work, read messages or delete them before processing.
Remediation
Specify the approved role in Principal and replace sqs:* with the actions it needs. For the public endpoint, use the approved external source range. For a VPC endpoint, use a condition such as aws:SourceVpce. Review IAM and queue policies and any required KMS permissions, then test permitted and denied requests.
Examples
The second policy keeps the same IP condition and narrows only the principal to the queue-client role. Define aws_sqs_queue.q separately and replace the role ARN and documentation range 203.0.113.0/24 with actual values.
Before
resource "aws_sqs_queue_policy" "example" {
queue_url = aws_sqs_queue.q.id
policy = <<EOF
{
"Version": "2012-10-17",
"Id": "Queue1_Policy_UUID",
"Statement": [{
"Sid":"Queue1_AnonymousAccess_AllActions_AllowlistIP",
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:*",
"Resource": "${aws_sqs_queue.q.arn}",
"Condition" : {
"IpAddress" : {
"aws:SourceIp":"203.0.113.0/24"
}
}
}]
}
EOF
}
After
resource "aws_sqs_queue_policy" "example" {
queue_url = aws_sqs_queue.q.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "Queue1_Policy_UUID",
"Statement": [{
"Sid":"Queue1_AnonymousAccess_AllActions_AllowlistIP",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:role/queue-client"},
"Action": "sqs:*",
"Resource": "${aws_sqs_queue.q.arn}",
"Condition" : {
"IpAddress" : {
"aws:SourceIp":"203.0.113.0/24"
}
}
}]
}
POLICY
}