带有服务器端加密 s3 存储桶的 AWS cloudfront
AWS cloudfront with server-side encrypted s3 bucket
(这是 上的 generalization/variation,基于我在解决这个问题时学到的知识。)
我将 AWS Cloudfront 与 S3 源一起使用(即服务于 S3 对象)。
我想将 server-side encryption 添加到我的存储桶,但仍然能够通过云端访问这些对象。
我不知道所使用的精确 SSE 策略(只要它是安全的)。
如果您对 SSE 加密类型有自由度,则可以在不使用 lambda 的情况下添加 SSE。
关键是将bucket上的加密类型设置为SSE-S3
(Amazon S3 Key)。
主要步骤是:
- 在属性(选项卡)~> 默认加密(面板)~> 编辑(按钮)中将存储桶加密设置为
SSE-S3
- 创建云端分发
- Link 通过 Origin Access Identity
的存储桶和云端分布
- 添加将源访问标识链接到存储桶的存储桶策略。
在文章 "Serving SSE-KMS encrypted content from S3 using CloudFront" 之后,这里是与此分布相对应的替代 CloudFormation 堆栈:
Resources:
S3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Join
- "-"
- - !Ref "AWS::StackName"
- s3bucket
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
S3BucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Statement:
- Action:
- "s3:GetObject"
Effect: Allow
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref S3Bucket
- /*
Principal:
CanonicalUser:
Fn::GetAtt: [OAI, S3CanonicalUserId]
OAI:
Type: "AWS::CloudFront::CloudFrontOriginAccessIdentity"
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: Origin Access Identity for S3
Cloudfront:
Type: "AWS::CloudFront::Distribution"
Properties:
DistributionConfig:
Comment: How to serve content encrypted with SSE-S3 from S3 using CloudFront
Origins:
- DomainName: !Join
- .
- - !Ref S3Bucket
- s3
- !Ref "AWS::Region"
- amazonaws.com
Id: S3-regional-endpoint
S3OriginConfig:
OriginAccessIdentity: !Join
- /
- - origin-access-identity
- cloudfront
- !Ref OAI
DefaultCacheBehavior:
TargetOriginId: S3-regional-endpoint
ForwardedValues:
QueryString: "false"
ViewerProtocolPolicy: redirect-to-https
Enabled: "true"
- 相对于上面引用的文章,这需要指定源访问身份 (
OAI
) 以及存储桶策略 (S3BucketPolicy
),但不需要 KMS 资源。
- 在 CloudFormation 和 terraform 中,您可以通过指定
AES256
将加密类型指定为 SSE-S3
(参见第 SSEAlgorithm: AES256
行)。
如果您使用的是 terraform,有一些模块(例如 here and here)基本上可以通过一些额外的好处来完成上述工作。
(这是
我将 AWS Cloudfront 与 S3 源一起使用(即服务于 S3 对象)。
我想将 server-side encryption 添加到我的存储桶,但仍然能够通过云端访问这些对象。
我不知道所使用的精确 SSE 策略(只要它是安全的)。
如果您对 SSE 加密类型有自由度,则可以在不使用 lambda 的情况下添加 SSE。
关键是将bucket上的加密类型设置为SSE-S3
(Amazon S3 Key)。
主要步骤是:
- 在属性(选项卡)~> 默认加密(面板)~> 编辑(按钮)中将存储桶加密设置为
SSE-S3
- 创建云端分发
- Link 通过 Origin Access Identity 的存储桶和云端分布
- 添加将源访问标识链接到存储桶的存储桶策略。
在文章 "Serving SSE-KMS encrypted content from S3 using CloudFront" 之后,这里是与此分布相对应的替代 CloudFormation 堆栈:
Resources:
S3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Join
- "-"
- - !Ref "AWS::StackName"
- s3bucket
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
S3BucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Statement:
- Action:
- "s3:GetObject"
Effect: Allow
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref S3Bucket
- /*
Principal:
CanonicalUser:
Fn::GetAtt: [OAI, S3CanonicalUserId]
OAI:
Type: "AWS::CloudFront::CloudFrontOriginAccessIdentity"
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: Origin Access Identity for S3
Cloudfront:
Type: "AWS::CloudFront::Distribution"
Properties:
DistributionConfig:
Comment: How to serve content encrypted with SSE-S3 from S3 using CloudFront
Origins:
- DomainName: !Join
- .
- - !Ref S3Bucket
- s3
- !Ref "AWS::Region"
- amazonaws.com
Id: S3-regional-endpoint
S3OriginConfig:
OriginAccessIdentity: !Join
- /
- - origin-access-identity
- cloudfront
- !Ref OAI
DefaultCacheBehavior:
TargetOriginId: S3-regional-endpoint
ForwardedValues:
QueryString: "false"
ViewerProtocolPolicy: redirect-to-https
Enabled: "true"
- 相对于上面引用的文章,这需要指定源访问身份 (
OAI
) 以及存储桶策略 (S3BucketPolicy
),但不需要 KMS 资源。 - 在 CloudFormation 和 terraform 中,您可以通过指定
AES256
将加密类型指定为SSE-S3
(参见第SSEAlgorithm: AES256
行)。
如果您使用的是 terraform,有一些模块(例如 here and here)基本上可以通过一些额外的好处来完成上述工作。