Skip to content

Commit 46fa7a4

Browse files
authored
Exception for lambda authorizer uri (#3720)
* Exception for lambda authorizer uri * Remove exceptions in I3042 and allow lambda auth uri
1 parent 4a57bc9 commit 46fa7a4

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

src/cfnlint/rules/resources/HardCodedArnProperties.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ def __init__(self):
4747
"type": "boolean",
4848
},
4949
}
50-
self.exceptions = {
51-
"AWS::ApiGateway::Authorizer": [
52-
["Properties", "AuthorizerUri"],
53-
]
54-
}
5550

5651
self.configure()
5752

@@ -102,17 +97,6 @@ def match(self, cfn: Template) -> RuleMatches:
10297
path = ["Resources"] + parameter_string_path[:-1]
10398
candidate = parameter_string_path[-1]
10499

105-
resource_name = path[1]
106-
_type = cfn.template.get("Resources", {}).get(resource_name, {}).get("Type")
107-
is_exception = False
108-
if _type in self.exceptions:
109-
for exception in self.exceptions[_type]:
110-
if all(x[0] == x[1] for x in zip(path[2:], exception)):
111-
is_exception = True
112-
113-
if is_exception:
114-
continue
115-
116100
# ruff: noqa: E501
117101
# !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
118102
# is valid even with aws as the account #. This handles empty string
@@ -135,8 +119,11 @@ def match(self, cfn: Template) -> RuleMatches:
135119
" incorrectly placed Pseudo Parameters"
136120
)
137121
matches.append(RuleMatch(path, message.format(path[1])))
122+
123+
# Lambda is added for authorizer's Uniform Resource Identifier (URI)
124+
# https://github.com/aws-cloudformation/cfn-lint/issues/3716
138125
if self.config["accountId"] and not re.match(
139-
r"^\$\{\w+}|\$\{AWS::AccountId}|aws|$", candidate[2]
126+
r"^\$\{\w+}|\$\{AWS::AccountId}|aws|lambda|$", candidate[2]
140127
):
141128
message = (
142129
"ARN in Resource {0} contains hardcoded AccountId in ARN or"

test/fixtures/templates/bad/hard_coded_arn_properties.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,3 @@ Resources:
7777
- !Sub arn:${AWS::Partition}:sns:${AWS::Partition}:${AWS::AccountId}:TestTopic
7878
Roles:
7979
- !Ref SampleRole
80-
81-
Authorizer:
82-
Type: AWS::ApiGateway::Authorizer
83-
Properties:
84-
AuthorizerUri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:Name/invocations
85-
RestApiId: RestApiId
86-
Type: REQUEST
87-
Name: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:Name/invocations

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

+8
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ Resources:
66
RestApiId: RestApiId
77
Type: REQUEST
88
Name: Name
9+
Stack:
10+
Type: AWS::CloudFormation::Stack
11+
DeletionPolicy: Delete
12+
UpdateReplacePolicy: Delete
13+
Properties:
14+
TemplateURL: !Sub https://s3_bucket_name.s3.${AWS::Region}.amazonaws.com/template.yaml
15+
Parameters:
16+
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

test/unit/rules/resources/test_hardcodedarnproperties.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_file_negative_region(self):
7171
def test_file_negative_accountid(self):
7272
self.helper_file_negative(
7373
"test/fixtures/templates/bad/hard_coded_arn_properties.yaml",
74-
2,
74+
1,
7575
ConfigMixIn(
7676
[],
7777
include_experimental=True,

0 commit comments

Comments
 (0)