Skip to content

Commit

Permalink
feat(cloudfront): s3 origin access control (#31150)
Browse files Browse the repository at this point in the history
### 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
gracelu0 authored Aug 19, 2024
2 parents c1c800e + 0acc247 commit 7e2dea7
Show file tree
Hide file tree
Showing 23 changed files with 33,754 additions and 20 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7e2dea7

Please sign in to comment.