Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
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=trueThe 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).
Step by step
- 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.
- Check each bucket — three places can make it public:
| Check | Command |
|---|---|
| Bucket-level Block Public Access | aws 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 / AuthenticatedUsers | aws 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 READAllUsers READ = anyone can list the bucket.
- 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- 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/
403200 with an XML file list = publicly listable.
- 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.
- 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).
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.
Common problems
| Problem | Cause | Fix |
|---|---|---|
NoSuchPublicAccessBlockConfiguration | Never set on the account or bucket. | Set it (step 5) after checking. |
| A website broke after blocking | It was served directly from a public bucket. | Move to CloudFront + OAC; keep the bucket private. |
AccessDenied on get-bucket-acl | Your role can not read bucket settings. | Use a security/audit role with read rights. |
| Objects still downloadable after the fix | A pre-signed URL (valid until it expires) or CloudFront cache. | Wait for expiry; invalidate CloudFront; rotate if needed. |
| Many accounts to check | Checking one by one is slow. | Access Analyzer with the organization as zone of trust; Security Hub across accounts. |
| Data was public for a while | It may be copied already. | Check S3 server access logs / CloudTrail data events; treat as a data incident. |
Go further
- Command pages: aws, curl.
- Next how-tos: Copy files to and from S3, Log in to AWS with SSO, Remove a secret from Git history, Create a safe S3 bucket with Terraform, CloudTrail.
- Full guides: AWS CLI, Trivy, Checkov.
- Practise: Lab: multi-account guardrails with SCPs and a central log trail, Lab: a locked-down storage account (Azure).
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.