Created
January 15, 2018 15:12
-
-
Save pacohope/f881a0709828c117d0e7c63ed02553f1 to your computer and use it in GitHub Desktop.
Very tightly locked down S3 bucket policy. IP address restriction. Encryption required. Public objects denied.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "DenyUnencryptedObjectUploads", | |
"Effect": "Deny", | |
"Principal": "*", | |
"Action": "s3:PutObject", | |
"Resource": [ | |
"arn:aws:s3:::BUCKETNAME/*", | |
"arn:aws:s3:::BUCKETNAME" | |
], | |
"Condition": { | |
"StringNotEquals": { | |
"s3:x-amz-server-side-encryption": "aws:kms" | |
} | |
} | |
}, | |
{ | |
"Sid": "DenyEncryptedWithWrongKMSKey", | |
"Effect": "Deny", | |
"Principal": "*", | |
"Action": "s3:PutObject", | |
"Resource": [ | |
"arn:aws:s3:::BUCKETNAME/*", | |
"arn:aws:s3:::BUCKETNAME" | |
], | |
"Condition": { | |
"StringNotEquals": { | |
"s3:x-amz-server-side-encryption-aws-kms-key-id": "arn:aws:kms:REGION:xxxxxxxxxxxx:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | |
} | |
} | |
}, | |
{ | |
"Sid": "DenyPuttingPublicObjects", | |
"Effect": "Deny", | |
"Principal": { | |
"AWS": "*" | |
}, | |
"Action": [ | |
"s3:PutObject", | |
"s3:PutObjectAcl" | |
], | |
"Resource": [ | |
"arn:aws:s3:::BUCKETNAME/*", | |
"arn:aws:s3:::BUCKETNAME" | |
], | |
"Condition": { | |
"StringEquals": { | |
"s3:x-amz-acl": [ | |
"public-read", | |
"public-read-write", | |
"authenticated-read" | |
] | |
} | |
} | |
}, | |
{ | |
"Sid": "DenyGrantingPublicRead", | |
"Effect": "Deny", | |
"Principal": { | |
"AWS": "*" | |
}, | |
"Action": [ | |
"s3:PutObject", | |
"s3:PutObjectAcl" | |
], | |
"Resource": [ | |
"arn:aws:s3:::BUCKETNAME/*", | |
"arn:aws:s3:::BUCKETNAME" | |
], | |
"Condition": { | |
"StringLike": { | |
"s3:x-amz-grant-read": [ | |
"*http://acs.amazonaws.com/groups/global/AllUsers*", | |
"*http://acs.amazonaws.com/groups/global/AuthenticatedUsers*" | |
] | |
} | |
} | |
}, | |
{ | |
"Sid": "DenyNotMySourceIP", | |
"Effect": "Deny", | |
"Principal": "*", | |
"Action": "s3:*", | |
"Resource": "arn:aws:s3:::BUCKETNAME/*", | |
"Condition": { | |
"NotIpAddress": { | |
"aws:SourceIp": [ | |
"1.2.3.4", | |
"192.168.1.0/24", | |
"172.16.0.0/16", | |
"10.0.0.0/8" | |
] | |
} | |
} | |
}, | |
{ | |
"Sid": "AllowMySourceIP", | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": "s3:*", | |
"Resource": "arn:aws:s3:::BUCKETNAME/*", | |
"Condition": { | |
"IpAddress": { | |
"aws:SourceIp": [ | |
"1.2.3.4", | |
"192.168.1.0/24", | |
"172.16.0.0/16", | |
"10.0.0.0/8" | |
] | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment