Description
restrict_public_buckets limits access to a bucket with a public policy to authorized principals in its owner’s account and AWS service principals. It also blocks a named external account covered by that public policy.
Potential impact
The policy’s actions determine whether an unintended user can read or change objects. A restriction can also interrupt legitimate cross-account access.
Remediation
Set restrict_public_buckets = true at the bucket or account scope that needs protection. For required cross-account access, remove public grants and name only the necessary principals, actions and resources. Test the integration. Check ACLs and the other blocks, including block_public_policy for new public policies.
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
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
resource "aws_s3_account_public_access_block" "example" {
account_id = 250924516109
restrict_public_buckets = 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 restricts buckets with public policies across the account. The bucket’s restrict_public_buckets = false cannot relax this account setting.