Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created July 10, 2017 01:05
Show Gist options
  • Save chrisbrownie/07bfbec4718bce6ec6417c75bed720a4 to your computer and use it in GitHub Desktop.
Save chrisbrownie/07bfbec4718bce6ec6417c75bed720a4 to your computer and use it in GitHub Desktop.
Returns all publicly accessible S3 buckets to which the executor has access to view the ACL
#!/bin/bash
EMPTYGRANTS='{"Grants":[]}'
buckets=`aws s3api list-buckets --output json | jq -r '.Buckets[].Name'`
for bucket in $buckets; do
acl=`aws s3api get-bucket-acl --bucket $bucket --output json | jq -c 'del(.Owner) | .Grants |= map( select(.Grantee.URI == "http://acs.amazonaws.com/groups/global/AllUsers") )'`
if [ $acl != $EMPTYGRANTS ] ; then
echo "$bucket"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment