Skip to content

Instantly share code, notes, and snippets.

@cktricky
Created January 25, 2017 17:11
Show Gist options
  • Save cktricky/faf0f40116e535a055b7412458136917 to your computer and use it in GitHub Desktop.
Save cktricky/faf0f40116e535a055b7412458136917 to your computer and use it in GitHub Desktop.
Review S3 Bucket Policies
import boto3
import pprint
# MAKE SURE YOU CHANGE THESE VALUES OR THE TOOL WON'T WORK.
access_key_id = 'replace me'
secret_access_key = 'replace me'
'''
WORK IN PROGRESS, NOT COMPLETED
This file is used to review s3 bucket permissions and whether or not they are encrypted
'''
pp = pprint.PrettyPrinter(indent=5, width=80, compact=False)
regions = ['us-east-1', 'us-west-2', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'eu-central-1', 'eu-west-1']
client = boto3.client(
's3',
aws_access_key_id = access_key_id,
aws_secret_access_key = secret_access_key,
region_name='us-east-1'
)
response = client.list_buckets()
#print(response)
for bucket in response['Buckets']:
try:
acl = client.get_bucket_policy(Bucket=bucket['Name'])
print(bucket['Name'] + "Policy: ")
pp.pprint(acl['Policy'])
except:
print(bucket['Name'] + "Has no policy")
print("\n---------\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment