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 13 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
36 changes: 36 additions & 0 deletions checkov/arm/checks/resource/AzureDefenderOnContainerRegistry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

from typing import List

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.ContainerRegistry/registries",)
categories = (CheckCategories.GENERAL_SECURITY,)
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources)

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

tier = properties.get("tier")

resourceType = properties.get("resourceType")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see tier and resourceType fields in Microsoft.ContainerRegistry/registries
Probably this is not the resource type.


return (

CheckResult.PASSED

if resourceType != "ContainerRegistry" or tier == "Standard"

else CheckResult.FAILED
)

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


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.ContainerRegistry/registries",
"apiVersion": "2023-01-01",
"name": "fail",
"properties": {
"tier": "Free",
"resourceType": "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.ContainerRegistry/registries",
"apiVersion": "2023-01-01",
"name": "pass",
"properties": {
"tier": "Standard",
"resourceType": "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.ContainerRegistry/registries.pass",
}
failing_resources = {
"Microsoft.ContainerRegistry/registries.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