forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Checkmarx#6863 from Checkmarx/kics-1145
feat(query): cloud formation api gateway access logging disabled
- Loading branch information
Showing
27 changed files
with
553 additions
and
178 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ogging_settings_not_defined/metadata.json → ...way_access_logging_disabled/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
import data.generic.cloudformation as cf_lib | ||
|
||
CxPolicy[result] { | ||
document := input.document | ||
resource = document[i].Resources[name] | ||
resource.Type == "AWS::ApiGatewayV2::Stage" | ||
|
||
properties := resource.Properties | ||
searchKeyValid := validNonEmptyKey(properties, "DefaultRouteSettings") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("Resources.%s.Properties%s", [name, searchKeyValid]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": sprintf("Resources.%s.Properties.DefaultRouteSettings should be defined and not null", [name]), | ||
"keyActualValue": sprintf("Resources.%s.Properties.DefaultRouteSettings are undefined or null", [name]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
document := input.document | ||
resource = document[i].Resources[name] | ||
resource.Type == "AWS::ApiGatewayV2::Stage" | ||
|
||
properties := resource.Properties | ||
defaultRouteSettings := properties.DefaultRouteSettings | ||
searchKeyValid := validNonEmptyKey(defaultRouteSettings, "LoggingLevel") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("Resources.%s.Properties.DefaultRouteSettings%s", [name, searchKeyValid]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": sprintf("Resources.%s.Properties.DefaultRouteSettings.LoggingLevel should be defined and not null", [name]), | ||
"keyActualValue": sprintf("Resources.%s.Properties.DefaultRouteSettings.LoggingLevel are undefined or null", [name]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
document := input.document | ||
resource = document[i].Resources[name] | ||
resource.Type == "AWS::ApiGatewayV2::Stage" | ||
|
||
properties := resource.Properties | ||
loggingLevel := properties.DefaultRouteSettings.LoggingLevel | ||
loggingLevel == "OFF" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("Resources.%s.Properties.DefaultRouteSettings.LoggingLevel", [name]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": sprintf("Resources.%s.Properties.DefaultRouteSettings.LoggingLevel should not be set to OFF", [name]), | ||
"keyActualValue": sprintf("Resources.%s.Properties.DefaultRouteSettings.LoggingLevel is OFF", [name]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
document := input.document | ||
resource = document[i].Resources[name] | ||
resource.Type == "AWS::ApiGateway::Stage" | ||
|
||
properties := resource.Properties | ||
searchKeyValid := validNonEmptyKey(properties, "MethodSettings") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("Resources.%s.Properties%s", [name, searchKeyValid]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings should be defined and not null", [name]), | ||
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings are undefined or null", [name]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
document := input.document | ||
resource = document[i].Resources[name] | ||
resource.Type == "AWS::ApiGateway::Stage" | ||
|
||
properties := resource.Properties | ||
methodSettings := properties.MethodSettings | ||
searchKeyValid := validNonEmptyKey(methodSettings, "LoggingLevel") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("Resources.%s.Properties.MethodSettings%s", [name, searchKeyValid]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel should be defined and not null", [name]), | ||
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel are undefined or null", [name]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
document := input.document | ||
resource = document[i].Resources[name] | ||
resource.Type == "AWS::ApiGateway::Stage" | ||
|
||
properties := resource.Properties | ||
loggingLevel := properties.MethodSettings.LoggingLevel | ||
loggingLevel == "OFF" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel", [name]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel should not be set to OFF", [name]), | ||
"keyActualValue": sprintf("Resources.%s.Properties.MethodSettings.LoggingLevel is OFF", [name]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
doc := input.document[i] | ||
resource := doc.Resources[stage] | ||
resource.Type == "AWS::ApiGatewayV2::Stage" | ||
properties := resource.Properties | ||
|
||
not properties.AccessLogSettings | ||
|
||
result := { | ||
"documentId": doc.id, | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "'AccessLogSettings' should be defined", | ||
"keyActualValue": "'AccessLogSettings' is not defined", | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, stage), | ||
"searchKey": sprintf("Resources.%s.Properties", [stage]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
doc := input.document[i] | ||
resource := doc.Resources[stage] | ||
resource.Type == "AWS::ApiGateway::Stage" | ||
properties := resource.Properties | ||
|
||
not properties.AccessLogSetting | ||
|
||
result := { | ||
"documentId": doc.id, | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "'AccessLogSetting' should be defined", | ||
"keyActualValue": "'AccessLogSetting' is not defined", | ||
"resourceType": resource.Type, | ||
"resourceName": cf_lib.get_resource_name(resource, stage), | ||
"searchKey": sprintf("Resources.%s.Properties", [stage]), | ||
} | ||
} | ||
|
||
validNonEmptyKey(field, key) = output { | ||
not common_lib.valid_key(field, key) | ||
output = "" | ||
} else = output { | ||
keyObj := field[key] | ||
is_object(keyObj) | ||
count(keyObj) == 0 | ||
output := concat(".", ["", key]) | ||
} |
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/negative3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": { | ||
"MyStage": { | ||
"Type": "AWS::ApiGateway::Stage", | ||
"Properties": { | ||
"StageName": "Prod", | ||
"Description": "Prod Stage", | ||
"AccessLogSetting": { | ||
"DestinationArn": "dest", | ||
"Format": "format" | ||
}, | ||
"DeploymentId": { | ||
"Ref": "MyDeployment" | ||
}, | ||
"MethodSettings": { | ||
"DetailedMetricsEnabled": true, | ||
"LoggingLevel": "INFO", | ||
"DataTraceEnabled": false, | ||
"ThrottlingBurstLimit": 10, | ||
"ThrottlingRateLimit": 10 | ||
}, | ||
"RestApiId": { | ||
"Ref": "CFNWebSocket" | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/negative4.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Resources: | ||
Prod: | ||
Type: AWS::ApiGateway::Stage | ||
Properties: | ||
StageName: Prod | ||
Description: Prod Stage | ||
RestApiId: !Ref MyRestApi | ||
DeploymentId: !Ref TestDeployment | ||
DocumentationVersion: "" | ||
MethodSettings: | ||
LoggingLevel: "ON" | ||
AccessLogSetting: | ||
DestinationArn: "dest" | ||
Format: "format" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive10.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": { | ||
"MyStage": { | ||
"Type": "AWS::ApiGateway::Stage", | ||
"Properties": { | ||
"StageName": "Prod", | ||
"Description": "Prod Stage", | ||
"AccessLogSetting": { | ||
"DestinationArn": "dest", | ||
"Format": "format" | ||
}, | ||
"DeploymentId": { | ||
"Ref": "MyDeployment" | ||
}, | ||
"RestApiId": { | ||
"Ref": "CFNWebSocket" | ||
}, | ||
"MethodSettings": { | ||
} | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive11.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Resources: | ||
Prod: | ||
Type: AWS::ApiGateway::Stage | ||
Properties: | ||
StageName: Prod | ||
Description: Prod Stage | ||
AccessLogSetting: | ||
DestinationArn: "dest" | ||
Format: "format" | ||
RestApiId: !Ref MyRestApi | ||
DeploymentId: !Ref TestDeployment | ||
DocumentationVersion: "" | ||
MethodSettings: |
29 changes: 29 additions & 0 deletions
29
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive12.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": { | ||
"MyStage": { | ||
"Type": "AWS::ApiGateway::Stage", | ||
"Properties": { | ||
"StageName": "Prod", | ||
"Description": "Prod Stage", | ||
"AccessLogSetting": { | ||
"DestinationArn": "dest", | ||
"Format": "format" | ||
}, | ||
"DeploymentId": { | ||
"Ref": "MyDeployment" | ||
}, | ||
"RestApiId": { | ||
"Ref": "CFNWebSocket" | ||
}, | ||
"MethodSettings": { | ||
"DetailedMetricsEnabled": true, | ||
"LoggingLevel": "OFF", | ||
"DataTraceEnabled": false, | ||
"ThrottlingBurstLimit": 10, | ||
"ThrottlingRateLimit": 10 | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive13.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Resources: | ||
Prod: | ||
Type: AWS::ApiGatewayV2::Stage | ||
Properties: | ||
StageName: Prod | ||
Description: Prod Stage | ||
AccessLogSettings: | ||
DestinationArn: "dest" | ||
Format: "format" | ||
RestApiId: !Ref MyRestApi | ||
DeploymentId: !Ref TestDeployment | ||
DocumentationVersion: "" | ||
ApiId: "teste" | ||
DefaultRouteSettings: |
14 changes: 14 additions & 0 deletions
14
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive14.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Resources: | ||
Prod: | ||
Type: AWS::ApiGateway::Stage | ||
Properties: | ||
StageName: Prod | ||
Description: Prod Stage | ||
AccessLogSetting: | ||
DestinationArn: "dest" | ||
Format: "format" | ||
RestApiId: !Ref MyRestApi | ||
DeploymentId: !Ref TestDeployment | ||
DocumentationVersion: "" | ||
MethodSettings: | ||
LoggingLevel: "OFF" |
15 changes: 15 additions & 0 deletions
15
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive15.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Resources: | ||
Prod: | ||
Type: AWS::ApiGatewayV2::Stage | ||
Properties: | ||
StageName: Prod | ||
Description: Prod Stage | ||
AccessLogSettings: | ||
DestinationArn: "dest" | ||
Format: "format" | ||
RestApiId: !Ref MyRestApi | ||
DeploymentId: !Ref TestDeployment | ||
DocumentationVersion: "" | ||
ApiId: "teste" | ||
DefaultRouteSettings: | ||
LoggingLevel: "OFF" |
11 changes: 11 additions & 0 deletions
11
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive16.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Resources: | ||
Prod: | ||
Type: AWS::ApiGateway::Stage | ||
Properties: | ||
StageName: Prod | ||
Description: Prod Stage | ||
RestApiId: !Ref MyRestApi | ||
DeploymentId: !Ref TestDeployment | ||
DocumentationVersion: "" | ||
MethodSettings: | ||
LoggingLevel: "ON" |
12 changes: 12 additions & 0 deletions
12
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive17.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Resources: | ||
Prod: | ||
Type: AWS::ApiGatewayV2::Stage | ||
Properties: | ||
StageName: Prod | ||
Description: Prod Stage | ||
RestApiId: !Ref MyRestApi | ||
DeploymentId: !Ref TestDeployment | ||
DocumentationVersion: "" | ||
ApiId: "teste" | ||
DefaultRouteSettings: | ||
LoggingLevel: "ON" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.