Skip to main content

SKY-D403 · Deployment and infrastructure

Terraform S3 bucket policy grants access to everyone

High

A bucket policy is a JSON document that says who may do what with an S3 bucket. SKY-D403 reports a Terraform bucket policy with an Allow statement for the principal * (anyone, signed in or not) and no conditions.

Languages
Terraform
Quality gate
counted toward the gate limits (full and diff scans). Reported under security (danger). It counts toward max_high and max_security; the rule never reports CRITICAL.
Finding type
review
Catalog name
Terraform AWS public S3 bucket policy
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Every object the statement covers can be read, or with write actions overwritten or deleted, by anyone on the internet. A policy copied from a static-website tutorial is a common way private files end up public.

What Skylos flags

main.tf · TerraformReported on line 1
resource "aws_s3_bucket_policy" "downloads" {  bucket = "shop-downloads"  policy = jsonencode({    Version = "2012-10-17"    Statement = [{      Effect    = "Allow"      Principal = "*"      Action    = "s3:GetObject"      Resource  = "arn:aws:s3:::shop-downloads/*"    }]  })}

What Skylos leaves alone

main.tf · Terraform
resource "aws_s3_bucket_policy" "downloads" {  bucket = "shop-downloads"  policy = jsonencode({    Version = "2012-10-17"    Statement = [{      Effect    = "Allow"      Principal = { AWS = "arn:aws:iam::123456789012:role/reporting" }      Action    = "s3:GetObject"      Resource  = "arn:aws:s3:::shop-downloads/*"    }]  })}

Why Skylos leaves it alone

The same read grant goes to one IAM role in your own account, not to everyone. Account IDs, role and user ARNs, and AWS service principals are not public.

How Skylos decides

  1. Runs with --danger (or -a). Reads .tf and .tf.json files, skipping .terraform, .git, node_modules, vendor, build, dist and virtual-environment folders, and parses them as HCL without running Terraform or contacting AWS.
  2. Resolves only literal values and local values of the same module. Input variables, data sources, attributes of other resources and module outputs stay unknown, and an unknown value never produces a finding.
  3. Skips a resource with count = 0 or an empty for_each, and needs the official AWS provider (hashicorp/aws, which an aws_ resource uses unless another provider is configured).
  4. Checks aws_s3_bucket_policy. The policy must be a literal: a JSON string or a jsonencode({...}) of literal values. A policy built from a data source or a variable is not judged.
  5. Reports an Allow statement whose principal is * or { AWS = "*" }, whose actions are S3 actions such as s3:GetObject, s3:PutObject, s3:* or *, and whose resources are * or this bucket.
  6. A statement with a Condition, a Deny, a NotPrincipal or another unsupported key makes the whole policy not judged.
  7. Does not report when a public access block for the same bucket sets block_public_policy or restrict_public_buckets.
  8. Reports HIGH on the resource line.

How to fix it

Grant access to the roles or services that need it. For public downloads, serve the bucket through CloudFront with origin access control and keep the bucket itself private.

main.tf · Terraform · the fix, against the flagged file
resource "aws_s3_bucket_policy" "downloads" {  bucket = "shop-downloads"  policy = jsonencode({    Version = "2012-10-17"    Statement = [{      Effect    = "Allow"Removed:       Principal = "*"Added:       Principal = { AWS = "arn:aws:iam::123456789012:role/reporting" }      Action    = "s3:GetObject"      Resource  = "arn:aws:s3:::shop-downloads/*"    }]  })}

When it can be wrong

  • A public statement with any Condition, even a weak one, is not reported, because Skylos does not evaluate conditions.
  • Values that come from variables, modules or other resources are not checked, because Skylos does not run Terraform: cidr_blocks = var.admin_cidrs is not reported even when its default is 0.0.0.0/0.
  • It judges the declaration only. It does not know what is deployed, and other settings (account defaults, security groups, routing) can make the real exposure smaller or larger.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Terraform rules read no inline marker: # skylos: ignore[SKY-D403] on the resource line does not hide the finding.

  • [tool.skylos] ignore = ["SKY-D403"] turns the rule off for the project.

  • A baseline (skylos baseline ., then --baseline) accepts the declarations that exist today and reports new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.