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): AzureDefenderOStorage #6269

Merged
merged 24 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f31821d
Storage Sync Public Access Disabled as arm
shoshiGit Apr 9, 2024
61b10d6
Storage Sync Public Access Disabled as arm
shoshiGit Apr 9, 2024
787f41d
Merge branch 'bridgecrewio:main' into main
shoshiGit Apr 9, 2024
06e5548
Revert "Storage Sync Public Access Disabled as arm"
shoshiGit May 5, 2024
450b6a9
Merge branch 'bridgecrewio:main' into main
shoshiGit May 7, 2024
133b8b1
remove unneccessary file1
shoshiGit May 7, 2024
bb54b86
remove unneccessary file2
shoshiGit May 7, 2024
e624bfa
AzureDefenderOnStorage
shoshiGit May 7, 2024
a832df5
Merge remote-tracking branch 'origin/AzureDefenderOnStorage1' into Az…
shoshiGit May 7, 2024
f03bdaa
AzureDefenderOnStorage updated resource file
shoshiGit May 7, 2024
8aa10cf
AzureDefenderOnStorage fix resource type
shoshiGit May 8, 2024
ac67212
AzureDefenderOnStorage fix resourceType
shoshiGit May 8, 2024
9be9136
AzureDefenderOnStorage fix 3
shoshiGit May 8, 2024
aa6334a
AzureDefenderOnStorage fix 4
shoshiGit May 12, 2024
ff32550
Merge branch 'main' into AzureDefenderOnStorage1
shoshiGit May 16, 2024
908ebcf
AzureDefenderOnStorage fix 5
shoshiGit May 19, 2024
63ce79b
Merge remote-tracking branch 'origin/AzureDefenderOnStorage1' into Az…
shoshiGit May 19, 2024
9e70e3f
AzureDefenderOnStorage fix 5
shoshiGit May 19, 2024
578f3d1
AzureDefenderOnStorage fix 5
shoshiGit May 19, 2024
cd9c8a7
AzureDefenderOnStorage fix 6
shoshiGit May 20, 2024
c1c8acc
Merge branch 'main' into AzureDefenderOnStorage1
shoshiGit May 20, 2024
9ab6d1c
AzureDefenderOnStorage fix 7
shoshiGit May 20, 2024
810d3f9
Merge remote-tracking branch 'origin/AzureDefenderOnStorage1' into Az…
shoshiGit May 20, 2024
02a52aa
Merge branch 'main' into AzureDefenderOnStorage1
shoshiGit May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions checkov/arm/checks/resource/AzureDefenderOnStorage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import List, Any, Dict
from checkov.common.models.enums import CheckCategories, CheckResult
from checkov.arm.base_resource_check import BaseResourceCheck


class AzureDefenderOnStorage(BaseResourceCheck):
def __init__(self) -> None:
name = "Ensure that Azure Defender is set to On for Storage"
id = "CKV_AZURE_84"
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: Dict[str, Any] = conf.get("properties", {})
pricingTier = properties.get("pricingTier", "")
resourceType = properties.get("resourceType", "")
return (
CheckResult.PASSED
if resourceType != "Microsoft.Security/pricings" or pricingTier == "Standard"
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the if resourceType != "Microsoft.Security/pricings" - in ARM it will always be this type.
(Just for terraform it can be other types as well)

else CheckResult.FAILED
)

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


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


class TestAzureDefenderOnStorage(unittest.TestCase):
def test_summary(self):
test_files_dir = Path(__file__).parent / "example_AzureDefenderOnStorage"
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[check.id]))
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(passed_check_resources, passing_resources)
self.assertEqual(failed_check_resources, failing_resources)


if __name__ == '__main__':
unittest.main()