How to require CloudFront URL signing based on S3 object permission

0

I am serving images from S3 and want to migrate to CloudFront. The S3 bucket is ACL-enabled. Some files are made public (ACL: public-read) and some are private, so they can be accessed like (where public files don't require signature):

But when I set up CloudFront for this S3 bucket:

  1. If I don't restrict viewer access (in Behavior setting), both public and private files can be accessed without signature.
  2. If I restrict viewer access using the key pair, then both types require signature in the URLs.

Is it possible to set up this as S3 does, which means, requires signature based on the ACL of the objects in S3?

2 Answers
0

Yes, it is possible to configure CloudFront to require signatures based on the ACL of the objects in S3.

To achieve this, you can use CloudFront's Origin Access Identity (OAI) feature. This feature allows you to create a special CloudFront user that can access your S3 bucket, while denying access to all other users.

setup instruction:

Create a new CloudFront distribution and set your S3 bucket as the origin.

In the "Origin Access Identity" section of the distribution settings, create a new identity and grant it read access to your S3 bucket.

In the S3 bucket permissions, update the bucket policy to grant read access to the CloudFront OAI.

Configure your CloudFront distribution to require signed URLs or cookies, depending on your requirements.

With this setup, CloudFront will only allow access to objects in your S3 bucket if the request is made through the CloudFront distribution and includes the required signature. Public objects in your S3 bucket will still be accessible without a signature, while private objects will only be accessible through the CloudFront distribution with the required signature.

AWS
answered a year ago
0

Thank you for answering!

I have a question about this: "Configure your CloudFront distribution to require signed URLs or cookies" At this point, all URLs with the CloudFront URL will require signature, is that right?

What I would like: public -> https://123.cloudfront.net/public.jpg private -> https://123.cloudfront.net/private.jpg?[Signature_of_CloudFront]

But requiring signed URLs would affect both public/private URLs. I cannot just replace the hostname of S3 with CloudFront. Is there a solution? Thanks!

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions