How can a Cloudfront distribution an AWS KMS key to GET an S3 image encrypted at rest?

徘徊边缘 提交于 2020-12-08 10:40:02

问题


I would like to use AWS's Server Side Encryption (SSE) with the AWS Key Management Service (KMS) to encrypt data at rest in S3. (See this AWS blog post detailing SSE-KMS.)

However, I also have the requirement that I use Cloudfront Presigned URLs.

How can I set up a Cloudfront distribution to use a key in AWS KMS to decrypt and use S3 objects encrypted at rest?

(This Boto3 issue seems to be from someone looking for the same answers as me, but with no results).


回答1:


This was previously not possible because CloudFront didn't support it and because (as I mentioned in comments on John's answer -- which was on the right track) there was no way to roll-your-own solution with Lambda@Edge because the X-Amz-Cf-Id request header --generated on the back side of CloudFront and visible only to S3, not to the trigger invocation -- would invalidate any signature you tried to add to the request inside a Lambda@Edge trigger, because signing of all X-Amz-* headers is mandatory.

But the X-Amz-Cf-Id header value is now exposed to a Lambda@Edge trigger function in the event structure -- not with the other request headers, but as a simple string attribute -- at event.Records[0].cf.config.requestId.

With that value in hand, you can use the execution role credentials and the built-in SDK in the Lambda@Edge environment to generate a signature and and add the necessary headers (including an Authorization header with the derived credential identifier and freshly-generated signature) to the request.

This setup does not use an Origin Access Identifier (OAI) because the Lambda@Edge trigger's IAM Execution Role is used instead of an OAI to persuade S3 that the request is authorized.

Achraf Souk has published an official AWS blog post explaining the solution from start to finish.

https://aws.amazon.com/blogs/networking-and-content-delivery/serving-sse-kms-encrypted-content-from-s3-using-cloudfront/




回答2:


Use S3 Presigned URLs. This AWS article discusses how to generate urls using Java, but this is easily ported to another language.

Server-Side Encryption with AWS Key Management Service (SSE-KMS)



来源:https://stackoverflow.com/questions/50166557/how-can-a-cloudfront-distribution-an-aws-kms-key-to-get-an-s3-image-encrypted-at

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!