Secure Amazon S3 and IAM with Least Privilege
Résumé
Pixel shares a practical guide to securing Amazon S3 and IAM using least privilege and S3 Block Public Access. It covers checking account and bucket settings, reviewing policies and ACLs, replacing broad s3:* permissions, and using IAM Access Analyzer to find public, external, or unused access.
DEV Community
Lock down Amazon S3 and IAM with least privilege and Block Public Access
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...

Powered by Readybot.io