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 Risposta
0
Risposta accettata

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
ESPERTO
Paul_L
con risposta un anno fa
profile picture
ESPERTO
verificato un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande