Skip to content

Commit 2b2443d

Browse files
authored
feat(cloudfront-origins): list access level for 404 response (#32059)
### Issue # (if applicable) Closes #13983. Closes #31689. ### Reason for this change When we want to receive HTTP 404 response where the requested object does not exist, s3:ListBucket permission is needed in the S3 bucket policy. Unlike `errorResponses` to convert 403 response to 404, This is useful to distinguish between responses blocked by WAF (403) and responses where the file does not exist (404). ### Description of changes Added a new `AccessLevel.LIST` to allow s3:ListBucket. ### Description of how you validated changes Unit test and integration test. The integ test also tests the response is 404. ### 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*
1 parent ddaad47 commit 2b2443d

File tree

14 files changed

+31793
-23
lines changed

14 files changed

+31793
-23
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac-list-access.js.snapshot/asset.b98abee59e034ed29eeb601684dc34752baa86509a7d457d72305d4e19ecc80b.bundle/index.js

+30,570
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac-list-access.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac-list-access.js.snapshot/cloudfront-s3-bucket-origin-oac-list-access.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
{
2+
"Resources": {
3+
"Bucket83908E77": {
4+
"Type": "AWS::S3::Bucket",
5+
"UpdateReplacePolicy": "Delete",
6+
"DeletionPolicy": "Delete"
7+
},
8+
"BucketPolicyE9A3008A": {
9+
"Type": "AWS::S3::BucketPolicy",
10+
"Properties": {
11+
"Bucket": {
12+
"Ref": "Bucket83908E77"
13+
},
14+
"PolicyDocument": {
15+
"Statement": [
16+
{
17+
"Action": [
18+
"s3:GetObject",
19+
"s3:ListBucket"
20+
],
21+
"Condition": {
22+
"StringEquals": {
23+
"AWS:SourceArn": {
24+
"Fn::Join": [
25+
"",
26+
[
27+
"arn:",
28+
{
29+
"Ref": "AWS::Partition"
30+
},
31+
":cloudfront::",
32+
{
33+
"Ref": "AWS::AccountId"
34+
},
35+
":distribution/",
36+
{
37+
"Ref": "Distribution830FAC52"
38+
}
39+
]
40+
]
41+
}
42+
}
43+
},
44+
"Effect": "Allow",
45+
"Principal": {
46+
"Service": "cloudfront.amazonaws.com"
47+
},
48+
"Resource": [
49+
{
50+
"Fn::GetAtt": [
51+
"Bucket83908E77",
52+
"Arn"
53+
]
54+
},
55+
{
56+
"Fn::Join": [
57+
"",
58+
[
59+
{
60+
"Fn::GetAtt": [
61+
"Bucket83908E77",
62+
"Arn"
63+
]
64+
},
65+
"/*"
66+
]
67+
]
68+
}
69+
]
70+
}
71+
],
72+
"Version": "2012-10-17"
73+
}
74+
}
75+
},
76+
"DistributionOrigin1S3OriginAccessControlEB606076": {
77+
"Type": "AWS::CloudFront::OriginAccessControl",
78+
"Properties": {
79+
"OriginAccessControlConfig": {
80+
"Name": "cloudfronts3bucketoriginoaclOrigin1S3OriginAccessControl5D8868CB",
81+
"OriginAccessControlOriginType": "s3",
82+
"SigningBehavior": "always",
83+
"SigningProtocol": "sigv4"
84+
}
85+
}
86+
},
87+
"Distribution830FAC52": {
88+
"Type": "AWS::CloudFront::Distribution",
89+
"Properties": {
90+
"DistributionConfig": {
91+
"DefaultCacheBehavior": {
92+
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
93+
"Compress": true,
94+
"TargetOriginId": "cloudfronts3bucketoriginoaclistaccessDistributionOrigin11CECE99D",
95+
"ViewerProtocolPolicy": "allow-all"
96+
},
97+
"DefaultRootObject": "index.html",
98+
"Enabled": true,
99+
"HttpVersion": "http2",
100+
"IPV6Enabled": true,
101+
"Origins": [
102+
{
103+
"DomainName": {
104+
"Fn::GetAtt": [
105+
"Bucket83908E77",
106+
"RegionalDomainName"
107+
]
108+
},
109+
"Id": "cloudfronts3bucketoriginoaclistaccessDistributionOrigin11CECE99D",
110+
"OriginAccessControlId": {
111+
"Fn::GetAtt": [
112+
"DistributionOrigin1S3OriginAccessControlEB606076",
113+
"Id"
114+
]
115+
},
116+
"S3OriginConfig": {
117+
"OriginAccessIdentity": ""
118+
}
119+
}
120+
]
121+
}
122+
}
123+
}
124+
},
125+
"Outputs": {
126+
"ExportsOutputFnGetAttDistribution830FAC52DomainNameBEB09E30": {
127+
"Value": {
128+
"Fn::GetAtt": [
129+
"Distribution830FAC52",
130+
"DomainName"
131+
]
132+
},
133+
"Export": {
134+
"Name": "cloudfront-s3-bucket-origin-oac-list-access:ExportsOutputFnGetAttDistribution830FAC52DomainNameBEB09E30"
135+
}
136+
}
137+
},
138+
"Parameters": {
139+
"BootstrapVersion": {
140+
"Type": "AWS::SSM::Parameter::Value<String>",
141+
"Default": "/cdk-bootstrap/hnb659fds/version",
142+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
143+
}
144+
},
145+
"Rules": {
146+
"CheckBootstrapVersion": {
147+
"Assertions": [
148+
{
149+
"Assert": {
150+
"Fn::Not": [
151+
{
152+
"Fn::Contains": [
153+
[
154+
"1",
155+
"2",
156+
"3",
157+
"4",
158+
"5"
159+
],
160+
{
161+
"Ref": "BootstrapVersion"
162+
}
163+
]
164+
}
165+
]
166+
},
167+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
168+
}
169+
]
170+
}
171+
}
172+
}

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac-list-access.js.snapshot/integ.json

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-cloudfront-origins/test/integ.s3-origin-oac-list-access.js.snapshot/manifest.json

+170
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)