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_86 to check resorce is a ContainerRegistry with tier "Standard" #6336

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions checkov/arm/checks/resource/AzureDefenderOnContainerRegistry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations

from typing import List, Any

from checkov.arm.base_resource_check import BaseResourceCheck
from checkov.common.models.enums import CheckCategories, CheckResult


class AzureDefenderOnContainerRegistry(BaseResourceCheck):

def __init__(self) -> None:
name = "Ensure that Azure Defender is set to On for Container Registries"
id = "CKV_AZURE_86"
supported_resources = ("Microsoft.Security/pricings",)
categories = (CheckCategories.GENERAL_SECURITY,)
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

def scan_resource_conf(self, conf: dict[str, Any]) -> CheckResult:
properties = conf.get("properties", {})

pricingTier = properties.get("pricingTier")

type = properties.get("type")

return (

CheckResult.PASSED

if type != "ContainerRegistry" or pricingTier == "Standard"

else CheckResult.FAILED
)

def get_evaluated_keys(self) -> List[str]:
return ["properties/pricingTier ", "properties/type"]


check = AzureDefenderOnContainerRegistry()
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [{
"type": "Microsoft.Security/pricings",
"apiVersion": "2023-01-01",
"name": "fail",
"properties": {
"pricingTier": "Free",
"type": "ContainerRegistry"
}
}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [{
"type": "Microsoft.Security/pricings",
"apiVersion": "2023-01-01",
"name": "pass",
"properties": {
"pricingTier": "Standard",
"type": "StorageAccounts"
}
}]}
40 changes: 40 additions & 0 deletions tests/arm/checks/resource/test_AzureDefenderOnContainerRegistry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import unittest
from pathlib import Path
from checkov.arm.runner import Runner
from checkov.arm.checks.resource.AzureDefenderOnContainerRegistry import check
from checkov.runner_filter import RunnerFilter


class TestAzureDefenderOnContainerRegistry(unittest.TestCase):

def test_summary(self):
# given
test_files_dir = Path(__file__).parent / "example_AzureDefenderOnContainerRegistry"

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

# then
summary = report.get_summary()

passing_resources = {
"Microsoft.Security/pricings.pass",
}
failing_resources = {
"Microsoft.Security/pricings.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"], len(passing_resources))
self.assertEqual(summary["failed"], len(failing_resources))
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()
Loading