Review S3 public bucket policy blocking

Manage blocking settings to prevent unintended public bucket policies.

Description

block_public_policy rejects attempts to save a bucket policy that S3 considers public. Enabling it leaves existing policies in effect, subject to other access controls.

Potential impact

A public read grant can expose objects such as backups or internal documents. Check the policy’s actions and resources to see what it allows.

Remediation

Enable block_public_policy = true on private buckets. Apply it at the account level if none of the account’s buckets should accept public policies. Review existing policies, remove unwanted grants and check the other Block Public Access options. Limit any intentional public access to the required actions and objects.

Examples

Use your account ID and supply the referenced bucket in that account. The examples set all four bucket options to false. Omitted account options also default to false in Terraform. Keep every required block enabled in the plan.

Before

hcl
resource "aws_s3_account_public_access_block" "example" {
  account_id = 250924516109
}

resource "aws_s3_bucket_public_access_block" "example" {
  bucket                  = aws_s3_bucket.public_bucket.id
  block_public_acls       = false
  block_public_policy     = false
  ignore_public_acls      = false
  restrict_public_buckets = false
}

After

hcl
resource "aws_s3_account_public_access_block" "example" {
  account_id           = 250924516109
  block_public_policy  = true
}

resource "aws_s3_bucket_public_access_block" "example" {
  bucket                  = aws_s3_bucket.public_bucket.id
  block_public_acls       = false
  block_public_policy     = false
  ignore_public_acls      = false
  restrict_public_buckets = false
}

The second example enables the account-wide block. The bucket’s block_public_policy = false cannot override it.

References