-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
rutiNalenger
wants to merge
16
commits into
bridgecrewio:main
Choose a base branch
from
rutiNalenger:AzureDefenderOnContainerRegistry2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
84adb24
FunctionAppsEnableAuthentication1
rutiNalenger 1660dfc
FunctionAppsEnableAuthentication1
rutiNalenger b26b579
FunctionAppsEnableAuthentication1
rutiNalenger 745880b
FunctionAppsEnableAuthentication1
rutiNalenger d8c3949
FunctionAppsEnableAuthentication1
rutiNalenger a1c9772
FunctionAppsEnableAuthentication1
rutiNalenger e986c41
remove unnecessary changes
rutiNalenger ce171fd
remove unnecessary changes
rutiNalenger bb0a852
remove unnecessary changes
rutiNalenger d3cdcc3
remove unnecessary changes
rutiNalenger e8ac4ee
AzureDefenderOnContainerRegistry
rutiNalenger e240545
Merge branch 'bridgecrewio:main' into AzureDefenderOnContainerRegistry2
rutiNalenger d9043f8
removed unnecessary files
rutiNalenger 9de3d28
Fixed the resource type
rutiNalenger 3f876a9
Fixed
rutiNalenger 575c313
Fixed
rutiNalenger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
checkov/arm/checks/resource/AzureDefenderOnContainerRegistry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
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() |
12 changes: 12 additions & 0 deletions
12
tests/arm/checks/resource/example_AzureDefenderOnContainerRegistry/fail.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
}]} |
12 changes: 12 additions & 0 deletions
12
tests/arm/checks/resource/example_AzureDefenderOnContainerRegistry/pass.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
tests/arm/checks/resource/test_AzureDefenderOnContainerRegistry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
andresourceType
fields inMicrosoft.ContainerRegistry/registries
Probably this is not the resource type.