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

fix(bicep): enforce encryption flag to be string for CKV_AZURE_97 #5669

Merged
merged 1 commit into from
Oct 22, 2023
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
2 changes: 1 addition & 1 deletion checkov/arm/checks/resource/VMEncryptionAtHostEnabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def scan_resource_conf(self, conf: dict[str, Any]) -> CheckResult:
input_dict=conf, key_path="properties/virtualMachineProfile/securityProfile/encryptionAtHost"
)

if encryption == "true":
if str(encryption).lower() == "true":
return CheckResult.PASSED

return CheckResult.FAILED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// pass

resource enabled 'Microsoft.Compute/virtualMachines@2021-11-01' = {
name: virtualMachineName
location: location
properties: {
securityProfile: {
encryptionAtHost: true
}
}
}

// fail

resource disabled 'Microsoft.Compute/virtualMachines@2021-11-01' = {
name: virtualMachineName
location: location
properties: {
securityProfile: {
encryptionAtHost: false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path

from checkov.bicep.runner import Runner
from checkov.arm.checks.resource.VMEncryptionAtHostEnabled import check
from checkov.runner_filter import RunnerFilter


def test_examples():
# given
test_files_dir = Path(__file__).parent / "example_VMEncryptionAtHostEnabled"

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

# then
summary = report.get_summary()

passing_resources = {
"Microsoft.Compute/virtualMachines.enabled",
}

failing_resources = {
"Microsoft.Compute/virtualMachines.disabled",
}

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

assert summary["passed"] == len(passing_resources)
assert summary["failed"] == len(failing_resources)
assert summary["skipped"] == 0
assert summary["parsing_errors"] == 0

assert passed_check_resources == passing_resources
assert failed_check_resources == failing_resources