Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Origin Access Control instead of deprecated OAI #298

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

otterley
Copy link
Contributor

Use Origin Access Control to allow CloudFront to authenticate to S3 for retrieving objects from the origin S3 bucket. This replaces the now-deprecated Origin Access Identity (OAI) mechanism.

Also add support for creating an S3 bucket for CloudFront access logging.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ottokruse
Copy link
Collaborator

Sorry mate this is on my list to look at but have been swamped.

QQ how well tested is this already?

@otterley
Copy link
Contributor Author

I've tested it myself, but YMMV. Users should be aware that updating their stacks to this latest version will delete the existing CloudFront Origin Access Identity and replace it with an Origin Access Control. So it would be helpful to test an upgrade scenario and provide upgrade instructions in the README, CHANGELOG, or similar document.

@ottokruse
Copy link
Collaborator

OK got it. I will also do some testing.

Another QQ, what's the reason for taking out the s3:ListBucket permission from the bucket policy?

The purpose of that was that CloudFront would see 404s from S3 in the case of non-existing objects, instead of 403. This is needed to enable SPA-routing:

@ottokruse
Copy link
Collaborator

Otherwise, tested myself, also an upgrade scenario from OAI, and works well!

@otterley
Copy link
Contributor Author

what's the reason for taking out the s3:ListBucket permission from the bucket policy? The purpose of that was that CloudFront would see 404s from S3 in the case of non-existing objects, instead of 403. This is needed to enable SPA-routing

Ignorance on my part combined with a bias for least-privilege access. I'll update the PR to restore it.

Use Origin Access Control to allow CloudFront to authenticate to S3 for
retrieving objects from the origin S3 bucket. This replaces the
now-deprecated Origin Access Identity (OAI) mechanism.

Also add support for creating an S3 bucket for CloudFront access logging.
@otterley otterley force-pushed the use-origin-access-control branch from 1726e4b to 1df6526 Compare October 24, 2024 19:33
@otterley
Copy link
Contributor Author

@ottokruse Can you take another look, please?

@ottokruse ottokruse merged commit f6fab45 into aws-samples:master Nov 13, 2024
@ottokruse
Copy link
Collaborator

Thanks for the PR, and the nudge!

@ottokruse
Copy link
Collaborator

Oops, just ran into:

+ sam publish --template packaged.yaml
Publish Failed
Error: The template contains unsupported resource types. [AWS::CloudFront::OriginAccessControl]
Please follow the instructions in https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-publishing-applications.html

And now see that AWS::CloudFront::OriginAccessControl is not on the List of Supported AWS Resources for the Serverless Repository.

Well, that is really, really, annoying.

Have logged an issue in the SAM repo: aws/serverless-application-model#3681

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants