Skip to content

Instantly share code, notes, and snippets.

@madhuakula
Forked from cktricky/review_s3_buckets.py
Created March 10, 2017 07:15
Show Gist options
  • Save madhuakula/f246dcd6dda3f6cf798362a7daa4cce6 to your computer and use it in GitHub Desktop.
Save madhuakula/f246dcd6dda3f6cf798362a7daa4cce6 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