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(arm): add CKV_AZURE_166 Ensure container image quarantine, scan, and mark images verified #6431

Merged
merged 1 commit into from
Jun 27, 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
21 changes: 21 additions & 0 deletions checkov/arm/checks/resource/ACREnableImageQuarantine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations
from checkov.common.models.enums import CheckCategories
from checkov.arm.base_resource_value_check import BaseResourceValueCheck


class ACREnableImageQuarantine(BaseResourceValueCheck):
def __init__(self) -> None:
name = "Ensure container image quarantine, scan, and mark images verified"
id = "CKV_AZURE_166"
supported_resources = ("Microsoft.ContainerRegistry/registries",)
categories = (CheckCategories.SUPPLY_CHAIN,)
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

def get_inspected_key(self) -> str:
return "properties/policies/quarantinePolicy/status"

def get_expected_value(self) -> str:
return "enabled"


check = ACREnableImageQuarantine()
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"resources": [
{
"apiVersion": "2019-05-01",
"type": "Microsoft.ContainerRegistry/registries",
"name": "fail",
"location": "[resourceGroup().location]",
"sku": {
"name": "Basic"
},
"properties": {
"adminUserEnabled": true,
"anonymousPullEnabled": true,
"dataEndpointEnabled": true,
"encryption": {
"keyVaultProperties": {
"identity": "someIdentity",
"keyIdentifier": "someKeyIdentifier"
},
"status": "enabled"
},
"policies": {
"quarantinePolicy": {
"status": "disabled"
}
},
"networkRuleBypassOptions": "AzureServices",
"networkRuleSet": {
"defaultAction": "Deny",
"ipRules": [
{
"action": "Allow",
"value": "127.0.0.1"
}
]
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"resources": [
{
"apiVersion": "2019-05-01",
"type": "Microsoft.ContainerRegistry/registries",
"name": "pass",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard"
},
"properties": {
"adminUserEnabled": true,
"anonymousPullEnabled": true,
"dataEndpointEnabled": true,
"encryption": {
"keyVaultProperties": {
"identity": "someIdentity",
"keyIdentifier": "someKeyIdentifier"
},
"status": "enabled"
},
"policies": {
"quarantinePolicy": {
"status": "enabled"
}
},
"networkRuleBypassOptions": "AzureServices",
"networkRuleSet": {
"defaultAction": "Deny",
"ipRules": [
{
"action": "Allow",
"value": "127.0.0.1"
}
]
}
}
}
]
}
41 changes: 41 additions & 0 deletions tests/arm/checks/resource/test_ACREnableImageQuarantine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import unittest

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


class TestACREnableImageQuarantine(unittest.TestCase):

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

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

passing_resources = {
'Microsoft.ContainerRegistry/registries.pass',
}
failing_resources = {
'Microsoft.ContainerRegistry/registries.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()
Loading