Skip to content

Instantly share code, notes, and snippets.

@angrychimp
Last active September 8, 2017 19:05
Show Gist options
  • Select an option

  • Save angrychimp/0d9b7c279794cbc3b68f21bfd664c3e3 to your computer and use it in GitHub Desktop.

Select an option

Save angrychimp/0d9b7c279794cbc3b68f21bfd664c3e3 to your computer and use it in GitHub Desktop.
Scan S3 buckets for public-read permissions
#!/bin/bash
# requires jq: https://stedolan.github.io/jq/
# requires aws-cli: http://docs.aws.amazon.com/cli/latest/userguide/installing.html
for bucket in `aws s3 ls | awk '{print $NF}'`; do
errors=$(expr $(aws s3api get-bucket-acl --bucket $bucket |
jq '.Grants | .[] | if (.Permission == "READ" and (.Grantee.URI == "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" or .Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers")) then "ERROR" else null end' |
grep ERROR |
wc -l))
if [[ $errors > 0 ]]; then
echo $bucket $errors
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment