Skip to content

Instantly share code, notes, and snippets.

@mohakevin
Forked from magnetikonline/README.md
Created September 16, 2016 22:33
Show Gist options
  • Save mohakevin/2714da930b5c2bc7e74a03a84c31f9a0 to your computer and use it in GitHub Desktop.
Save mohakevin/2714da930b5c2bc7e74a03a84c31f9a0 to your computer and use it in GitHub Desktop.
AWS S3 bucket policy recipes.

AWS S3 bucket policy recipes

Anonymous GET access

Type: bucket

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Action": [
				"s3:GetObject"
			],
			"Effect": "Allow",
			"Principal": {
				"AWS": [
					"*"
				]
			},
			"Resource": [
				"arn:aws:s3:::BUCKET_NAME/*"
			]
		}
	]
}

Anonymous GET access match HTTP referrer

Type: bucket

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Action": [
				"s3:GetObject"
			],
			"Condition": {
				"StringLike": {
					"aws:Referer": [
						"http://domain.com/*",
						"http://www.domain.com/*"
					]
				}
			},
			"Effect": "Allow",
			"Principal": {
				"AWS": [
					"*"
				]
			},
			"Resource": [
				"arn:aws:s3:::BUCKET_NAME/*"
			]
		}
	]
}

Full access for specific IAM user/role

Type: bucket

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Action": [
				"s3:*"
			],
			"Effect": "Allow",
			"Principal": {
				"AWS": [
					"arn:aws:iam::ACCOUNT_NUMBER:user/USERNAME_A",
					"arn:aws:iam::ACCOUNT_NUMBER:user/USERNAME_B",
					"arn:aws:iam::ACCOUNT_NUMBER:user/USERNAME_C",
					"arn:aws:iam::ACCOUNT_NUMBER:role/ROLE_A",
					"arn:aws:iam::ACCOUNT_NUMBER:role/ROLE_B",
					"arn:aws:iam::ACCOUNT_NUMBER:role/ROLE_C"
				]
			},
			"Resource": [
				"arn:aws:s3:::BUCKET_NAME",
				"arn:aws:s3:::BUCKET_NAME/*"
			]
		}
	]
}

Full access (and S3 weblogin) for specific IAM users

Type: group/user

Note: specifying both arn:aws:s3:::BUCKET_NAME and arn:aws:s3:::BUCKET_NAME/* under the "Resource" block allows the IAM user to list objects at the root level of the bucket.

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Action": [
				"s3:ListAllMyBuckets"
			],
			"Effect": "Allow",
			"Resource": [
				"arn:aws:s3:::*"
			]
		},
		{
			"Action": [
				"s3:*"
			],
			"Effect": "Allow",
			"Resource": [
				"arn:aws:s3:::BUCKET_NAME",
				"arn:aws:s3:::BUCKET_NAME/*"
			]
		}
	]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment