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_272 to validate Lambda function code-signing #3556

Merged
merged 5 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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.common.models.consts import ANY_VALUE
from checkov.terraform.checks.resource.base_resource_value_check import BaseResourceValueCheck
from checkov.common.models.enums import CheckCategories


class LambdaCodeSigningConfigured(BaseResourceValueCheck):
def __init__(self):
name = "Ensure AWS Lambda function is configured to validate code-signing"
id = "CKV_AWS_272"
supported_resources = ['aws_lambda_function']
categories = [CheckCategories.SUPPLY_CHAIN]
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

def get_inspected_key(self):
return "code_signing_config_arn"

def get_expected_value(self):
return ANY_VALUE


check = LambdaCodeSigningConfigured()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# pass

resource "aws_lambda_function" "pass" {
function_name = "test-env"
role = ""
runtime = "python3.8"
code_signing_config_arn = "123123123"
}

# fail

resource "aws_lambda_function" "fail" {
function_name = "stest-env"
role = ""
runtime = "python3.8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import unittest
from pathlib import Path

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


class TestWafHasAnyRules(unittest.TestCase):
def test(self):
# given
test_files_dir = Path(__file__).parent / "example_LambdaCodeSigningConfigured"

# when
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[check.id]))

# then
summary = report.get_summary()

passing_resources = {
"aws_lambda_function.pass"
}

failing_resources = {
"aws_lambda_function.fail"
}

passed_check_resources = {c.resource for c in report.passed_checks}
failed_check_resources = {c.resource for c in report.failed_checks}

self.assertEqual(summary["passed"], 1)
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()