Object Storage Exposure and Block Public Access
Publicly readable storage buckets have leaked voter rolls, medical records, source code and backups by the terabyte, and they are still found every week by people who simply list well-known bucket names. The cause is rarely one setting; it is the interaction of several: a bucket policy written for a website, an access control list (ACL) left over from an old tool, a "temporary" share. Providers responded with account-wide switches that override all of those (AWS S3 Block Public Access, Azure's allowBlobPublicAccess, GCP's public access prevention), and since April 2023 new S3 buckets are created with Block Public Access on and ACLs disabled. The auditor's job is to find the buckets created before that, the ones where someone turned the protection off, and the other paths (presigned URLs, cross-account grants) that the switches don't cover.
The ways an S3 bucket becomes readable by strangers
| Path | What it looks like | Covered by Block Public Access? |
|---|---|---|
| Bucket policy | "Principal": "*" (or {"AWS": "*"}) without a condition that fixes the caller to known accounts, VPCs or IPs |
yes: BlockPublicPolicy rejects new ones, RestrictPublicBuckets neutralises existing ones |
| ACL on the bucket or objects | grantee group AllUsers (anyone) or AuthenticatedUsers (any AWS account) |
yes: BlockPublicAcls rejects new ones, IgnorePublicAcls ignores existing ones; Object Ownership "bucket owner enforced" disables ACLs entirely |
| Cross-account grant | policy naming another account | no: it isn't "public", it is shared. Review with external-access findings |
| Presigned URL | a URL with a signature, valid up to 7 days for SigV4 (and never longer than the credentials that signed it, so a role session's URL dies with the session) | no: anyone with the URL can use it until it expires |
| Website / CDN origin | static website hosting or a CDN in front of a public bucket | depends; use origin access control instead of a public bucket |
The four Block Public Access settings exist at account, bucket and access point level (and, through an AWS Organizations S3 policy, for a whole organisation, all four together); S3 applies the most restrictive combination. The Azure and GCP equivalents work the same way: a storage-account or organisation-level switch that overrides container or bucket settings (allUsers and allAuthenticatedUsers are GCP's public members).
An exposure evaluator
The program decides, for each bucket of the lab account, whether anonymous users can read it and through which path, following the documented S3 rules in simplified form: a policy statement is public when it allows * and its conditions don't pin the caller; RestrictPublicBuckets limits a public policy to the owner account and AWS services; IgnorePublicAcls makes public ACL grants count for nothing.
PINNING_KEYS = {"aws:SourceIp", "aws:SourceVpce", "aws:SourceVpc", "aws:PrincipalOrgID", "aws:PrincipalAccount",
"aws:SourceAccount", "aws:SourceArn"}
def public_statements(policy):
out = []
for st in (policy or {}).get("Statement", []):
p = st.get("Principal")
if st["Effect"] == "Allow" and (p == "*" or p == {"AWS": "*"}):
keys = {k for tests in st.get("Condition", {}).values() for k in tests}
if not keys & PINNING_KEYS:
out.append(st.get("Sid", "?"))
return out
def effective(bucket, account_bpa):
bpa = {k: bucket["bpa"].get(k, False) or account_bpa.get(k, False)
for k in ("BlockPublicAcls", "IgnorePublicAcls", "BlockPublicPolicy", "RestrictPublicBuckets")}
paths = []
pub = public_statements(bucket.get("policy"))
if pub:
paths.append(f"policy {pub} " + ("(neutralised by RestrictPublicBuckets)" if bpa["RestrictPublicBuckets"] else "-> PUBLIC"))
acl_public = [g for g in bucket.get("acl", []) if g in ("AllUsers", "AuthenticatedUsers")]
if acl_public:
if bucket.get("ownership") == "BucketOwnerEnforced":
paths.append(f"ACL {acl_public} (ACLs disabled)")
elif bpa["IgnorePublicAcls"]:
paths.append(f"ACL {acl_public} (ignored by IgnorePublicAcls)")
else:
paths.append(f"ACL {acl_public} -> PUBLIC")
verdict = "PUBLIC" if any(p.endswith("PUBLIC") for p in paths) else "not public"
return verdict, paths, [k for k, v in bpa.items() if not v]
account_bpa = {"BlockPublicAcls": True, "IgnorePublicAcls": True, "BlockPublicPolicy": False, "RestrictPublicBuckets": False}
buckets = {
"lab-public-site": {"bpa": {}, "policy": {"Statement": [
{"Sid": "Website", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::lab-public-site/*"}]}},
"lab-app-uploads": {"bpa": {}, "ownership": "ObjectWriter", "acl": ["AllUsers"], "policy": {"Statement": [
{"Sid": "OfficeOnly", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::lab-app-uploads/*",
"Condition": {"IpAddress": {"aws:SourceIp": "192.0.2.0/24"}}}]}},
"lab-backups": {"bpa": {"RestrictPublicBuckets": True}, "policy": {"Statement": [
{"Sid": "Legacy", "Effect": "Allow", "Principal": {"AWS": "*"}, "Action": ["s3:GetObject", "s3:ListBucket"], "Resource": "*"}]}},
"lab-exports": {"bpa": {}, "ownership": "BucketOwnerEnforced", "acl": ["AuthenticatedUsers"], "policy": {"Statement": [
{"Sid": "AnyAwsUser", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::lab-exports/*",
"Condition": {"StringEquals": {"s3:ExistingObjectTag/classification": "public"}}}]}},
}
for name, b in buckets.items():
verdict, paths, off = effective(b, account_bpa)
print(f"{name:16} {verdict:10} BPA off: {', '.join(off) or 'none'}")
for p in paths:
print(f"{'':16} {p}")lab-public-site PUBLIC BPA off: BlockPublicPolicy, RestrictPublicBuckets
policy ['Website'] -> PUBLIC
lab-app-uploads not public BPA off: BlockPublicPolicy, RestrictPublicBuckets
ACL ['AllUsers'] (ignored by IgnorePublicAcls)
lab-backups not public BPA off: BlockPublicPolicy
policy ['Legacy'] (neutralised by RestrictPublicBuckets)
lab-exports PUBLIC BPA off: BlockPublicPolicy, RestrictPublicBuckets
policy ['AnyAwsUser'] -> PUBLIC
ACL ['AuthenticatedUsers'] (ACLs disabled)
lab-public-siteis public on purpose: a static site. The finding is the method: a public bucket is the old way; a CDN with origin access control keeps the bucket private.lab-app-uploadshas anAllUsersACL, but the account'sIgnorePublicAclsneutralises it, and its policy pins the caller to the office range. Not public; the ACL should still be removed and ownership set toBucketOwnerEnforced.lab-backupshas a policy that would make every backup world-readable; only the bucket-levelRestrictPublicBucketsholds it back. A latent finding of the highest severity: one setting from a data breach.lab-exportsis the subtle one: the condition on an object tag doesn't pin who the caller is, so every object taggedpublicis readable by anyone. Whether that's intended is a question for the data owner.
The same review before deployment
IaC scanners check the Block Public Access configuration of every bucket. Here Trivy reviews the Terraform for lab-app-uploads in two versions: as first written, and after the fix. The session runs in your sandbox on local files only.
mkdir before after
cat > before/s3.tf <<'TF'
resource "aws_s3_bucket" "uploads" {
bucket = "lab-app-uploads"
}
resource "aws_s3_bucket_policy" "uploads" {
bucket = aws_s3_bucket.uploads.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Sid = "PublicRead"
Effect = "Allow"
Principal = "*"
Action = "s3:GetObject"
Resource = "arn:aws:s3:::lab-app-uploads/*"
}]
})
}
TF
cat > after/s3.tf <<'TF'
resource "aws_s3_bucket" "uploads" {
bucket = "lab-app-uploads"
}
resource "aws_s3_bucket_public_access_block" "uploads" {
bucket = aws_s3_bucket.uploads.id
block_public_acls = true
ignore_public_acls = true
block_public_policy = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_server_side_encryption_configuration" "uploads" {
bucket = aws_s3_bucket.uploads.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
kms_master_key_id = "arn:aws:kms:eu-west-1:123456789012:key/11111111-2222-3333-4444-555555555555"
}
}
}
resource "aws_s3_bucket_versioning" "uploads" {
bucket = aws_s3_bucket.uploads.id
versioning_configuration { status = "Enabled" }
}
resource "aws_s3_bucket_logging" "uploads" {
bucket = aws_s3_bucket.uploads.id
target_bucket = "lab-access-logs-123456789012"
target_prefix = "uploads/"
}
TF
for d in before after; do
echo "== $d: $(trivy config -q -f json $d | jq '[.Results[].Misconfigurations[]?] | length') findings"
trivy config -q -f json $d | jq -r '[.Results[].Misconfigurations[]?] | sort_by(.ID)[] | " \(.Severity) \(.ID) \(.Title)"'
done== before: 8 findings
HIGH AWS-0086 S3 Access block should block public ACL
HIGH AWS-0087 S3 Access block should block public policy
LOW AWS-0089 S3 Bucket Logging
MEDIUM AWS-0090 S3 Data should be versioned
HIGH AWS-0091 S3 Access Block should Ignore Public ACL
HIGH AWS-0093 S3 Access block should restrict public bucket to limit access
LOW AWS-0094 S3 buckets should each define an aws_s3_bucket_public_access_block
HIGH AWS-0132 S3 encryption should use Customer Managed Keys
== after: 0 findings
The "before" version fails the four Block Public Access checks and the check that a block exists at all, plus encryption with a customer-managed key, versioning and logging. The fixed version passes. Note what the scanner checked: the presence of Block Public Access, not the policy text. It didn't say "this policy is public"; the Python evaluator did. Use both: scanners for the guardrails, an evaluator (or the provider's analyser) for what the policies actually grant.
How exposure is detected
- Inventory and evaluate every bucket's effective access (above), plus IAM Access Analyzer's findings for public and cross-account buckets, and the console's "Public" labels. Azure: storage accounts with
allowBlobPublicAccess = trueand containers with access levelbloborcontainer; GCP: buckets withallUsersorallAuthenticatedUsersbindings. - CloudTrail management events for changes that open access:
PutBucketPolicy,PutBucketAcl,PutObjectAcl,DeleteBucketPublicAccessBlock,PutBucketPublicAccessBlockwith any settingfalse,PutAccountPublicAccessBlock. - S3 server access logs or data events with anonymous requesters (
requester-in access logs,userIdentity.accountIdanonymousin CloudTrail S3 data events, as in AWS's own Athena example) show public access being used.
How it is fixed
- Turn on all four Block Public Access settings at the account level (and organisation-wide with an Organizations S3 policy, or an SCP denying
s3:PutAccountPublicAccessBlock), with documented exceptions only. - Set Object Ownership to bucket owner enforced (ACLs disabled) on every bucket, after replacing any ACL-based grants with policies.
- Serve public content through a CDN with origin access control; share data with partners by exact account or role, not
*. - Prefer short-lived presigned URLs (minutes, not days) and generate them from a role that can only read the intended prefix.
Pitfalls
- Turning on
BlockPublicPolicyand assuming existing public policies are fixed: it only blocks new ones;RestrictPublicBucketshandles the existing ones. - Conditions that look restrictive but don't pin the caller (object tags,
s3:prefix,aws:UserAgent,aws:Referer, which anyone can set), and pinning conditions with values too wide to pin anything: S3 still treats anaws:SourceIprange broader than/8(IPv4) as public. AuthenticatedUsersmeaning "any AWS account in the world", not "users of our account".
Practice
1. Set the account's RestrictPublicBuckets to True. Which verdicts change?
lab-public-site and lab-exports become "not public" (their public policies are neutralised). The website would stop working, which is why the static site should move behind a CDN with origin access control before the switch is flipped.
2. Replace lab-exports' condition with {"StringEquals": {"aws:PrincipalOrgID": "o-lab0example"}}. Public or not, and why?
Not public: aws:PrincipalOrgID pins the caller to principals of your organisation, so the statement is no longer "anyone".
3. Which CloudTrail event would you alert on to catch someone turning off the protection of lab-backups?
PutBucketPublicAccessBlock with RestrictPublicBuckets false, or DeleteBucketPublicAccessBlock on lab-backups, from any principal other than the IaC pipeline; with the latent policy in place it is a near-certain data exposure.
Test yourself
Why is lab-backups not public today?
- Its policy has a condition
- The bucket-level RestrictPublicBuckets setting neutralises its public policy
- ACLs are disabled
- It is encrypted
Which condition key pins the caller and makes a Principal * statement non-public?
- aws:UserAgent
- s3:ExistingObjectTag/...
- aws:PrincipalOrgID
- aws:Referer
What did Trivy check in the 'before' Terraform?
- That the policy text is public
- That Block Public Access, encryption, versioning and logging are configured
- That the bucket name is unique
- Nothing
Does BlockPublicPolicy fix a public bucket policy that already exists?
- Yes, it deletes it
- No: it only rejects new public policies; RestrictPublicBuckets neutralises existing ones
- Only for ACLs
- Only in us-east-1