-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): cloud formation api gateway access logging disabled
- Loading branch information
Showing
8 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
assets/queries/cloudFormation/aws/api_gateway_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "999ecb35-10df-4d73-8f17-3f4b8c3beec5", | ||
"queryName": "API Gateway Access Logging Disabled", | ||
"severity": "MEDIUM", | ||
"category": "Observability", | ||
"descriptionText": "API Gateway should have Access Log Settings defined", | ||
"descriptionUrl": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html", | ||
"platform": "CloudFormation", | ||
"descriptionID": "d7151524", | ||
"cloudProvider": "aws", | ||
"cwe": "" | ||
} |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
package Cx | ||
|
||
import data.generic.cloudformation as cf_lib | ||
|
||
CxPolicy[result] { | ||
doc := input.document[i] | ||
res := doc.Resources[stage] | ||
properties := res.Properties | ||
res.Type == "AWS::ApiGatewayV2::Stage" | ||
|
||
not properties.AccessLogSettings | ||
|
||
result := { | ||
"documentId": doc.id, | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "'AccessLogSettings' should be defined", | ||
"keyActualValue": "'AccessLogSettings' is not defined", | ||
"resourceType": res.Type, | ||
"resourceName": cf_lib.get_resource_name(res, stage), | ||
"searchKey": sprintf("Resources.%s.Properties", [stage]), | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
doc := input.document[i] | ||
res := doc.Resources[stage] | ||
properties := res.Properties | ||
res.Type == "AWS::ApiGateway::Stage" | ||
|
||
not properties.AccessLogSetting | ||
|
||
result := { | ||
"documentId": doc.id, | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "'AccessLogSetting' should be defined", | ||
"keyActualValue": "'AccessLogSetting' is not defined", | ||
"resourceType": res.Type, | ||
"resourceName": cf_lib.get_resource_name(res, stage), | ||
"searchKey": sprintf("Resources.%s.Properties", [stage]), | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/negative1.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::ApiGatewayV2::Stage", | ||
"Properties": { | ||
"StageName": "Prod", | ||
"Description": "Prod Stage", | ||
"AccessLogSettings": { | ||
"DestinationArn": "dest", | ||
"Format": "format" | ||
}, | ||
"DeploymentId": { | ||
"Ref": "MyDeployment" | ||
}, | ||
"ApiId": { | ||
"Ref": "CFNWebSocket" | ||
}, | ||
"DefaultRouteSettings": { | ||
"DetailedMetricsEnabled": true, | ||
"LoggingLevel": "INFO", | ||
"DataTraceEnabled": false, | ||
"ThrottlingBurstLimit": 10, | ||
"ThrottlingRateLimit": 10 | ||
} | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/negative2.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,23 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09T00:00:00Z", | ||
"Resources": { | ||
"NewAmpApp-1": { | ||
"Type": "AWS::Amplify::App", | ||
"Properties": { | ||
"OauthToken": "String", | ||
"Repository": "String", | ||
"BasicAuthConfig": { | ||
"Username": "admin", | ||
"EnableBasicAuth": true, | ||
"Password": "@skdsjdk0234!AB" | ||
}, | ||
"CustomHeaders": "String", | ||
"Description": "String", | ||
"Name": "NewAmpApp", | ||
"BuildSpec": "String", | ||
"EnableBranchAutoDeletion": true, | ||
"IAMServiceRole": "String" | ||
} | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
{ | ||
"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" | ||
} | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive1.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,25 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": { | ||
"MyStage": { | ||
"Type": "AWS::ApiGatewayV2::Stage", | ||
"Properties": { | ||
"StageName": "Prod", | ||
"Description": "Prod Stage", | ||
"DeploymentId": { | ||
"Ref": "MyDeployment" | ||
}, | ||
"ApiId": { | ||
"Ref": "CFNWebSocket" | ||
}, | ||
"DefaultRouteSettings": { | ||
"DetailedMetricsEnabled": true, | ||
"LoggingLevel": "INFO", | ||
"DataTraceEnabled": false, | ||
"ThrottlingBurstLimit": 10, | ||
"ThrottlingRateLimit": 10 | ||
} | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
assets/queries/cloudFormation/aws/api_gateway_access_logging_disabled/test/positive2.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,18 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Resources": { | ||
"MyStage": { | ||
"Type": "AWS::ApiGateway::Stage", | ||
"Properties": { | ||
"StageName": "Prod", | ||
"Description": "Prod Stage", | ||
"DeploymentId": { | ||
"Ref": "MyDeployment" | ||
}, | ||
"RestApiId": { | ||
"Ref": "CFNWebSocket" | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...cloudFormation/aws/api_gateway_access_logging_disabled/test/positive_expected_result.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,14 @@ | ||
[ | ||
{ | ||
"queryName": "API Gateway Access Logging Disabled", | ||
"severity": "MEDIUM", | ||
"line": 6, | ||
"filename": "positive1.json" | ||
}, | ||
{ | ||
"queryName": "API Gateway Access Logging Disabled", | ||
"severity": "MEDIUM", | ||
"line": 6, | ||
"filename": "positive2.json" | ||
} | ||
] |