Symptoms
- An IAM Access Analyzer, Security Hub, Trusted Advisor or Macie finding says a bucket allows public access.
- Someone outside the company reports they can open an object URL like
https://my-bucket.s3.amazonaws.com/exports/customers.csvwithout signing in. - The S3 console shows Publicly accessible on the bucket.
- A recent change, often to host a static site or to "fix" an access denied error, added
"Principal": "*"to the bucket policy or granted ACL access toAllUsers.
Treat this as a security incident from the first minute. The order is: contain, preserve evidence, assess, recover.
Step 1: contain - block public access now (2 minutes)
Turn on all four Block Public Access settings on the bucket. This overrides public bucket policies and public ACLs without deleting them, so the evidence stays in place.
BUCKET=my-bucket
aws s3api put-public-access-block --bucket $BUCKET \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
Confirm it took effect:
aws s3api get-public-access-block --bucket $BUCKET
aws s3api get-bucket-policy-status --bucket $BUCKET --query "PolicyStatus.IsPublic"
curl -s -o /dev/null -w "%{http_code}\n" https://$BUCKET.s3.amazonaws.com/exports/customers.csv
An anonymous request should now return 403.
Warning
If the bucket legitimately serves a public website or downloads, this step takes that down too. That is the right call while you assess. Bring public content back later through CloudFront with origin access control, not by reopening the bucket.
If you suspect other buckets in the account, apply Block Public Access at account level as well:
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
aws s3control put-public-access-block --account-id $ACCOUNT \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
Also check for access paths that Block Public Access does not cover:
- Presigned URLs that were shared keep working until they expire, as long as the signing credentials are valid. Rotate or deactivate those credentials if needed.
- Cross-account grants to a specific external account ID are not "public". Check the policy for unknown account IDs.
- Access points and Multi-Region Access Points have their own policies; list them with
aws s3control list-access-points --account-id $ACCOUNT --bucket $BUCKET.
Step 2: preserve evidence (10 minutes)
Save the current configuration before anyone "cleans up":
mkdir -p ir-$BUCKET && cd ir-$BUCKET
aws s3api get-bucket-policy --bucket $BUCKET --query Policy --output text > bucket-policy.json
aws s3api get-bucket-acl --bucket $BUCKET > bucket-acl.json
aws s3api get-bucket-ownership-controls --bucket $BUCKET > ownership.json
aws s3api get-bucket-logging --bucket $BUCKET > logging.json
aws s3api get-bucket-website --bucket $BUCKET > website.json 2>&1
Find who made it public and when. Bucket configuration changes are CloudTrail management events, recorded by default:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=ResourceName,AttributeValue=$BUCKET \
--start-time $(date -u -d '-30 days' +%FT%TZ) \
--query "Events[?contains('PutBucketPolicy PutBucketAcl PutObjectAcl DeleteBucketPublicAccessBlock PutBucketPublicAccessBlock PutBucketOwnershipControls', EventName)].[EventTime,EventName,Username]" \
--output table
The earliest event that opened access gives you the exposure window: from that time until Step 1. Also check for an account-level change with AttributeKey=EventName,AttributeValue=DeleteAccountPublicAccessBlock.
| Change found | How it made the bucket public |
|---|---|
PutBucketPolicy with "Principal": "*" and no restricting condition | Anyone can perform the listed actions |
PutBucketAcl granting AllUsers or AuthenticatedUsers | Public (or any AWS account) read or list |
PutObjectAcl with public-read | Individual objects public |
DeleteBucketPublicAccessBlock | Removed the guardrail that was masking an old public policy or ACL |
PutBucketOwnershipControls away from BucketOwnerEnforced | ACLs re-enabled, so public ACLs start to apply |
Step 3: assess what was read
This depends on logging that was already on. You cannot add logs retroactively.
- CloudTrail data events for S3 record
GetObjectandListObjectsper request, including anonymous ones. - S3 server access logs record every request to the bucket; anonymous requests show
-as the requester.
If you have a CloudTrail Lake event data store or an Athena table over your trail, query reads from outside your organization during the window. Example for an Athena CloudTrail table named cloudtrail_logs; column names follow the standard CloudTrail Athena schema, adjust to yours:
SELECT eventtime, eventname, sourceipaddress, useragent,
json_extract_scalar(requestparameters, '$.key') AS object_key,
useridentity.accountid AS caller_account
FROM cloudtrail_logs
WHERE eventsource = 's3.amazonaws.com'
AND eventname IN ('GetObject', 'ListObjects', 'ListObjectsV2')
AND json_extract_scalar(requestparameters, '$.bucketName') = 'my-bucket'
AND eventtime BETWEEN '2026-11-10T00:00:00Z' AND '2026-11-16T12:00:00Z'
AND (useridentity.accountid IS NULL OR useridentity.accountid NOT IN ('111122223333','444455556666'))
ORDER BY eventtime;
If neither log source was on, assume every object that existed during the window was exposed. List them:
aws s3api list-objects-v2 --bucket $BUCKET \
--query "Contents[].[Key,Size,LastModified]" --output text > objects-in-bucket.tsv
Run an Amazon Macie sensitive-data discovery job on the bucket to classify what was in it. Hand the object list, the exposure window and the access findings to your security and privacy teams; they decide whether notification duties apply.
Caution
If the bucket held credentials, keys,
.envfiles, Terraform state or database dumps, treat those secrets as compromised. Rotate them now, even if the logs show no reads. Terraform state in particular often contains plaintext passwords.
Step 4: remove the public grant at the source
Block Public Access is a guardrail; fix the underlying configuration too.
Disable ACLs entirely so object and bucket ACLs no longer apply:
aws s3api put-bucket-ownership-controls --bucket $BUCKET \
--ownership-controls 'Rules=[{ObjectOwnership=BucketOwnerEnforced}]'
Edit the bucket policy to remove the "Principal": "*" statement (keep the saved copy as evidence), then apply it:
aws s3api put-bucket-policy --bucket $BUCKET --policy file://bucket-policy-fixed.json
If public content is genuinely needed, put CloudFront with origin access control in front and allow only the distribution in the bucket policy.
Check Access Analyzer no longer reports the bucket:
aws accessanalyzer list-findings --analyzer-arn arn:aws:access-analyzer:eu-west-1:111122223333:analyzer/account-analyzer \
--filter '{"resourceType":{"eq":["AWS::S3::Bucket"]},"status":{"eq":["ACTIVE"]}}' \
--query "findings[].[resource,isPublic,updatedAt]" --output table
Prevent it next time
- Block Public Access at account level in every account, enforced through your account vending process, and deny changes to it with an SCP:
{
"Effect": "Deny",
"Action": ["s3:PutAccountPublicAccessBlock", "s3:PutBucketPublicAccessBlock"],
"Resource": "*",
"Condition": { "StringNotLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/PlatformAdmin" } }
}
- Keep ACLs disabled (
BucketOwnerEnforced) on all buckets; it is the default for new buckets. - Serve public content only through CloudFront, never directly from the bucket.
- Turn on S3 data events or server access logs for buckets with sensitive data, so the next assessment has evidence.
- Alert on change. An EventBridge rule for
PutBucketPolicy,PutBucketAclandDeleteBucketPublicAccessBlockto the security channel, plus an organization-wide Access Analyzer.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get