S3 bucket policy grants Get permissions to all principals

Limit S3 Get permissions to required principals and resources, and verify the actual public-access scope.

Description

A wildcard read grant can include anonymous requests. Check which action it allows. s3:GetObject reads object contents, while s3:GetBucketLocation returns the bucket’s Region. Changing or deleting data requires separate permissions.

Potential impact

A public object read can expose logs, backups or deployment files. Configuration reads can disclose details about the bucket.

Remediation

  • Remove unnecessary public grants. For private reads, name the accounts, roles or services that need access and limit the actions, resource ARNs and conditions. For public files, grant only the reads those objects need.
  • Check other policies, explicit denies, Block Public Access and any required KMS permissions. Test both intended and unwanted reads. If data was exposed, identify the affected objects and review access records.

Examples

Use your bucket name and role ARN, and check the bucket’s public-access settings.

Before

hcl
resource "aws_s3_bucket" "data_bucket" {
  bucket = "my-tf-test-bucket"
}

resource "aws_s3_bucket_policy" "data_bucket_policy" {
  bucket = aws_s3_bucket.data_bucket.id

  policy = <<POLICY
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-tf-test-bucket/*"
    }
  ]
}
POLICY
}

The wildcard grants s3:GetObject on every object in this bucket, subject to the other access controls.

After

hcl
resource "aws_s3_bucket" "data_bucket" {
  bucket = "my-tf-test-bucket"
}

resource "aws_s3_bucket_policy" "data_bucket_policy" {
  bucket = aws_s3_bucket.data_bucket.id

  policy = <<POLICY
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:role/app-reader"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-tf-test-bucket/*"
    }
  ]
}
POLICY
}

The grant now names only app-reader. Check who can assume that role and whether another policy still grants public access.

References