The S3 Public Access Block feature provides a set of controls that let you centrally manage public access to S3 buckets. The module enables all four block settings by default, following the AWS security best practice of keeping buckets private unless explicitly required otherwise.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/terraform-aws-modules/terraform-aws-s3-bucket/llms.txt
Use this file to discover all available pages before exploring further.
How it works
Theaws_s3_bucket_public_access_block resource is created whenever attach_public_policy = true (the default). It applies four independent access block settings to the bucket:
Variables
block_public_acls
Default:
trueBlocks any PutBucketAcl or PutObjectAcl calls that would grant public access. Also blocks new object uploads made with a public ACL.block_public_policy
Default:
truePrevents new bucket policies from being applied if they would grant public access to the bucket or its objects.ignore_public_acls
Default:
trueCauses S3 to ignore all public ACLs on the bucket and its objects. Existing public ACLs are not removed but their grants are not honored.restrict_public_buckets
Default:
trueRestricts access to the bucket and its objects to only AWS service principals and authorized users within the bucket owner’s account. Cross-account access requires explicit identity-based policies.Lifecycle and attachment variables
| Variable | Default | Description |
|---|---|---|
attach_public_policy | true | Whether to create and attach the aws_s3_bucket_public_access_block resource. Set to false to let upstream infrastructure manage the block settings. |
skip_destroy_public_access_block | true | When true, Terraform will not destroy the Public Access Block configuration during terraform destroy. This prevents accidental public exposure during teardown. |
Object Ownership
The module also supports controlling S3 Object Ownership, which interacts closely with ACL-based access:| Variable | Default | Description |
|---|---|---|
control_object_ownership | false | Whether to manage aws_s3_bucket_ownership_controls on the bucket. |
object_ownership | "BucketOwnerEnforced" | Valid values: BucketOwnerEnforced, BucketOwnerPreferred, ObjectWriter. |
BucketOwnerEnforced, ACLs are completely disabled — the bucket owner automatically owns and has full control over every object. This is the recommended setting for most use cases.
Examples
Account-level public access
Theblock_public_acls, block_public_policy, ignore_public_acls, and restrict_public_buckets variables control settings at the bucket level. AWS also supports configuring these same four settings at the account level, which acts as a guard rail across all buckets in the account.
Use the account-public-access submodule to manage account-level Public Access Block settings:
Account-level block settings override bucket-level settings. If the account-level
block_public_policy is true, no bucket policy in the account can grant public access regardless of the bucket-level setting.
