Skip to content

Commit

Permalink
feat(terraform): add check for Neptune DB clusters IAM database auth …
Browse files Browse the repository at this point in the history
…enabled (#5545)

* add check for Neptune DB clusters should have IAM database authentication enabled

* another test

* another test

* update ckv num
  • Loading branch information
omryMen committed Sep 10, 2023
1 parent 55c52c4 commit 112e558
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from checkov.common.models.enums import CheckCategories
from checkov.terraform.checks.resource.base_resource_value_check import BaseResourceValueCheck


class NeptuneDBClustersIAMDatabaseAuthenticationEnabled(BaseResourceValueCheck):
def __init__(self):
description = "Neptune DB clusters should have IAM database authentication enabled"
id = "CKV_AWS_359"
supported_resources = ['aws_neptune_cluster']
categories = [CheckCategories.IAM]
super().__init__(name=description, id=id, categories=categories, supported_resources=supported_resources)

def get_inspected_key(self):
return "iam_database_authentication_enabled"


check = NeptuneDBClustersIAMDatabaseAuthenticationEnabled()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## SHOULD PASS: iam_database_authentication_enabled set to true
resource "aws_neptune_cluster" "ckv_unittest_pass" {
## Your test here
cluster_identifier = "bla"
iam_database_authentication_enabled = true
}

## SHOULD FAIL: iam_database_authentication_enabled set to false
resource "aws_neptune_cluster" "ckv_unittest_fail" {
## Your test here
cluster_identifier = "bla_fail"
iam_database_authentication_enabled = false
}


## SHOULD FAIL: iam_database_authentication_enabled doesn't exist
resource "aws_neptune_cluster" "ckv_unittest2_fail" {
## Your test here
cluster_identifier = "bla_fail"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import unittest

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


class TestNeptuneDBClustersIAMDatabaseAuthenticationEnabled(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_NeptuneDBClustersIAMDatabaseAuthenticationEnabled")
report = runner.run(root_folder=test_files_dir,
runner_filter=RunnerFilter(checks=[check.id]))
summary = report.get_summary()

passing_resources = {
'aws_neptune_cluster.ckv_unittest_pass'
}
failing_resources = {
'aws_neptune_cluster.ckv_unittest_fail',
'aws_neptune_cluster.ckv_unittest2_fail',
}
skipped_resources = {}

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'], len(passing_resources))
self.assertEqual(summary['failed'], len(failing_resources))
self.assertEqual(summary['skipped'], len(skipped_resources))
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()

0 comments on commit 112e558

Please sign in to comment.