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): Update ckv-aws-8 policy - support unknown statement #6596

Merged
merged 1 commit into from
Jul 25, 2024
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
Expand Up @@ -35,16 +35,31 @@ def scan_resource_conf(self, conf: Dict[str, List[Any]]) -> CheckResult:
self.evaluated_keys.append("ebs_block_device")
blocks = conf.get("ebs_block_device") or []

allblocks = root + blocks
all_blocks = root + blocks

if not allblocks:
if not all_blocks:
return CheckResult.UNKNOWN
all_blocks_results = []

for block in allblocks:
if isinstance(block, dict) and not block.get("encrypted") == [True]:
if not block.get("snapshot_id"):
return CheckResult.FAILED
return CheckResult.PASSED
for block in all_blocks:
all_blocks_results.append(_is_block_encrypted(block))
if CheckResult.FAILED in all_blocks_results:
return CheckResult.FAILED
elif CheckResult.UNKNOWN in all_blocks_results:
return CheckResult.UNKNOWN
else:
return CheckResult.PASSED


check = LaunchConfigurationEBSEncryption()


def _is_block_encrypted(block) -> CheckResult:
if isinstance(block, dict):
if block.get("encrypted") in ([False], False) and not block.get("snapshot_id"):
return CheckResult.FAILED
elif block.get("encrypted") in ([True], True):
return CheckResult.PASSED
elif not block.get("encrypted") in ([True], True) and block.get("snapshot_id"):
return CheckResult.PASSED
return CheckResult.UNKNOWN
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ resource "aws_instance" "fail_empty_root_list" {
root_block_device = var.empty_list
}

resource "aws_instance" "fail_empty_ebs_list" {
resource "aws_instance" "unknown_empty_ebs_list" {
image_id = "ami-123"
instance_type = "t2.micro"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ def test(self):
"aws_instance.fail4",
"aws_instance.fail5",
"aws_instance.fail_empty_root_list",
"aws_instance.fail_empty_ebs_list",
"aws_launch_configuration.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"], 5)
self.assertEqual(summary["failed"], 8)
self.assertEqual(summary["failed"], 7)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add a check for unknown here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unknown is not recognized as part of the test result

self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)

Expand Down
Loading