Skip to content

Commit dbdd7e2

Browse files
fix(query): resolve false positive on API Gateway access logging #7466
Made-with: Cursor
1 parent e1f23ca commit dbdd7e2

File tree

9 files changed

+62
-49
lines changed

9 files changed

+62
-49
lines changed

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/query.rego

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ CxPolicy[result] {
114114
resource.Type == "AWS::ApiGateway::Stage"
115115

116116
properties := resource.Properties
117-
methodSettings := properties.MethodSettings
118-
not common_lib.valid_key(methodSettings, "LoggingLevel")
117+
methodSetting := properties.MethodSettings[j]
118+
not common_lib.valid_key(methodSetting, "LoggingLevel")
119119

120120
result := {
121121
"documentId": input.document[i].id,
122122
"resourceType": resource.Type,
123123
"resourceName": cf_lib.get_resource_name(resource, name),
124124
"searchKey": sprintf("Resources.%s.Properties.MethodSettings", [name]),
125125
"issueType": "MissingAttribute",
126-
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel should be defined and not null", [name]),
127-
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel are undefined or null", [name]),
128-
"searchLine": common_lib.build_search_line(["Resources", name, "Properties", "MethodSettings"], []),
126+
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel should be defined and not null", [name, j]),
127+
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel is undefined or null", [name, j]),
128+
"searchLine": common_lib.build_search_line(["Resources", name, "Properties", "MethodSettings", j], []),
129129
}
130130
}
131131

@@ -135,18 +135,18 @@ CxPolicy[result] {
135135
resource.Type == "AWS::ApiGateway::Stage"
136136

137137
properties := resource.Properties
138-
loggingLevel := properties.MethodSettings.LoggingLevel
138+
loggingLevel := properties.MethodSettings[j].LoggingLevel
139139
loggingLevel == ""
140140

141141
result := {
142142
"documentId": input.document[i].id,
143143
"resourceType": resource.Type,
144144
"resourceName": cf_lib.get_resource_name(resource, name),
145-
"searchKey": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel", [name]),
145+
"searchKey": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel", [name, j]),
146146
"issueType": "IncorrectValue",
147-
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel should be not be empty", [name]),
148-
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel is empty", [name]),
149-
"searchLine": common_lib.build_search_line(["Resources", name, "Properties", "MethodSettings", "LoggingLevel"], []),
147+
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel should not be empty", [name, j]),
148+
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel is empty", [name, j]),
149+
"searchLine": common_lib.build_search_line(["Resources", name, "Properties", "MethodSettings", j, "LoggingLevel"], []),
150150
}
151151
}
152152

@@ -156,18 +156,18 @@ CxPolicy[result] {
156156
resource.Type == "AWS::ApiGateway::Stage"
157157

158158
properties := resource.Properties
159-
loggingLevel := properties.MethodSettings.LoggingLevel
159+
loggingLevel := properties.MethodSettings[j].LoggingLevel
160160
loggingLevel == "OFF"
161161

162162
result := {
163163
"documentId": input.document[i].id,
164164
"resourceType": resource.Type,
165165
"resourceName": cf_lib.get_resource_name(resource, name),
166-
"searchKey": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel", [name]),
166+
"searchKey": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel", [name, j]),
167167
"issueType": "IncorrectValue",
168-
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel should not be set to OFF", [name]),
169-
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel is OFF", [name]),
170-
"searchLine": common_lib.build_search_line(["Resources", name, "Properties", "MethodSettings", "LoggingLevel"], []),
168+
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel should not be set to OFF", [name, j]),
169+
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings[%d].LoggingLevel is OFF", [name, j]),
170+
"searchLine": common_lib.build_search_line(["Resources", name, "Properties", "MethodSettings", j, "LoggingLevel"], []),
171171
}
172172
}
173173

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/negative3.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
"DeploymentId": {
1414
"Ref": "MyDeployment"
1515
},
16-
"MethodSettings": {
17-
"DetailedMetricsEnabled": true,
18-
"LoggingLevel": "INFO",
19-
"DataTraceEnabled": false,
20-
"ThrottlingBurstLimit": 10,
21-
"ThrottlingRateLimit": 10
22-
},
16+
"MethodSettings": [
17+
{
18+
"DetailedMetricsEnabled": true,
19+
"LoggingLevel": "INFO",
20+
"DataTraceEnabled": false,
21+
"ThrottlingBurstLimit": 10,
22+
"ThrottlingRateLimit": 10
23+
}
24+
],
2325
"RestApiId": {
2426
"Ref": "CFNWebSocket"
2527
}

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/negative4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Resources:
88
DeploymentId: !Ref TestDeployment
99
DocumentationVersion: ""
1010
MethodSettings:
11-
LoggingLevel: "ON"
11+
- LoggingLevel: "INFO"
1212
AccessLogSetting:
1313
DestinationArn: "dest"
1414
Format: "format"

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive10.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
"RestApiId": {
1717
"Ref": "CFNWebSocket"
1818
},
19-
"MethodSettings": {
20-
}
19+
"MethodSettings": [
20+
{}
21+
]
2122
}
2223
}
2324
}

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive12.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
"RestApiId": {
1717
"Ref": "CFNWebSocket"
1818
},
19-
"MethodSettings": {
20-
"DetailedMetricsEnabled": true,
21-
"LoggingLevel": "OFF",
22-
"DataTraceEnabled": false,
23-
"ThrottlingBurstLimit": 10,
24-
"ThrottlingRateLimit": 10
25-
}
19+
"MethodSettings": [
20+
{
21+
"DetailedMetricsEnabled": true,
22+
"LoggingLevel": "OFF",
23+
"DataTraceEnabled": false,
24+
"ThrottlingBurstLimit": 10,
25+
"ThrottlingRateLimit": 10
26+
}
27+
]
2628
}
2729
}
2830
}

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive14.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Resources:
1111
DeploymentId: !Ref TestDeployment
1212
DocumentationVersion: ""
1313
MethodSettings:
14-
LoggingLevel: "OFF"
14+
- LoggingLevel: "OFF"

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive16.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Resources:
88
DeploymentId: !Ref TestDeployment
99
DocumentationVersion: ""
1010
MethodSettings:
11-
LoggingLevel: "ON"
11+
- LoggingLevel: "INFO"

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive6.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
"DeploymentId": {
1010
"Ref": "MyDeployment"
1111
},
12-
"MethodSettings": {
13-
"DetailedMetricsEnabled": true,
14-
"LoggingLevel": "INFO",
15-
"DataTraceEnabled": false,
16-
"ThrottlingBurstLimit": 10,
17-
"ThrottlingRateLimit": 10
18-
},
12+
"MethodSettings": [
13+
{
14+
"DetailedMetricsEnabled": true,
15+
"LoggingLevel": "INFO",
16+
"DataTraceEnabled": false,
17+
"ThrottlingBurstLimit": 10,
18+
"ThrottlingRateLimit": 10
19+
}
20+
],
1921
"RestApiId": {
2022
"Ref": "CFNWebSocket"
2123
}

assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive_expected_result.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
{
33
"queryName": "API Gateway V2 Stage Access Logging Settings Not Defined",
44
"severity": "MEDIUM",
5-
"line": 16,
5+
"line": 17,
6+
"fileName": "positive1.yaml"
7+
},
8+
{
9+
"queryName": "API Gateway V2 Stage Access Logging Settings Not Defined",
10+
"severity": "MEDIUM",
11+
"line": 21,
12+
"fileName": "positive1.yaml"
13+
},
14+
{
15+
"queryName": "API Gateway V2 Stage Access Logging Settings Not Defined",
16+
"severity": "MEDIUM",
17+
"line": 25,
618
"fileName": "positive1.yaml"
719
},
820
{
@@ -68,13 +80,7 @@
6880
{
6981
"queryName": "API Gateway V2 Stage Access Logging Settings Not Defined",
7082
"severity": "MEDIUM",
71-
"line": 13,
72-
"fileName": "positive11.yaml"
73-
},
74-
{
75-
"queryName": "API Gateway V2 Stage Access Logging Settings Not Defined",
76-
"severity": "MEDIUM",
77-
"line": 21,
83+
"line": 22,
7884
"fileName": "positive12.json"
7985
},
8086
{

0 commit comments

Comments
 (0)