CSP for AWS Cloudfront Lambda@Edge
- In AWS, set up a static site hosted in an S3 bucket.
- Set the permissions on the S3 bucket to include a public access policy and Cloudfront Object Access Identity.
- Set up Cloudfront to serve the content in the S3 bucket.
- Goto Lambda and make sure you’re in US-East-1
- Create a new function, make it Node.js.6.10
- Dump in your CSP.js, configured to do what you want. Note: start small and build your policy gradually.
- Save your code.
- Publish your code and make a note of the ARN (including version number).
- Select Cloudfront as a trigger, select Origin-Response, select the distribution that you’re going to use, hit the checkbox to say that you are ok with this, hit add and then go back to the top and hit save.
- Wait for the distribution to redeploy.
- Consider invalidating your origin objects if you’re impatient!
- Goto Mozilla Observatory Mozilla Observatory and test your policy.