---
title: SQS queue should not be accessible over the public internet
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > SQS queue should not be accessible over the
  public internet
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# SQS queue should not be accessible over the public internet

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**Id:** `terraform-aws-sqs-queue-should-not-be-accessible-over-the-public-internet` 

**Provider:** AWS

**Platform:** Terraform

**Severity:** High

**Category:** Access Control

#### Learn More{% #learn-more %}

- [Provider Reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue#policy)

### Description{% #description %}

Grant SQS queue access only to the principals that need it. In the `policy` argument of `aws_sqs_queue` or `aws_sqs_queue_policy`, list specific principals in each `Allow` statement, such as an AWS account or IAM role ARN, instead of `"*"`.

If a statement must use a wildcard principal, for example to let an AWS service deliver messages, add a `Condition` that binds the caller or request source. Use a key such as `aws:SourceArn` with a value that names a specific resource or account.

A transport-only condition such as `aws:SecureTransport` does not limit who can call the queue.

Scoping principals this way prevents arbitrary AWS identities from performing the queue actions the policy allows.

```hcl
# Assumes an existing aws_sqs_queue.example resource.
resource "aws_sqs_queue_policy" "example" {
  queue_url = aws_sqs_queue.example.id

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect    = "Allow"
      Principal = { AWS = "arn:aws:iam::111122223333:role/app-producer" }
      Action    = "sqs:SendMessage"
      Resource  = aws_sqs_queue.example.arn
    }]
  })
}
```
