-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(arm): implement CKV_AZURE_100 for arm (#5490)
* feat(arm): implement CKV_AZURE_100 for arm * feat(arm): implement CKV_AZURE_100 for arm
- Loading branch information
1 parent
d4ccffe
commit d70f1dc
Showing
6 changed files
with
300 additions
and
92 deletions.
There are no files selected for viewing
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,21 @@ | ||
from checkov.common.models.consts import ANY_VALUE | ||
from checkov.common.models.enums import CheckCategories | ||
from checkov.arm.base_resource_value_check import BaseResourceValueCheck | ||
|
||
|
||
class CosmosDBHaveCMK(BaseResourceValueCheck): | ||
def __init__(self): | ||
name = "Ensure that Cosmos DB accounts have customer-managed keys to encrypt data at rest" | ||
id = "CKV_AZURE_100" | ||
supported_resources = ['Microsoft.DocumentDb/databaseAccounts'] | ||
categories = [CheckCategories.NETWORKING] | ||
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources) | ||
|
||
def get_inspected_key(self): | ||
return 'properties/keyVaultKeyUri' | ||
|
||
def get_expected_value(self): | ||
return ANY_VALUE | ||
|
||
|
||
check = CosmosDBHaveCMK() |
65 changes: 65 additions & 0 deletions
65
tests/arm/checks/resource/example_CosmosDBHaveCMK/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,65 @@ | ||
{ | ||
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"location": { | ||
"type": "string" | ||
}, | ||
"locationName": { | ||
"type": "string" | ||
}, | ||
"defaultExperience": { | ||
"type": "string" | ||
}, | ||
"isZoneRedundant": { | ||
"type": "string" | ||
} | ||
}, | ||
"variables": {}, | ||
"resources": [ | ||
{ | ||
"apiVersion": "2023-03-15-preview", | ||
"kind": "GlobalDocumentDB", | ||
"type": "Microsoft.DocumentDb/databaseAccounts", | ||
"name": "fail", | ||
"location": "[parameters('location')]", | ||
"properties": { | ||
"databaseAccountOfferType": "Standard", | ||
"locations": [ | ||
{ | ||
"id": "[concat(parameters('name'), '-', parameters('location'))]", | ||
"failoverPriority": 0, | ||
"locationName": "[parameters('locationName')]" | ||
} | ||
], | ||
"backupPolicy": { | ||
"type": "Periodic", | ||
"periodicModeProperties": { | ||
"backupIntervalInMinutes": 240, | ||
"backupRetentionIntervalInHours": 8, | ||
"backupStorageRedundancy": "Geo" | ||
} | ||
}, | ||
"isVirtualNetworkFilterEnabled": false, | ||
"virtualNetworkRules": [], | ||
"ipRules": [], | ||
"dependsOn": [], | ||
"minimalTlsVersion": "Tls12", | ||
"enableMultipleWriteLocations": false, | ||
"capabilities": [], | ||
"enableFreeTier": true, | ||
"capacity": { | ||
"totalThroughputLimit": 1000 | ||
} | ||
}, | ||
"tags": { | ||
"defaultExperience": "[parameters('defaultExperience')]", | ||
"hidden-cosmos-mmspecial": "" | ||
} | ||
} | ||
], | ||
"outputs": {} | ||
} |
66 changes: 66 additions & 0 deletions
66
tests/arm/checks/resource/example_CosmosDBHaveCMK/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,66 @@ | ||
{ | ||
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"location": { | ||
"type": "string" | ||
}, | ||
"locationName": { | ||
"type": "string" | ||
}, | ||
"defaultExperience": { | ||
"type": "string" | ||
}, | ||
"isZoneRedundant": { | ||
"type": "string" | ||
} | ||
}, | ||
"variables": {}, | ||
"resources": [ | ||
{ | ||
"apiVersion": "2023-03-15-preview", | ||
"kind": "GlobalDocumentDB", | ||
"type": "Microsoft.DocumentDb/databaseAccounts", | ||
"name": "pass", | ||
"location": "[parameters('location')]", | ||
"properties": { | ||
"databaseAccountOfferType": "Standard", | ||
"locations": [ | ||
{ | ||
"id": "[concat(parameters('name'), '-', parameters('location'))]", | ||
"failoverPriority": 0, | ||
"locationName": "[parameters('locationName')]" | ||
} | ||
], | ||
"backupPolicy": { | ||
"type": "Periodic", | ||
"periodicModeProperties": { | ||
"backupIntervalInMinutes": 240, | ||
"backupRetentionIntervalInHours": 8, | ||
"backupStorageRedundancy": "Geo" | ||
} | ||
}, | ||
"isVirtualNetworkFilterEnabled": false, | ||
"virtualNetworkRules": [], | ||
"ipRules": [], | ||
"dependsOn": [], | ||
"minimalTlsVersion": "Tls12", | ||
"enableMultipleWriteLocations": false, | ||
"capabilities": [], | ||
"enableFreeTier": true, | ||
"capacity": { | ||
"totalThroughputLimit": 1000 | ||
}, | ||
"keyVaultKeyUri": "https://examplekeyvaultjgw.vault.azure.net/keys/temp" | ||
}, | ||
"tags": { | ||
"defaultExperience": "[parameters('defaultExperience')]", | ||
"hidden-cosmos-mmspecial": "" | ||
} | ||
} | ||
], | ||
"outputs": {} | ||
} |
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.checks.resource.CosmosDBHaveCMK import check | ||
from checkov.arm.runner import Runner | ||
from checkov.runner_filter import RunnerFilter | ||
|
||
|
||
class TestCosmosDBHaveCMK(unittest.TestCase): | ||
def test_summary(self): | ||
# given | ||
test_files_dir = Path(__file__).parent / "example_CosmosDBHaveCMK" | ||
|
||
# when | ||
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[check.id])) | ||
|
||
# then | ||
summary = report.get_summary() | ||
|
||
passing_resources = { | ||
"Microsoft.DocumentDb/databaseAccounts.pass", | ||
} | ||
failing_resources = { | ||
"Microsoft.DocumentDb/databaseAccounts.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() |
78 changes: 78 additions & 0 deletions
78
tests/terraform/checks/resource/azure/example_CosmosDBHaveCMK/main.tf
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,78 @@ | ||
|
||
resource "azurerm_cosmosdb_account" "fail" { | ||
name = "tfex-cosmos-db-${random_integer.ri.result}" | ||
location = azurerm_resource_group.rg.location | ||
resource_group_name = azurerm_resource_group.rg.name | ||
offer_type = "Standard" | ||
kind = "GlobalDocumentDB" | ||
|
||
enable_automatic_failover = true | ||
|
||
capabilities { | ||
name = "EnableAggregationPipeline" | ||
} | ||
|
||
capabilities { | ||
name = "mongoEnableDocLevelTTL" | ||
} | ||
|
||
capabilities { | ||
name = "MongoDBv3.4" | ||
} | ||
|
||
consistency_policy { | ||
consistency_level = "BoundedStaleness" | ||
max_interval_in_seconds = 10 | ||
max_staleness_prefix = 200 | ||
} | ||
|
||
geo_location { | ||
location = var.failover_location | ||
failover_priority = 1 | ||
} | ||
|
||
geo_location { | ||
location = azurerm_resource_group.rg.location | ||
failover_priority = 0 | ||
} | ||
} | ||
|
||
resource "azurerm_cosmosdb_account" "pass" { | ||
name = "tfex-cosmos-db-${random_integer.ri.result}" | ||
location = azurerm_resource_group.rg.location | ||
resource_group_name = azurerm_resource_group.rg.name | ||
offer_type = "Standard" | ||
kind = "GlobalDocumentDB" | ||
|
||
enable_automatic_failover = true | ||
|
||
capabilities { | ||
name = "EnableAggregationPipeline" | ||
} | ||
|
||
capabilities { | ||
name = "mongoEnableDocLevelTTL" | ||
} | ||
|
||
capabilities { | ||
name = "MongoDBv3.4" | ||
} | ||
|
||
consistency_policy { | ||
consistency_level = "BoundedStaleness" | ||
max_interval_in_seconds = 10 | ||
max_staleness_prefix = 200 | ||
} | ||
|
||
geo_location { | ||
location = var.failover_location | ||
failover_priority = 1 | ||
} | ||
|
||
geo_location { | ||
location = azurerm_resource_group.rg.location | ||
failover_priority = 0 | ||
} | ||
|
||
key_vault_key_id = "A versionless Key Vault Key ID for CMK encryption" | ||
} |
Oops, something went wrong.