This article was first published on the Rokkhe blog on Hashnode. It was drafted with AI assistance and reviewed and edited by the Rokkhe team; all commands and sources were checked against AWS documentation.
A hands-on pass of official AWS controls, on accounts you own. 16 November 2026, Asia/Dhaka. By the Rokkhe research team.
A surprising number of cloud incidents start with a setting: a bucket policy that grants Principal: "*", an access-control list that still allows AllUsers, or an application role with s3:* on Resource: "*". AWS already ships the controls that close those paths. This post uses them, in a safe order: read first, then tighten.
You will need permission to call S3 and IAM APIs on the account, and a terminal with the AWS CLI configured for that account. Replace placeholders such as amzn-s3-demo-bucket and 123456789012 with your own names. Do not run these commands against an account you do not administer.
TL;DR
- Turn on S3 Block Public Access at the account level, with all four settings enabled, unless you have a documented exception for a bucket that is deliberately public.
- Before you change a bucket, read its Block Public Access config, policy and ACLs.
- Replace
s3:*on*with the actions and prefixes the application actually uses. - Use IAM Access Analyzer to list resources that are still shared publicly or with other accounts, and to find unused access.
- This is not a complete AWS security programme. It is the misconfiguration pass most teams can finish in an afternoon.
Public data is usually a setting, not a break-in
AWS documents S3 access as a combination of account settings, bucket policies, IAM identity policies, and (for older setups) access-control lists. Block Public Access is the safety catch on top: it can prevent public ACLs and public policies from taking effect, at the account or at the bucket.
That is why this pass starts with Block Public Access and Access Analyzer, not with a hunt for an attacker. If a bucket is public, the first job is to decide whether it was meant to be public (a static website you accept as public) or whether it is a mistake. Both happen. Only the second is an incident; both should be explicit in a ticket.
One useful fact before you start: since April 2023, AWS turns on all four Block Public Access settings and disables ACLs for every new bucket by default (AWS News Blog). Buckets created before that, or created by templates that switched those defaults off, are where this pass usually finds work.
Work in a non-production account first if you can, or on a bucket whose downtime you can afford, until you are comfortable with the read commands.
Turn on S3 Block Public Access at the account, then check each bucket
AWS’s “Blocking public access to your Amazon S3 storage” page describes four switches: BlockPublicAcls, IgnorePublicAcls, BlockPublicPolicy, and RestrictPublicBuckets. For almost every account, all four should be true at the account level, so a new bucket cannot be made public by accident.
Read the account setting first:
# Replace with your 12-digit account id. aws s3control get-public-access-block --account-id 123456789012 If the command says the configuration is missing, or any of the four flags is false, document the current state, then apply the official all-true configuration:
aws s3control put-public-access-block \ --account-id 123456789012 \ --public-access-block-configuration \ BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true Then check a specific bucket:
aws s3api get-public-access-block --bucket amzn-s3-demo-bucket A bucket can have its own Block Public Access settings. Account-level settings still apply; AWS documents how the more restrictive combination wins. If a marketing site must be public, make that a named exception with an owner, not a quiet hole in the account-level catch. Everything else should inherit the account default.
List buckets so you know the scope of the afternoon:
aws s3api list-buckets --query 'Buckets[].Name' --output text Read the bucket policy and ACLs without changing them first
For each bucket that matters (internet-adjacent, customer data, backups, logs), take a snapshot of how it is currently shared:
BUCKET=amzn-s3-demo-bucket aws s3api get-bucket-policy --bucket "$BUCKET" --output text > /tmp/${BUCKET}-policy.json aws s3api get-bucket-acl --bucket "$BUCKET" > /tmp/${BUCKET}-acl.json aws s3api get-bucket-policy-status --bucket "$BUCKET" aws s3api get-bucket-ownership-controls --bucket "$BUCKET" get-bucket-policy-status tells you whether AWS currently considers the policy public. Read the saved policy before you edit it. Look for "Principal": "*" combined with Allow, for s3:GetObject on the whole bucket, and for any statement you cannot explain.
ACLs that grant AllUsers or AuthenticatedUsers are a second path to public or overly broad access. Newer buckets often use “bucket owner enforced” ownership, which disables ACLs; that is the direction AWS has been steering accounts toward. If you still have ACL-based sharing, record it and plan to replace it with a bucket policy you can read.
Do not delete a policy until you know what still needs legitimate access (a CloudFront distribution, a partner account, a log-delivery service). Taking the bucket private is easy. Recreating a working partner integration at 2 a.m. is not.
Write a least-privilege IAM policy for one application role
Pick one application role that can read or write a bucket, and tighten that role rather than boiling the ocean. A policy that is too broad usually looks like this:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:*", "Resource": "*" } ] } Version here is the IAM policy-language version, which AWS documents as 2012-10-17. It is not a date you made up, and it is not “the policy is from 2012.”
A narrower starting point, which you must still edit to your prefix and account, is:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListOnlyOnePrefix", "Effect": "Allow", "Action": ["s3:ListBucket"], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket", "Condition": { "StringLike": { "s3:prefix": ["app-name/*"] } } }, { "Sid": "ReadWriteOnlyOnePrefix", "Effect": "Allow", "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"], "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/app-name/*" } ] } Anything you do not list is denied by default, so leave out what the application does not call. Add s3:PutObjectAcl only if the application truly needs it; many public-bucket accidents start with an object ACL change. Prefer the application role over a long-lived access key on a human IAM user. If a human still has an access key, list and age those keys:
aws iam list-access-keys --user-name A_HUMAN_USER aws iam get-access-key-last-used --access-key-id AKIA_EXAMPLE Rotate unused keys; do not leave a spare key “for emergencies” in a ticket or a git repo (see post 3: find leaked secrets in Git and rotate them).
Test the new policy on a staging role with IAM policy simulator or a canary request, then attach it. Watch the application’s error logs for AccessDenied on a path you intended to allow, and widen that path only.
Let IAM Access Analyzer show you what is still shared
IAM Access Analyzer is the official way to list resources shared outside the account, and, with a separate unused-access analyzer, to find unused roles, keys and permissions.
Create or reuse an external access analyzer in the region you care about, then list findings for S3:
# After an analyzer exists in the account: aws accessanalyzer list-analyzers --region us-east-1 aws accessanalyzer list-findings --analyzer-arn arn:aws:access-analyzer:us-east-1:123456789012:analyzer/CONSOLE_OR_NAME \ --filter '{"resourceType":{"eq":["AWS::S3::Bucket"]}}' AWS also documents Access Analyzer for S3 in the S3 console, which highlights buckets that are public or shared with other accounts. Walk that list. Every public bucket should have a ticket: “intended and covered by Block Public Access exceptions” or “close it.”
If you enable an unused access analyzer, use it for IAM users and roles, not as an S3 public-access tool. AWS documents that unused-access analysis covers IAM users and roles (keys, passwords, unused permissions) over a tracking period you choose. It is a good weekly companion to the least-privilege work above, not a substitute for Block Public Access.
Checklist
- [ ] Account-level S3 Block Public Access is on, all four flags true, or exceptions are named and owned.
- [ ] Every production bucket has a recorded policy, ACL, ownership setting and policy-status snapshot.
- [ ] No unexplained
Principal: "*"Allow remains on a private bucket. - [ ] At least one application role no longer uses
s3:*onResource: "*". - [ ] Human access keys are inventoried; unused keys are disabled.
- [ ] IAM Access Analyzer (external access) has been reviewed for S3 findings.
- [ ] Deliberately public buckets are documented, monitored, and contain only what you intend to publish.
- [ ] Changes were made in a ticket, with a rollback (the saved policy files).
FAQ
Will account-level Block Public Access break a static website?
It will block public access, so a public website hosted directly from a bucket will stop working until you give that bucket a documented exception or you put a CDN/signed-URL design in front of a private bucket. Discover that in staging, not in production.
Is a bucket policy enough without Block Public Access?
A policy can be edited later, including by a too-broad role. Block Public Access is the backstop. Use both.
Does this cover encryption, logging and malware in objects?
No. Turn on default encryption, access logging or CloudTrail data events, and object inspection as separate work. This post is about who can reach the data.
Can we do the same thing in Terraform or CloudFormation?
Yes. The same four Block Public Access flags and the same IAM statements belong in infrastructure as code, reviewed in a pull request. The CLI commands here are for discovery and for accounts that are not fully in code yet.
Sources
- AWS Docs, Blocking public access to your Amazon S3 storage
- AWS Docs, Identity-based policies for Amazon S3
- AWS Docs, IAM Access Analyzer
- AWS Docs, Reviewing bucket access using IAM Access Analyzer for S3
- AWS Docs, Controlling ownership of objects and disabling ACLs
- AWS News Blog, Amazon S3 security changes in April 2023
Next in the series
Test your API against the OWASP API Security Top 10 2023. Previous: Build a weekly CVE triage workflow with CISA KEV, EPSS and CVSS. If a public bucket shows up in that triage, this post is the fix list. Start of the series: Pin your GitHub Actions by commit SHA.
Rokkhe is an AI pentesting and security-operations workspace. Learn more at rokkhe.com.

