Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform): Add CKV_AWS_276 to ensure that API Gateway Method Settings data_trace_enabled is not set to True #3761

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from checkov.terraform.checks.resource.base_resource_negative_value_check import BaseResourceNegativeValueCheck
from checkov.common.models.enums import CheckCategories


class APIGatewayMethodSettingsDataTrace(BaseResourceNegativeValueCheck):

NickG123 marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self):
name = "Ensure Data Trace is not enabled in API Gateway Method Settings"
id = "CKV_AWS_276"
supported_resources = ['aws_api_gateway_method_settings']
categories = [CheckCategories.LOGGING]
NickG123 marked this conversation as resolved.
Show resolved Hide resolved
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

def get_inspected_key(self):
return "settings/[0]/data_trace_enabled"

def get_forbidden_values(self):
return [True]


check = APIGatewayMethodSettingsDataTrace()
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "aws_api_gateway_method_settings" "fail" {
rest_api_id = aws_api_gateway_rest_api.test.id
stage_name = aws_api_gateway_stage.test.stage_name
method_path = "path1/GET"

settings {
data_trace_enabled = true
}
}

resource "aws_api_gateway_method_settings" "pass_explicit" {
rest_api_id = aws_api_gateway_rest_api.test.id
stage_name = aws_api_gateway_stage.test.stage_name
method_path = "path1/GET"

settings {
data_trace_enabled = false
}
}

resource "aws_api_gateway_method_settings" "pass_implicit" {
rest_api_id = aws_api_gateway_rest_api.test.id
stage_name = aws_api_gateway_stage.test.stage_name
method_path = "path1/GET"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import unittest

from checkov.runner_filter import RunnerFilter
from checkov.terraform.runner import Runner
from checkov.terraform.checks.resource.aws.APIGatewayMethodSettingsDataTrace import check


class TestAPIGatewayMethodSettingsDataTrace(unittest.TestCase):

def test(self):
runner = Runner()
current_dir = os.path.dirname(os.path.realpath(__file__))

test_files_dir = os.path.join(current_dir, "example_APIGatewayMethodSettingsDataTrace")
report = runner.run(root_folder=test_files_dir, runner_filter=RunnerFilter(checks=[check.id]))
summary = report.get_summary()

passing_resources = {
"aws_api_gateway_method_settings.pass_explicit",
"aws_api_gateway_method_settings.pass_implicit",
}
failing_resources = {
"aws_api_gateway_method_settings.fail",
}

passed_check_resources = set([c.resource for c in report.passed_checks])
failed_check_resources = set([c.resource for c in report.failed_checks])

self.assertEqual(summary["passed"], 2)
self.assertEqual(summary["failed"], 1)
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

self.assertEqual(passing_resources, passed_check_resources)
self.assertEqual(failing_resources, failed_check_resources)


if __name__ == '__main__':
unittest.main()