Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 53Security · AWS

How to find public S3 buckets

A public S3 bucket is one of the most common cloud data leaks: customer files, backups or logs that anyone on the internet can list and download. New buckets are private by default since 2023, but old buckets, old accounts and "quick fixes" are still out there. This how-to checks the account-wide guard first, then every bucket (policy, ACL, Block Public Access), uses IAM Access Analyzer to find all outside access, and closes what should not be open.

  • 5 Lessen
  • 4 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

53.1

The quick answer

aws s3control get-public-access-block --account-id 111122223333
for b in $(aws s3api list-buckets --query 'Buckets[].Name' --output text); do printf '%s ' "$b"; aws s3api get-bucket-policy-status --bucket "$b" --query 'PolicyStatus.IsPublic' --output text 2>/dev/null || echo "no-policy"; done
aws s3control put-public-access-block --account-id 111122223333 --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

The last line blocks public access for all buckets of the account — run it only after you checked that no bucket must be public (for example a static website without CloudFront).

53.2

Step by step

  1. Account-wide Block Public Access — the strongest guard:
aws s3control get-public-access-block --account-id 111122223333
{
    "PublicAccessBlockConfiguration": {
        "BlockPublicAcls": true,
        "IgnorePublicAcls": true,
        "BlockPublicPolicy": true,
        "RestrictPublicBuckets": true
    }
}

All four true = no bucket in this account can be public. NoSuchPublicAccessBlockConfiguration = not set — check every bucket.

  1. Check each bucket — three places can make it public:
CheckCommand
Bucket-level Block Public Accessaws s3api get-public-access-block --bucket B
Bucket policy is public?aws s3api get-bucket-policy-status --bucket B → IsPublic
ACL gives access to AllUsers / AuthenticatedUsersaws s3api get-bucket-acl --bucket B
aws s3api get-bucket-acl --bucket acme-old-exports --query "Grants[?Grantee.URI!=null].[Grantee.URI,Permission]" --output text
http://acs.amazonaws.com/groups/global/AllUsers   READ

AllUsers READ = anyone can list the bucket.

  1. Find every kind of outside access with IAM Access Analyzer (public and other accounts):
aws accessanalyzer create-analyzer --analyzer-name account-analyzer --type ACCOUNT
aws accessanalyzer list-findings --analyzer-arn arn:aws:access-analyzer:eu-central-1:111122223333:analyzer/account-analyzer --filter '{"resourceType":{"eq":["AWS::S3::Bucket"]},"status":{"eq":["ACTIVE"]}}' --query 'findings[].[resource,isPublic]' --output text
  1. Test from outside (no credentials) — what does the internet see?
curl -s -o /dev/null -w '%{http_code}\n' https://acme-old-exports.s3.amazonaws.com/
403

200 with an XML file list = publicly listable.

  1. Close it — per bucket, or for the whole account:
aws s3api put-public-access-block --bucket acme-old-exports --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
aws s3api put-bucket-ownership-controls --bucket acme-old-exports --ownership-controls 'Rules=[{ObjectOwnership=BucketOwnerEnforced}]'

BucketOwnerEnforced turns ACLs off completely. A website that must stay public: serve it through CloudFront with Origin Access Control, keep the bucket private.

  1. Keep it closed: an SCP or Organization policy that forbids turning off Block Public Access, AWS Config / Security Hub controls for public buckets, and regular scans (for example Prowler or Trivy's AWS scanning).

53.3

Check that it worked

The account block shows four true, every bucket shows IsPublic = False, Access Analyzer has no active public findings, and the curl from outside returns 403.

Commando's in deze les

53.4

Common problems

ProblemCauseFix
NoSuchPublicAccessBlockConfigurationNever set on the account or bucket.Set it (step 5) after checking.
A website broke after blockingIt was served directly from a public bucket.Move to CloudFront + OAC; keep the bucket private.
AccessDenied on get-bucket-aclYour role can not read bucket settings.Use a security/audit role with read rights.
Objects still downloadable after the fixA pre-signed URL (valid until it expires) or CloudFront cache.Wait for expiry; invalidate CloudFront; rotate if needed.
Many accounts to checkChecking one by one is slow.Access Analyzer with the organization as zone of trust; Security Hub across accounts.
Data was public for a whileIt may be copied already.Check S3 server access logs / CloudTrail data events; treat as a data incident.

53.5

Go further

1Which single setting stops every bucket in an account from becoming public?

Account-level S3 Block Public Access with all four options true.

2How should a public static website use S3 without a public bucket?

Serve it through CloudFront with Origin Access Control; the bucket stays private.

Alle commando's in dit hoofdstuk