Skip to content

Commit

Permalink
feat(cloudfront-origins): read versioned access level (aws#33038)
Browse files Browse the repository at this point in the history
### Issue # (if applicable)
Closes aws#33034

### Reason for this change
This allows creating an S3 bucket origin OriginAccessControl for access of versioned objects via CloudFront.

### Description of changes
Added a new `AccessLevel.READ_VERSIONED`, to extend the list of the OAC access levels, which extends the S3 bucket policy to contain `s3:GetObjectVersion`. I followed the existing patterns for the different AccessLevels, to make the change as small as possible. 

This enables versioned S3 bucket origins to allow the CloudFront distribution to access object versions.

### Describe any new or updated permissions being added
n/a

### Description of how you validated changes
Added a new unit-test and a new integration test

### 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
matthiasgubler authored and yashkh-amzn committed Feb 21, 2025
1 parent 0edf1ba commit 49434ef
Show file tree
Hide file tree
Showing 13 changed files with 31,723 additions and 3 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"Resources": {
"Bucket83908E77": {
"Type": "AWS::S3::Bucket",
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"BucketPolicyE9A3008A": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "Bucket83908E77"
},
"PolicyDocument": {
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"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"
]
},
"/*"
]
]
}
}
],
"Version": "2012-10-17"
}
}
},
"DistributionOrigin1S3OriginAccessControlEB606076": {
"Type": "AWS::CloudFront::OriginAccessControl",
"Properties": {
"OriginAccessControlConfig": {
"Name": "cloudfronts3bucketoriginoacrOrigin1S3OriginAccessControlE3A6B956",
"OriginAccessControlOriginType": "s3",
"SigningBehavior": "always",
"SigningProtocol": "sigv4"
}
}
},
"Distribution830FAC52": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"TargetOriginId": "cloudfronts3bucketoriginoacreadversionedaccessDistributionOrigin1920A1FBA",
"ViewerProtocolPolicy": "allow-all"
},
"Enabled": true,
"HttpVersion": "http2",
"IPV6Enabled": true,
"Origins": [
{
"DomainName": {
"Fn::GetAtt": [
"Bucket83908E77",
"RegionalDomainName"
]
},
"Id": "cloudfronts3bucketoriginoacreadversionedaccessDistributionOrigin1920A1FBA",
"OriginAccessControlId": {
"Fn::GetAtt": [
"DistributionOrigin1S3OriginAccessControlEB606076",
"Id"
]
},
"S3OriginConfig": {
"OriginAccessIdentity": ""
}
}
]
}
}
}
},
"Outputs": {
"ExportsOutputRefBucket83908E7781C90AC0": {
"Value": {
"Ref": "Bucket83908E77"
},
"Export": {
"Name": "cloudfront-s3-bucket-origin-oac-read-versioned-access:ExportsOutputRefBucket83908E7781C90AC0"
}
}
},
"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 49434ef

Please sign in to comment.