Playbook: S3 bucket accidentally public
Contain an exposed S3 bucket in minutes with Block Public Access, work out who changed it and who read from it using CloudTrail and access logs, preserve evidence, and hand a factual timeline to the incident and data protection teams.
Assumes: .NET 10 LTS · AWS SDK for .NET v4 (AWSSDK.S3) · AWS CLI v2 · Amazon S3 · Region us-east-1. Verified against official sources on 2026-11-18.
Learning objectives
By the end of this playbook you can:
- Contain a publicly exposed bucket in the first minutes without destroying evidence.
- Explain the four Block Public Access settings and why account-level and bucket-level settings both matter.
- Find who made the bucket public and when from CloudTrail management events.
- Find who read from it using CloudTrail data events, S3 server access logs or CloudFront logs, and state honestly what you cannot know when those logs were off.
- Hand the incident and data protection teams a factual timeline, without declaring a breach yourself.
- Run a C# scanner that reports the public-access status of every bucket in an account.
Prerequisites
- S3 protection, Object Lock and Macie
- Incident response, CloudTrail for banks and Audit logging and evidence collection
- UK GDPR and data residency
- Tools: AWS CLI v2 with the
learn-sandboxprofile; .NET 10 SDK for the scanner
Why this matters in banking
A developer creates a bucket harbourline-statements-export to share a month of customer statement PDFs with a printing partner. To make the partner's download work quickly, they add a bucket policy with "Principal": "*". The policy is meant to last an afternoon. Nobody removes it. Three weeks later an external security researcher emails the bank: "your statements bucket is listable from the internet".
Two things must happen at once. First, stop the exposure now: every minute the bucket stays open, more data can be read. Second, do not destroy the evidence the bank needs to answer "who accessed what, and when". A hasty "delete the bucket" or "delete the logs" turns a containable event into an unprovable one. The decision on whether this is a reportable personal data breach belongs to the data protection officer and legal team, not to the engineer. Your job is containment, evidence and a precise timeline. Under UK GDPR, a notifiable breach generally must be reported to the regulator within 72 hours of the organisation becoming aware, so the clock matters; the data protection team confirms how it applies.
The idea in plain language
A bucket is public when something allows anyone (the whole internet, no sign-in) to read or list it. There are four ways that can happen:
- A bucket policy with a wildcard principal.
- An ACL (access control list) granting access to "everyone" (
AllUsers) or "any authenticated AWS user". - An access point policy with a wildcard.
- A CloudFront or website configuration exposing it on purpose with the wrong scope.
AWS gives you a single master switch, Block Public Access, with four settings that you can apply per bucket or for a whole account:
| Setting | What it stops |
|---|---|
BlockPublicAcls | New public ACLs and uploads that include them |
IgnorePublicAcls | Existing public ACLs: S3 ignores them |
BlockPublicPolicy | New bucket policies that grant public access |
RestrictPublicBuckets | Existing public policies: only AWS services and authorised users in the account can use the bucket |
RestrictPublicBuckets is the containment tool, because it neutralises a public policy that is already attached. Turning on all four at the account level is the strongest single control, and it overrides bucket-level settings for the public-access decision.
Analogy: The bucket policy is a notice on the door saying "anyone may come in". Block Public Access is the building manager's master lock: with it on, the notice is ignored. You engage the master lock first, then investigate who wrote the notice and who walked in while it was up.
What problem the AWS services solve
- S3 Block Public Access gives a fast, reversible containment switch that does not alter the policy or the data, which keeps the evidence intact.
- CloudTrail management events record
PutBucketPolicy,PutBucketAclandDeleteBucketPublicAccessBlock: who changed access, when, from which IP and with which role. - CloudTrail data events (opt-in, and charged per event) record object-level
GetObjectandListObjects-style calls with the caller identity and IP. - S3 server access logging records requests to a bucket to another bucket, on a best-effort basis (a few hours of delay and occasional gaps are possible).
- IAM Access Analyzer raises findings for resources shared outside your zone of trust, including public S3 buckets.
- AWS Config rules such as
s3-bucket-public-read-prohibitedflag buckets that allow public read. - Amazon Macie (see the Macie lesson) tells you what kind of data (names, account numbers) is in the bucket, which feeds the impact assessment.
What AWS cannot do: it cannot tell you what was read if object-level logging was off. In that case you must say "we cannot determine", which is a finding in itself and a reason to enable data events for sensitive buckets by policy.
Current defaults (⚠ VERIFY before quoting)
New buckets are created with Block Public Access on and ACLs disabled (Object Ownership "bucket owner enforced") by default since April 2023. An exposed bucket in a modern account therefore usually means somebody turned protection off or the bucket is old. Both are worth proving from CloudTrail.
Microsoft / Azure comparison
| You know (Microsoft/Azure) | AWS equivalent | What's different |
|---|---|---|
| Storage account "Allow Blob public access" off | S3 Block Public Access (account or bucket) | Four separate settings, and an account-level master that applies to all buckets |
| Container access level "Blob" or "Container" | Bucket policy or ACL granting * | Public access is expressed through policy, not a container level |
| Azure Policy deny rule for public storage | Organizations policy or Config rule plus SCP | Preventive controls come from several places; use SCPs to prevent changing the block |
Azure Activity Log for Microsoft.Storage changes | CloudTrail management events | Same idea. Object-level reads need data events on AWS |
| Storage Analytics logs | S3 server access logs and CloudTrail data events | Two sources with different guarantees and costs |
| Defender for Storage alerts | GuardDuty S3 protection, Macie | Separate services you enable |
| SAS token leaked | Pre-signed URL leaked | A pre-signed URL is a different exposure: bucket not public, but a URL works until it expires |
Architecture
The incident flow
Security-boundary view
Step-by-step implementation
Minutes 0 to 5: confirm and open the incident
- Record who reported it, the bucket name and the time you were told (UTC). This starts the awareness clock the data protection team will ask about.
- Confirm exposure without downloading data: run
get-bucket-policy-status(does the policy make it public?) and check the ACL. An anonymous HEAD request to a known object key, using a request with no credentials, confirms it from the outside. Do not download customer files to prove the point. - Open your incident record using your bank's process (Incident Manager is closed to new customers, see the module overview; use your own incident tooling) and notify the security lead.
Minutes 5 to 10: contain
Turn on all four Block Public Access settings on the bucket, then on the account if it is not already on. This does not delete the policy or change the objects, so it preserves evidence. Re-run the anonymous check: it should now fail. Note the exact time of containment.
Check the legitimate users: if the partner's download relied on the public policy, tell the business owner it will stop working, and plan a proper replacement (pre-signed URLs, a cross-account role, or AWS Transfer Family).
Minutes 10 to 25: preserve evidence
Before changing anything else, save: the bucket policy JSON, the ACL, the public access block configuration (before and after), the bucket's logging and versioning configuration, and a listing of object keys (names, sizes and dates, not contents). Store them in the incident record. Do not delete the bucket, empty it, shorten log retention or "clean up" objects. If Object Lock or a legal hold is appropriate for the logs, ask the security team.
Minutes 25 to 50: who changed it, and who read it
Who changed it (management events, retained 90 days in Event history, longer in a trail):
PutBucketPolicy,PutBucketAcl,DeleteBucketPolicy,PutBucketPublicAccessBlock,DeleteBucketPublicAccessBlock,PutAccountPublicAccessBlockorDeletePublicAccessBlock(the account-level call is on the S3 Control endpoint).- Capture
eventTime,userIdentity.arn(the role, and the session name if present),sourceIPAddressanduserAgent.
Who read it:
- CloudTrail data events for the bucket, if enabled:
GetObject, withuserIdentityofAWSAccountandANONYMOUS_PRINCIPALstyle entries for unauthenticated access (⚠ VERIFY the exact anonymous identity wording in your records). - S3 server access logs, if enabled: requester
-indicates unauthenticated requests. Filter for requests from outside your known IPs during the exposure window. - CloudFront logs, if the bucket sat behind a distribution.
- If none were enabled: record plainly that access cannot be determined and that all objects must be assumed readable. That statement drives the impact assessment.
The exposure window runs from the change that made the bucket public (from CloudTrail) to the containment time.
Minutes 50 to 75: impact, handover and prevention
- Classify what was in the bucket. Ask the bucket owner and, if available, run a Macie discovery job on it. Distinguish personal data, financial account data, cardholder data (a PCI DSS matter) and non-sensitive files.
- Write the timeline (all UTC): exposure begins, discovered, contained, evidence of external reads, assessments.
- Hand over to the incident manager and data protection officer with the facts. They decide on regulatory and customer notification. You do not.
- Prevent recurrence: account-level Block Public Access, an SCP to stop principals changing it, a Config rule and alert for public buckets, data events on sensitive buckets, and a review of how the engineer was allowed to attach a wildcard policy in the first place.
AWS Console instructions
- Console → S3 → Buckets → (bucket) → Permissions: check Block public access (bucket settings), the Bucket policy and the Access control list (ACL). A bucket flagged Publicly accessible shows a banner. Choose Edit on Block public access and tick all four boxes.
- Console → S3 → Block Public Access settings for this account (left menu): turn on all four settings for the account.
- Console → CloudTrail → Event history: filter Event source
s3.amazonaws.comand Event namePutBucketPolicy(thenPutBucketAcl) to see who changed access. For long retention use your trail's S3 bucket with Athena. - Console → S3 → (bucket) → Properties: look at Server access logging and, further down, Event notifications and whether CloudTrail data events cover the bucket (CloudTrail console → Trails → Data events).
- Console → IAM → Access Analyzer → Findings: filter for the bucket resource type to see the public-access finding.
AWS CLI
# 1. Is the bucket public according to its policy?
aws s3api get-bucket-policy-status --bucket harbourline-statements-export \
--query 'PolicyStatus.IsPublic' --profile learn-sandbox
# 2. EVIDENCE FIRST: save the policy, ACL and block settings before changing anything.
mkdir -p evidence && cd evidence
aws s3api get-bucket-policy --bucket harbourline-statements-export --profile learn-sandbox > policy-before.json
aws s3api get-bucket-acl --bucket harbourline-statements-export --profile learn-sandbox > acl-before.json
aws s3api get-public-access-block --bucket harbourline-statements-export --profile learn-sandbox > bpa-before.json
aws s3api get-bucket-logging --bucket harbourline-statements-export --profile learn-sandbox > logging.json
# 3. CONTAIN: turn on all four Block Public Access settings on the bucket.
aws s3api put-public-access-block --bucket harbourline-statements-export \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true \
--profile learn-sandbox
# 4. CONTAIN: the same at account level (the account ID is fictional).
aws s3control put-public-access-block --account-id 111122223333 \
--public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true \
--profile learn-sandbox
# 5. Who changed access? Look up the management events for this bucket's policy changes.
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=PutBucketPolicy \
--start-time 2026-10-25T00:00:00Z --end-time 2026-11-18T23:59:59Z \
--query 'Events[].[EventTime,Username,EventName]' --output table --profile learn-sandbox
# 6. Keep a key listing as evidence of what was in the bucket (names and sizes only).
aws s3api list-objects-v2 --bucket harbourline-statements-export \
--query 'Contents[].[Key,Size,LastModified]' --output text --profile learn-sandbox > object-listing.txtAn Athena query over a CloudTrail table (named cloudtrail_logs here; yours may differ) for who changed bucket access and who read objects, if data events were on:
-- Who changed access to the bucket?
SELECT eventtime, eventname, useridentity.arn AS actor, sourceipaddress, useragent
FROM cloudtrail_logs
WHERE eventsource = 's3.amazonaws.com'
AND eventname IN ('PutBucketPolicy','PutBucketAcl','DeleteBucketPublicAccessBlock','PutBucketPublicAccessBlock')
AND json_extract_scalar(requestparameters, '$.bucketName') = 'harbourline-statements-export'
ORDER BY eventtime;
-- Who read objects during the exposure window (requires data events)?
SELECT eventtime, useridentity.type AS identity_type, useridentity.arn AS actor, sourceipaddress, count(*) AS reads
FROM cloudtrail_logs
WHERE eventsource = 's3.amazonaws.com'
AND eventname = 'GetObject'
AND json_extract_scalar(requestparameters, '$.bucketName') = 'harbourline-statements-export'
AND eventtime BETWEEN '2026-10-28T00:00:00Z' AND '2026-11-18T12:00:00Z'
GROUP BY eventtime, useridentity.type, useridentity.arn, sourceipaddress
ORDER BY eventtime;Infrastructure as Code
Preventive controls: a bucket that cannot be made public, encrypted at rest, with TLS enforced and server access logs going to a separate bucket, plus a Config rule that flags public buckets. The account-level Block Public Access setting is set separately (Terraform resource below, or the CLI above; ⚠ VERIFY whether your CloudFormation version has a native resource).
using Amazon.CDK;
using Amazon.CDK.AWS.Config;
using Amazon.CDK.AWS.S3;
using Constructs;
public class StatementsBucketStack : Stack
{
public StatementsBucketStack(Construct scope, string id, IStackProps props) : base(scope, id, props)
{
var logs = new Bucket(this, "AccessLogs", new BucketProps
{
BlockPublicAccess = BlockPublicAccess.BLOCK_ALL,
Encryption = BucketEncryption.S3_MANAGED,
EnforceSSL = true,
RemovalPolicy = RemovalPolicy.RETAIN
});
var statements = new Bucket(this, "Statements", new BucketProps
{
BucketName = null, // let CloudFormation name it
BlockPublicAccess = BlockPublicAccess.BLOCK_ALL, // all four settings
Encryption = BucketEncryption.KMS_MANAGED,
EnforceSSL = true,
Versioned = true,
ServerAccessLogsBucket = logs,
ServerAccessLogsPrefix = "statements/",
RemovalPolicy = RemovalPolicy.RETAIN
});
// Managed Config rule that flags buckets allowing public read.
new ManagedRule(this, "NoPublicRead", new ManagedRuleProps
{
Identifier = ManagedRuleIdentifiers.S3_BUCKET_PUBLIC_READ_PROHIBITED,
Description = "Flags buckets that allow public read. See playbook s3-bucket-accidentally-public."
});
Amazon.CDK.Tags.Of(this).Add("Project", "cea-lab");
Amazon.CDK.Tags.Of(this).Add("Lab", "m17-playbook-public-bucket");
}
}An Organizations service control policy (SCP) that stops anyone but a break-glass role from weakening the setting, as a sketch (test in a sandbox organisation first). Deleting a bucket-level block is authorised by the same s3:PutBucketPublicAccessBlock action (⚠ VERIFY against the S3 actions reference):
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "DenyChangingPublicAccessBlock",
"Effect": "Deny",
"Action": [
"s3:PutAccountPublicAccessBlock",
"s3:PutBucketPublicAccessBlock"
],
"Resource": "*",
"Condition": {
"StringNotLike": { "aws:PrincipalArn": "arn:aws:iam::*:role/hl-security-breakglass" }
}
}]
}Complete code
A scanner for public-access status across an account
This tool lists every bucket, then reports its Block Public Access settings and whether its policy makes it public. It uses AWSSDK.S3 v4 and the default credential chain (use the learn-sandbox profile through AWS_PROFILE). It is read-only.
using Amazon.S3;
using Amazon.S3.Model;
using var s3 = new AmazonS3Client();
var buckets = (await s3.ListBucketsAsync()).Buckets ?? new List<S3Bucket>();
Console.WriteLine($"{"bucket",-45} {"BPA all four",-13} {"policy public",-14} verdict");
var exposed = 0;
foreach (var bucket in buckets)
{
var name = bucket.BucketName;
try
{
var bpa = await GetBlockSettingsAsync(s3, name);
var policyPublic = await IsPolicyPublicAsync(s3, name);
var verdict = Classify(bpa.AllFour, policyPublic);
if (verdict != "ok") exposed++;
Console.WriteLine($"{name,-45} {bpa.AllFour,-13} {(policyPublic ? "yes" : "no"),-14} {verdict}");
}
catch (AmazonS3Exception ex)
{
// For example a bucket in another Region or one we cannot read: report, never ignore silently.
Console.WriteLine($"{name,-45} {"?",-13} {"?",-14} could not check ({ex.ErrorCode})");
}
}
Console.WriteLine($"{buckets.Count} buckets checked, {exposed} need attention.");
return exposed == 0 ? 0 : 2;
static async Task<(bool AllFour, string Detail)> GetBlockSettingsAsync(IAmazonS3 s3, string bucket)
{
try
{
var response = await s3.GetPublicAccessBlockAsync(new GetPublicAccessBlockRequest { BucketName = bucket });
var c = response.PublicAccessBlockConfiguration;
var all = c.BlockPublicAcls == true && c.IgnorePublicAcls == true
&& c.BlockPublicPolicy == true && c.RestrictPublicBuckets == true;
return (all, $"acls={c.BlockPublicAcls} ignore={c.IgnorePublicAcls} policy={c.BlockPublicPolicy} restrict={c.RestrictPublicBuckets}");
}
catch (AmazonS3Exception ex) when (ex.ErrorCode == "NoSuchPublicAccessBlockConfiguration")
{
return (false, "no bucket-level configuration");
}
}
static async Task<bool> IsPolicyPublicAsync(IAmazonS3 s3, string bucket)
{
try
{
var status = await s3.GetBucketPolicyStatusAsync(new GetBucketPolicyStatusRequest { BucketName = bucket });
return status.PolicyStatus?.IsPublic == true;
}
catch (AmazonS3Exception ex) when (ex.ErrorCode == "NoSuchBucketPolicy")
{
return false;
}
}
static string Classify(bool allFour, bool policyPublic) => (allFour, policyPublic) switch
{
(_, true) when !allFour => "EXPOSED: public policy and protection not fully on",
(_, true) => "policy is public but blocked by BPA: remove the policy",
(false, false) => "weak: Block Public Access not fully on",
_ => "ok"
};Create a console project targeting net10.0 and add the package with dotnet add package AWSSDK.S3 (the current 4.x version). Run it with AWS_PROFILE=learn-sandbox dotnet run.
Code explained line by line
new AmazonS3Client()uses the default credential chain, so no keys appear in code. WithAWS_PROFILE=learn-sandboxit uses your SSO profile.ListBucketsAsyncreturns every bucket in the account. In SDK v4 collections can be null, so the code guards with?? new List<S3Bucket>().GetPublicAccessBlockAsyncreads the bucket-level settings. A bucket with none throwsNoSuchPublicAccessBlockConfiguration, which the code treats as "not protected at bucket level" (the account-level setting may still protect it).- Comparing each flag with
== trueworks whether the SDK property isboolorbool?, which is how v4 models optional values. GetBucketPolicyStatusAsyncasks S3 to evaluate whether the policy makes the bucket public. A missing policy raisesNoSuchBucketPolicy, which means "not public by policy".- The
catch (AmazonS3Exception)in the loop prints a?row instead of skipping. A scanner that hides errors gives false comfort. Classifyputs the dangerous combination first: public policy without full protection. A public policy that Block Public Access neutralises is still a finding, because switching the block off would expose it at once.- The exit code is 2 when anything needs attention, so a pipeline can fail on it.
Security considerations
⚠ Learning shortcut — not for production
The scanner reads bucket settings but not the account-level Block Public Access, and it does not look at ACLs, access points or website hosting. A real posture check uses Access Analyzer, Config and Security Hub across all accounts and Regions. The scanner is for learning and for an incident-time first look. Also, never confirm exposure by downloading real customer files; check metadata only.
- Containment before investigation, but evidence before deletion. Never delete a bucket, policy history or logs during the incident.
- Least privilege for the investigators. Give responders read access to logs and the ability to set Block Public Access, not blanket admin.
- Protect the log bucket. Server access logs and CloudTrail logs are evidence. Keep them in a separate, locked-down account or bucket, with Object Lock where policy requires.
- Do not paste object names or customer identifiers into chat. File names themselves can be personal data.
- Pre-signed URLs are not "public" but behave like bearer links. Keep expiries short and do not log full URLs.
- KMS encryption does not make a public bucket safe. With a public policy, S3 decrypts SSE-S3 objects for anonymous readers. For SSE-KMS objects, an anonymous reader needs KMS permission, which usually fails: a useful extra barrier, not a control to rely on.
- Notification decisions are not yours. State facts and timestamps. The data protection officer decides on notifying the regulator or customers. Nothing here is legal advice or a compliance claim.
Banking use case
For Harbourline, three controls turn this incident into a non-event. The account has Block Public Access on at account level and an SCP that stops everyone except a break-glass role from weakening it, so the wildcard policy in the story would have been rejected at the time it was written. Sensitive buckets (statements, KYC documents) have CloudTrail data events and server access logs, so "who read it?" is answerable. A Config rule and an Access Analyzer finding raise an alert within minutes, which keeps the exposure window short. The incident record for the story above shows the timeline the responders produced: policy added 2026-10-28 14:12 UTC by a named role, reported 2026-11-18 09:40 UTC, contained 09:48 UTC, 3 external IPs in the logs for the window, 2 of them the partner's known addresses, and the unexplained one passed to the security team.
Common mistakes
- Deleting the bucket or the policy first. It destroys evidence and may remove data the bank must retain.
- Only fixing the one bucket. Check the whole account and turn on the account-level setting.
- Assuming "no reads" because there are no logs. Absence of logs is not absence of access.
- Downloading customer files to confirm exposure. It creates another copy of personal data.
- Declaring "no breach" or "breach" as an engineer. That is a data protection decision.
- Fixing the symptom only. Without an SCP or a Config alert the same mistake repeats next quarter.
- Forgetting other exposure routes: an ACL, an access point, a CloudFront distribution or leaked pre-signed URLs.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
put-public-access-block returns AccessDenied | Missing s3:PutBucketPublicAccessBlock, or an SCP blocks it | Use a role with the permission, or the break-glass role the SCP excludes |
| Bucket still reachable after setting the block | Exposure through CloudFront, a pre-signed URL or a different bucket | Check distributions and access points, and rotate any signing credentials involved |
| Partner download broke after containment | It relied on the public policy | Replace with pre-signed URLs, a role the partner assumes, or Transfer Family |
NoSuchPublicAccessBlockConfiguration | No bucket-level settings exist | Create the configuration with put-public-access-block |
No GetObject records in CloudTrail | Data events were not enabled | State that reads cannot be determined, check server access logs and CloudFront logs |
| Server access logs have gaps | Best-effort delivery | Treat as incomplete, and note this in the findings |
| Event history lacks the change | Older than 90 days, or in another Region | Search the trail's S3 bucket with Athena, check the right Region |
| Access Analyzer finding stays active after the fix | Finding not re-evaluated yet | Rescan or wait, then verify the status turns resolved |
Cost and cleanup
Cost label: free for reading the lesson and running the scanner. The optional sandbox reproduction creates a tiny bucket (pennies at most) and, if you enable CloudTrail data events, charges per event (⚠ VERIFY current price), so use a sandbox account, do not turn on data events beyond a short test, and tear down afterwards. Never make a bucket public in an account that holds real data. For the exercise, use a bucket containing only a dummy text file.
# Empty and delete the sandbox bucket (versioned buckets also need versions removed)
aws s3 rm s3://<sandbox-bucket> --recursive --profile learn-sandbox
aws s3api delete-bucket --bucket <sandbox-bucket> --profile learn-sandbox
# Remove the Config rule if you created it
aws configservice delete-config-rule --config-rule-name hl-s3-no-public-read --profile learn-sandbox
# Confirm nothing tagged for this lesson remains
aws resourcegroupstaggingapi get-resources --tag-filters Key=Lab,Values=m17-playbook-public-bucket --profile learn-sandboxExercises
- 🟢 Guided: In a sandbox account, create a bucket with one dummy file, temporarily turn the bucket-level Block Public Access off and attach a public-read bucket policy. Run the scanner and read the verdict. Turn Block Public Access on and run it again.
- 🟡 Challenge: Extend the scanner to also fetch the account-level block settings with
AmazonS3ControlClientand report buckets that are weak at the bucket level but protected by the account. Add a column for it. - 🔴 Live problem: "A researcher says
harbourline-kyc-uploadsis listable. Block Public Access is already on for the bucket. Nobody changed the policy this month." List where else the exposure could come from and which evidence you collect first.
Assignment
Write an S3 exposure runbook for your portfolio: containment commands in order, an evidence checklist, the two Athena queries adapted to your account, a timeline template and the preventive controls from this lesson. Commit as runbooks/s3-public-bucket.md with fictional names and no real data.
Solutions
Before the block is on, the scanner prints False under "BPA all four", yes under "policy public" and the verdict "EXPOSED: public policy and protection not fully on". After you enable all four settings the policy is still attached, so the second run prints True, yes (or no if S3 now treats the policy as non-public, ⚠ VERIFY the observed value) and "policy is public but blocked by BPA: remove the policy". Why: the block neutralises the policy without deleting it, which is perfect for containment, but the leftover policy is a risk until it is removed in a controlled change.
Create new AmazonS3ControlClient() (package AWSSDK.S3Control) and call GetPublicAccessBlockAsync(new Amazon.S3Control.Model.GetPublicAccessBlockRequest { AccountId = accountId }). Get the account ID from STS GetCallerIdentity. Compute accountAllFour the same way as the bucket check. A bucket with weak bucket-level settings but accountAllFour == true is protected today, but depends on one account-wide setting, so classify it as "covered by account". Why: two independent layers give defence in depth, and knowing which layer is doing the work tells you the blast radius if someone changes the account setting.
With Block Public Access on and a clean policy, other routes remain: (1) an access point for the bucket with its own policy (the bucket policy can delegate to access points); (2) a CloudFront distribution that serves the bucket with listing or a public origin path; (3) website hosting configuration; (4) a leaked pre-signed URL (not "listable" but readable), or a leaked long-lived credential; (5) a cross-account grant to an account that is itself open; (6) the researcher is looking at a different bucket with a similar name. First evidence: save the access point list and policies, the CloudFront origins list, the bucket policy and website configuration, then CloudTrail events for CreateAccessPoint, PutAccessPointPolicy and distribution changes. Why: Block Public Access covers bucket policies and ACLs for the bucket and its access points when set, but you must verify each route rather than assuming one switch covers everything.
Knowledge check
Answer: RestrictPublicBuckets. BlockPublicPolicy only stops new public policies from being attached.
Answer: It stops public access immediately without altering or deleting the policy, so the evidence of what was configured stays intact. Delete the policy later in a controlled change.
Answer: No. Without data events (or server access or CloudFront logs) you cannot determine who read objects, and you must report it as unknown and assume exposure.
Answer: The data protection officer and legal or compliance team, using the facts engineers provide. Engineers contain, collect evidence and write the timeline.
Answer: It applies to every bucket in the account, including new and forgotten ones, so one wrong bucket policy cannot expose data publicly.
Interview questions
- A public S3 bucket has been reported. What are your first three actions? Confirm exposure without downloading data, contain with Block Public Access, and preserve the policy, ACL and logs as evidence.
- How do you find out who accessed the objects? CloudTrail data events, S3 server access logs and CloudFront logs, filtered to the exposure window. If none were enabled, say so.
- How do you stop it happening again? Account-level Block Public Access, an SCP preventing weakening it, Config and Access Analyzer alerts, and data events on sensitive buckets.
- What is the difference between a public bucket and a leaked pre-signed URL? The first is open to everyone through bucket configuration, the second is a bearer link to specific objects that works until it expires.
- Is encrypting the bucket with KMS enough? No. It adds a barrier for SSE-KMS objects, but a public policy is still a control failure.
Certification practice
A security engineer finds an S3 bucket with a bucket policy granting s3:GetObject to Principal: "*". The first priority is to stop public access without losing evidence. What should the engineer do?
A. Delete the bucket. B. Enable S3 Block Public Access on the bucket, then preserve the policy and review CloudTrail. C. Delete the bucket policy and the CloudTrail trail. D. Move all objects to another bucket and delete the original.
Answer: B. Block Public Access neutralises public access immediately and retains configuration and logs. A, C and D destroy evidence.
An operations team wants to be alerted whenever any bucket in an account allows public read access. Which solution is best?
A. An AWS Config managed rule for public-read prohibition with notifications. B. A weekly manual check in the console. C. An EC2 instance that runs a script every hour. D. CloudFront access logs.
Answer: A. Config continuously evaluates configuration and can notify or remediate. B and C are manual or custom, and D concerns requests, not configuration.
A company wants to ensure no bucket in an account can ever be made public by a bucket policy, even by an administrator mistake. Which control is most effective?
A. A tag on each bucket saying "private". B. Account-level S3 Block Public Access, with an SCP preventing its removal. C. Server access logging on each bucket. D. Versioning on each bucket.
Answer: B. The account-level block overrides bucket-level public grants and the SCP stops it being weakened. Tags, logs and versioning do not prevent public access.
Completion checklist
- I can name the four Block Public Access settings and which one handles an existing policy
- I can list the evidence to save before changing anything
- I know which CloudTrail events show who changed access and which show who read objects
- I ran the scanner or the CLI checks in a sandbox
- I can explain why the notification decision is not an engineer's
- I ran the cleanup steps and confirmed nothing tagged
m17-playbook-public-bucketremains
Key takeaways
- Contain first with Block Public Access, and keep every piece of evidence.
- CloudTrail management events say who changed access, data events and access logs say who read.
- No logs means "unknown", not "nobody".
- Engineers give facts and timelines, the data protection team decides on notification.
- Prevent with account-level blocking, an SCP, Config and data events on sensitive buckets.
Further reading
- Blocking public access to your Amazon S3 storage
- Logging Amazon S3 API calls using AWS CloudTrail
- Previous playbook: CORS failures
- Next playbook: IAM role too broad
- Related: Module 17 overview
Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.
Playbook: CORS failures
Diagnose browser CORS errors by replaying the preflight request yourself, finding which layer (API Gateway, CloudFront, ASP.NET Core) should answer it, and fixing credentials, header and error-response gaps without opening the API to every origin.
Playbook: IAM role too broad
Right-size an over-permissive IAM role safely using last-accessed data, CloudTrail and IAM Access Analyzer policy generation, with a staged rollout and rollback so you reduce risk without breaking a year-end job.