-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloudfront): s3 origin access control (#31150)
### Issue # (if applicable) n/a ### Reason for this change Note: This PR is a WIP, not merging to the main branch. Merging to a feature branch first to facilitate smaller PR reviews. Support OAC for S3 origins, see [RFC](aws/aws-cdk-rfcs#624) for more details ### Description of changes - Deprecate `CloudFrontWebDistribution` in favour of existing class `Distribution` - Add new abstract base class `OriginAccessControlBase` and subclass `S3OriginAccessControl` - Deprecate `S3Origin` in favour of new classes `S3BucketOrigin` and `S3StaticWebsiteOrigin` - Add new abstract class `S3BucketOrigin` - 3 static functions for instantiating S3 origin with OAI, OAC and no origin access control (using bucket defaults) - Add new class `S3StaticWebsiteOrigin` - Update README for `cloudfront` and `cloudfront-origins` ### Description of how you validated changes - `integ.s3-origin-oac`: basic use case setting up a distribution with an S3 origin with OAC, using assertions to check the distribution has the oac configured and the oac has the expected default properties - unit tests for `S3OriginAccessControl` (more tests to follow in coming PRs) ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
23 changed files
with
33,754 additions
and
20 deletions.
There are no files selected for viewing
31,546 changes: 31,546 additions & 0 deletions
31,546
...ot/asset.3cef2cdbb46b3821e641ffb8b9af9731af5f7e4a9e857ab633dbcd9023de724d.bundle/index.js
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
.../framework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac.js.snapshot/cdk.out
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...udfront-origins/test/integ.s3-origin-oac.js.snapshot/cloudfront-s3-origin-oac.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
158 changes: 158 additions & 0 deletions
158
...front-origins/test/integ.s3-origin-oac.js.snapshot/cloudfront-s3-origin-oac.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
{ | ||
"Resources": { | ||
"Bucket83908E77": { | ||
"Type": "AWS::S3::Bucket", | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"BucketPolicyE9A3008A": { | ||
"Type": "AWS::S3::BucketPolicy", | ||
"Properties": { | ||
"Bucket": { | ||
"Ref": "Bucket83908E77" | ||
}, | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "s3:GetObject", | ||
"Condition": { | ||
"StringEquals": { | ||
"AWS:SourceArn": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":cloudfront::", | ||
{ | ||
"Ref": "AWS::AccountId" | ||
}, | ||
":distribution/", | ||
{ | ||
"Ref": "Distribution830FAC52" | ||
} | ||
] | ||
] | ||
} | ||
} | ||
}, | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "cloudfront.amazonaws.com" | ||
}, | ||
"Resource": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
{ | ||
"Fn::GetAtt": [ | ||
"Bucket83908E77", | ||
"Arn" | ||
] | ||
}, | ||
"/*" | ||
] | ||
] | ||
}, | ||
"Sid": "GrantCloudFrontOACAccessToS3Origin" | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
}, | ||
"DistributionOrigin1S3OriginAccessControlEB606076": { | ||
"Type": "AWS::CloudFront::OriginAccessControl", | ||
"Properties": { | ||
"OriginAccessControlConfig": { | ||
"Name": "cloudfronts3originoacDistribOrigin1S3OriginAccessControl48F3BA9D", | ||
"OriginAccessControlOriginType": "s3", | ||
"SigningBehavior": "always", | ||
"SigningProtocol": "sigv4" | ||
} | ||
} | ||
}, | ||
"Distribution830FAC52": { | ||
"Type": "AWS::CloudFront::Distribution", | ||
"Properties": { | ||
"DistributionConfig": { | ||
"DefaultCacheBehavior": { | ||
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6", | ||
"Compress": true, | ||
"TargetOriginId": "cloudfronts3originoacDistributionOrigin12695E2FC", | ||
"ViewerProtocolPolicy": "allow-all" | ||
}, | ||
"Enabled": true, | ||
"HttpVersion": "http2", | ||
"IPV6Enabled": true, | ||
"Origins": [ | ||
{ | ||
"DomainName": { | ||
"Fn::GetAtt": [ | ||
"Bucket83908E77", | ||
"RegionalDomainName" | ||
] | ||
}, | ||
"Id": "cloudfronts3originoacDistributionOrigin12695E2FC", | ||
"OriginAccessControlId": { | ||
"Fn::GetAtt": [ | ||
"DistributionOrigin1S3OriginAccessControlEB606076", | ||
"Id" | ||
] | ||
}, | ||
"S3OriginConfig": { | ||
"OriginAccessIdentity": "" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"ExportsOutputRefDistribution830FAC524DF81588": { | ||
"Value": { | ||
"Ref": "Distribution830FAC52" | ||
}, | ||
"Export": { | ||
"Name": "cloudfront-s3-origin-oac:ExportsOutputRefDistribution830FAC524DF81588" | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...amework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac.js.snapshot/integ.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
186 changes: 186 additions & 0 deletions
186
...work-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac.js.snapshot/manifest.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.