Skip to content

Commit 013413b

Browse files
authored
Allow cloudfront to be used in ARNs for accountId (#3821)
* Allow cloudfront to be used in ARNs for accountId
1 parent f3e0699 commit 013413b

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/cfnlint/rules/resources/HardCodedArnProperties.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ def match(self, cfn: Template) -> RuleMatches:
125125
if self.config["accountId"] and not re.match(
126126
r"^\$\{\w+}|\$\{AWS::AccountId}|aws|lambda|$", candidate[2]
127127
):
128-
message = (
129-
"ARN in Resource {0} contains hardcoded AccountId in ARN or"
130-
" incorrectly placed Pseudo Parameters"
131-
)
132-
matches.append(RuleMatch(path, message.format(path[1])))
128+
if candidate[2] not in ["cloudfront"]:
129+
message = (
130+
"ARN in Resource {0} contains hardcoded AccountId in ARN or"
131+
" incorrectly placed Pseudo Parameters"
132+
)
133+
matches.append(RuleMatch(path, message.format(path[1])))
133134

134135
return matches

test/fixtures/templates/good/resources/properties/hard_coded_arn_properties.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ Resources:
1414
TemplateURL: !Sub https://s3_bucket_name.s3.${AWS::Region}.amazonaws.com/template.yaml
1515
Parameters:
1616
AuthorizerUri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:FunctionName/invocations
17+
Bucket:
18+
Type: AWS::S3::BucketPolicy
19+
Properties:
20+
Bucket: bucket
21+
PolicyDocument:
22+
Version: 2012-10-17
23+
Statement:
24+
- Effect: Allow
25+
Principal:
26+
AWS: !Sub arn:${AWS::Partition}:iam::cloudfront:user/CloudFront Origin Access Identity E15MNIMTCFKK4C
27+
Action: s3:GetObject
28+
Resource: arn:aws:s3:::bucket/*

test/unit/rules/resources/test_hardcodedarnproperties.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ def test_file_positive(self):
2828
# By default, a set of "correct" templates are checked
2929
self.helper_file_positive()
3030

31+
def test_file_positive_with_config(self):
32+
self.helper_file_negative(
33+
"test/fixtures/templates/good/resources/properties/hard_coded_arn_properties.yaml",
34+
0,
35+
ConfigMixIn(
36+
[],
37+
include_experimental=True,
38+
include_checks=[
39+
"I",
40+
],
41+
configure_rules={
42+
"I3042": {
43+
"partition": True,
44+
"region": True,
45+
"accountId": True,
46+
}
47+
},
48+
),
49+
)
50+
3151
def test_file_negative_partition(self):
3252
self.helper_file_negative(
3353
"test/fixtures/templates/bad/hard_coded_arn_properties.yaml",

0 commit comments

Comments
 (0)