Make S3 static website accessible to Cloudfront Only Permissions

0

I'm hosting a static website in an S3 bucket. I am attempting to limit access permissions to cloudfront only. My current configuration:

{
	"Version": "2008-10-17",
	"Id": "PolicyForCloudFrontPrivateContent",
	"Statement": [
		{
			"Sid": "AllowCloudFrontServicePrincipal",
			"Effect": "Allow",
			"Principal": {
				"Service": "cloudfront.amazonaws.com"
			},
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::MYBUCKET/*",
			"Condition": {
				"StringEquals": {
					"AWS:SourceArn": "DISTRIBUTION_ARN/"
				}
			}
		}
	]
}

But this does not allow cloudfront access and returns a 403 Forbidden error. How can I fix this?

1개 답변
0
수락된 답변

You haven't mentioned whether you're trying to use Origin Access Control (OAC), or Origin Access Identity (OAI - legacy).

However, the policy that you've provided looks almost correct for OAC, except for the Condition key which should look like this (no trailing slash):

AWS:SourceArn": "arn:aws:cloudfront::<AWS account ID>:distribution/<CloudFront distribution ID>"

Please take a look at the documentation for more information, particularly the section on SSE-KMS, if you're using that on your bucket

Note also that in the Cloudfront Origin settings, there's an option to copy a pre-populated policy statement that you can insert into your S3 bucket policy.

AWS
전문가
Paul_L
답변함 일 년 전
profile picture
전문가
검토됨 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠