Skip to content

Commit

Permalink
feat(arm): DataLakeStoreEncryption (#6516)
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
shoshiGit authored Jul 3, 2024
1 parent 2ded048 commit aa5efbb
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
20 changes: 20 additions & 0 deletions checkov/arm/checks/resource/DataLakeStoreEncryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from checkov.common.models.enums import CheckResult, CheckCategories
from checkov.arm.base_resource_value_check import BaseResourceValueCheck


class DataLakeStoreEncryption(BaseResourceValueCheck):
def __init__(self) -> None:
name = "Ensure that Data Lake Store accounts enables encryption"
id = "CKV_AZURE_105"
supported_resources = ['Microsoft.DataLakeStore/accounts',]
categories = [CheckCategories.ENCRYPTION,]
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources, missing_block_result=CheckResult.PASSED)

def get_inspected_key(self) -> str:
return 'properties/encryptionState'

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


check = DataLakeStoreEncryption()
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.DataLakeStore/accounts",
"apiVersion": "2016-11-01",
"name": "fail",
"location": "[resourceGroup().location]",
"properties": {
"encryptionState": "Disabled"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.DataLakeStore/accounts",
"apiVersion": "2016-11-01",
"name": "pass",
"location": "[resourceGroup().location]",
"properties": {
}
}
]
}
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.DataLakeStore/accounts",
"apiVersion": "2016-11-01",
"name": "pass2",
"location": "[resourceGroup().location]",
"properties": {
"encryptionState": "Enabled"
}
}
]
}
43 changes: 43 additions & 0 deletions tests/arm/checks/resource/test_DataLakeStoreEncryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import unittest
from pathlib import Path

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


class TestDataLakeStoreEncryption(unittest.TestCase):

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

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

# then
summary = report.get_summary()

passing_resources = {
"Microsoft.DataLakeStore/accounts.pass",
"Microsoft.DataLakeStore/accounts.pass2",
}
failing_resources = {
"Microsoft.DataLakeStore/accounts.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()

0 comments on commit aa5efbb

Please sign in to comment.