Stop 06 · Storage: S3, EBS & EFSTopics · 4/10

S3 Bucket Policies & Block Public Access

Part of the AWS Roadmap

In short

"Company leaks lakhs of customer records from an open S3 bucket" has been a headline far too often. Bucket policies decide who can touch your data, and Block Public Access is the safety catch that stops one bad line from making it public.

Bucket policies are resource-based JSON policies that control access to a bucket and its objects. Block Public Access settings act as a safety net that overrides any policy or ACL trying to make data public, and they are turned on by default for new buckets.

The jaadu snaps a heavy padlock onto a warehouse gate while a rules board hangs beside the doorway behind it.

Think of it like this

Godown rules and the main gate lock

A godown has a board at the door listing who may take what (bucket policy). The owner also fits a padlock on the main gate that stays shut no matter what the board says (Block Public Access). Even if someone writes 'everyone welcome' on the board, the padlock wins.

Watch it happen

Can this request read the object?

Request
Block Public Access
Any Deny?
Bucket or IAM Allow?
Result

1/5An anonymous visitor asks for s3://acme-reports/q3.pdf.

The big ideas

What you need to know

Resource-based policy

A bucket policy is attached to the bucket and has a Principal: who the statement applies to.

Four BPA settings

Block and ignore public ACLs, block and restrict public policies. All four are on by default for new buckets.

ACLs are off by default

New buckets use Bucket owner enforced object ownership, which disables ACLs. Control access with policies instead.

Enforce HTTPS

A Deny with aws:SecureTransport false blocks any request that doesn't use TLS.

See it in code

Walk through the code

json
1{2  "Version": "2012-10-17",3  "Statement": [4    {5      "Sid": "DenyInsecureTransport",6      "Effect": "Deny",7      "Principal": "*",8      "Action": "s3:*",9      "Resource": ["arn:aws:s3:::acme-reports", "arn:aws:s3:::acme-reports/*"],10      "Condition": { "Bool": { "aws:SecureTransport": "false" } }11    },12    {13      "Sid": "AllowPartnerRoleRead",14      "Effect": "Allow",15      "Principal": { "AWS": "arn:aws:iam::444455556666:role/partner-reader" },16      "Action": "s3:GetObject",17      "Resource": "arn:aws:s3:::acme-reports/shared/*"18    }19  ]20}

1/3Anyone using plain HTTP is denied for every action on the bucket and its objects.

Apply with aws s3api put-bucket-policy --bucket acme-reports --policy file://policy.json. Block Public Access stays fully on.

Save yourself the pain

Common mistakes

Oops

Turning off Block Public Access at the account level to share one file.

Do this instead

Share with a presigned URL or CloudFront. Keep BPA on, ideally at the account level too.

Oops

Writing a policy with Principal "*" and Allow s3:GetObject on the whole bucket.

Do this instead

That makes every object public. Name specific principals and prefixes.

Your mission

Lock a bucket properly

~25 min

Quick check

A bucket policy grants s3:GetObject to Principal "*", but Block Public Access is fully enabled. What happens when an anonymous user requests an object?

Go deeper

  1. 1Write a bucket policy that allows one IAM role to read objects and nothing else.
  2. 2Try to make an object public with Block Public Access on and see it fail.
  3. 3Learn why object ACLs are disabled by default for new buckets and policies are preferred.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge