A security scanner says one of your buckets is public. Before you change anything, find out how it's public, because there are two separate ways in, and one switch that decides whether either works:
- the bucket policy: a statement with
"Principal": "*", - the ACL: a grant to the
AllUsers(anyone) orAuthenticatedUsers(anyone with any AWS account) group, - Block Public Access: four settings on the bucket (and on the account) that can override both.
Everything below was run on a BrokenCluster AWS lab: the real aws CLI against an AWS-style account. The bucket is shop-exports-amber, and an app reads it through the IAM role shop-reader.
1. Is Block Public Access on?
Start here, because it tells you whether the other two can matter at all:
$ aws s3api get-public-access-block --bucket shop-exports-amber
{
"PublicAccessBlockConfiguration": {
"BlockPublicAcls": false,
"IgnorePublicAcls": false,
"BlockPublicPolicy": false,
"RestrictPublicBuckets": false
}
}
All four are off: someone turned them off on purpose (new buckets have them on). Whatever the policy and the ACL grant to the public, works. The four settings come in pairs:
| Setting | What it does |
|---|---|
BlockPublicAcls | Rejects requests that add a public ACL. |
IgnorePublicAcls | Makes existing public ACLs have no effect. |
BlockPublicPolicy | Rejects a bucket policy that would make the bucket public. |
RestrictPublicBuckets | Makes an existing public policy work only for AWS services and your own account. |
The account can have the same four settings (aws s3control get-public-access-block --account-id <id>), and the stricter of the two levels wins.
2. Does the policy make it public?
S3 can judge the policy for you:
$ aws s3api get-bucket-policy-status --bucket shop-exports-amber
{
"PolicyStatus": {
"IsPublic": true
}
}
Then read the policy to find the statement responsible. The policy comes back as a JSON string, so pipe it through jq:
$ aws s3api get-bucket-policy --bucket shop-exports-amber --query Policy --output text | jq .
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AppReader",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:role/shop-reader"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::shop-exports-amber/*"
},
{
"Sid": "Sharing",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::shop-exports-amber/*"
}
]
}
AppReader is fine: it names one role. Sharing gives s3:GetObject to "Principal": "*", everyone, with no condition. Someone wanted to share a file once.
3. Does the ACL make it public?
$ aws s3api get-bucket-acl --bucket shop-exports-amber
{
"Owner": {
"DisplayName": "webfile",
"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
},
"Grants": [
{
"Grantee": {
"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a",
"Type": "CanonicalUser"
},
"Permission": "FULL_CONTROL"
},
{
"Grantee": {
"Type": "Group",
"URI": "http://acs.amazonaws.com/groups/global/AllUsers"
},
"Permission": "READ"
}
]
}
The second grant gives READ to AllUsers. On a bucket, READ means anyone can list it, so the file names are public too. This bucket is public twice over.
Objects have ACLs of their own (get-object-acl), so a single object can be public in a bucket whose ACL is clean.
4. Lock it down, in this order
The order matters: first make sure the readers you want keep working, then remove the public grants, then switch on the settings that stop them coming back.
Remove the public statement, keeping the app's. Write the policy you want to a file and replace the old one:
$ cat policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AppReader",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::123456789012:role/shop-reader" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::shop-exports-amber/*"
}
]
}
$ aws s3api put-bucket-policy --bucket shop-exports-amber --policy file://policy.json
Reset the ACL to the owner only:
$ aws s3api put-bucket-acl --bucket shop-exports-amber --acl private
Turn Block Public Access back on, all four:
$ aws s3api put-public-access-block --bucket shop-exports-amber \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
Check with the same commands as before:
$ aws s3api get-bucket-policy-status --bucket shop-exports-amber
{
"PolicyStatus": {
"IsPublic": false
}
}
$ aws s3api get-bucket-acl --bucket shop-exports-amber --query 'Grants[].[Grantee.Type,Grantee.URI,Permission]' --output text
CanonicalUser None FULL_CONTROL
From now on, on AWS, a put-bucket-policy with a public statement or a put-bucket-acl --acl public-read on this bucket fails with AccessDenied. That's the "even if someone adds one later" part: the next person who wants to share a file has to find a better way.
5. Turn ACLs off altogether
ACLs are a legacy way to grant access. Setting object ownership to bucket owner enforced disables them for the bucket and every object in it, so access is decided by policies alone:
$ aws s3api put-bucket-ownership-controls --bucket shop-exports-amber \
--ownership-controls 'Rules=[{ObjectOwnership=BucketOwnerEnforced}]'
$ aws s3api get-bucket-ownership-controls --bucket shop-exports-amber
{
"OwnershipControls": {
"Rules": [
{
"ObjectOwnership": "BucketOwnerEnforced"
}
]
}
}
This is the default for new buckets. On AWS it fails while the bucket ACL still grants access to anyone other than the owner, which is one more reason to reset the ACL first.
6. Prove the app still works
The point of keeping AppReader was that shop-reader can still read. Test as that role, not as yourself, because an administrator can read the bucket regardless:
$ creds=$(aws sts assume-role --role-arn arn:aws:iam::123456789012:role/shop-reader \
--role-session-name check --query Credentials --output json)
$ AWS_ACCESS_KEY_ID=$(jq -r .AccessKeyId <<<"$creds") \
AWS_SECRET_ACCESS_KEY=$(jq -r .SecretAccessKey <<<"$creds") \
AWS_SESSION_TOKEN=$(jq -r .SessionToken <<<"$creds") \
aws s3 cp s3://shop-exports-amber/monthly/2026-11.csv - | head -1
id,amount
Signed requests from your own account's roles and users are not "public", so Block Public Access never affects them.
If something really needs public files
Don't open the bucket again. Two better ways:
- A website or downloads: put CloudFront in front of the bucket with origin access control, and allow only that distribution in the bucket policy. The bucket stays private; CloudFront serves the files.
- Sharing one file for a while: a pre-signed URL gives time-limited access to one object without changing any permissions:
aws s3 presign s3://shop-exports-amber/monthly/2026-11.csv --expires-in 3600.
The checklist
get-public-access-block: are the four settings on, for the bucket and the account?get-bucket-policy-statusandget-bucket-policy: any"Principal": "*"?get-bucket-acl: anyAllUsersorAuthenticatedUsersgrant?- Fix in order: keep the wanted readers, remove the public grants, block public access, disable ACLs, test as the reader.
Questions
- How do I check if an S3 bucket is public from the CLI?
- Run aws s3api get-bucket-policy-status --bucket <name>: IsPublic true means its bucket policy grants access to everyone. Then check the ACL with get-bucket-acl for an AllUsers or AuthenticatedUsers grantee, and get-public-access-block to see whether either can take effect.
- Does Block Public Access delete my bucket policy?
- No. It changes nothing that is stored. IgnorePublicAcls and RestrictPublicBuckets stop existing public grants from working; BlockPublicAcls and BlockPublicPolicy reject new public ACLs and policies. The old public statement stays in the policy until you remove it.
- Will turning on Block Public Access break my application?
- Not if the application signs its requests with AWS credentials (an IAM user or role). Only anonymous access stops. Check first which readers rely on the public grant, for example a website served straight from S3, and move them to CloudFront with origin access control or to pre-signed URLs.
- What does AuthenticatedUsers mean in an S3 ACL?
- Anyone with any AWS account, not just users in yours. It's as good as public, and AWS counts it as public.
Fix it yourself
A live machine in your browser, already broken. The grader checks the result.
- Close a Public Bucket Without Breaking the Appmedium 12 min
- Admin Who Can't Read the Reportsmedium 12 min
- The Website That Downloads Itselfeasy 10 min
No account needed for your first tries.
More guides
- Kubernetes Service has no endpoints: the 3 causes and how to check each
Your Service exists, but requests fail and its EndpointSlice is empty. Three causes explain almost every case: the selector, readiness, or no Pods at all.
- sudo echo >> /etc/hosts: Permission denied. Why sudo didn't help
sudo runs the command as root, but the >> redirect is done by your own shell, before sudo starts. Here's why, and the three correct ways to write the file.
- I added the file to .gitignore and Git still tracks it
.gitignore only applies to files Git isn't tracking yet. Here's how to untrack a file without deleting it, and what happens to your teammates when they pull.