-
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.
fix(terraform): Update CKV_AZURE_167 to correct check on retention po…
…licy (#6758) * fix: Update CKV_AZURE_167 to correct check on retention policy * Include old method --------- Co-authored-by: Taylor <[email protected]> Co-authored-by: Taylor <[email protected]>
- Loading branch information
1 parent
25333ca
commit 3e46e49
Showing
3 changed files
with
42 additions
and
20 deletions.
There are no files selected for viewing
23 changes: 18 additions & 5 deletions
23
checkov/terraform/checks/resource/azure/ACREnableRetentionPolicy.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 |
---|---|---|
@@ -1,17 +1,30 @@ | ||
from checkov.common.models.enums import CheckCategories | ||
from checkov.terraform.checks.resource.base_resource_value_check import BaseResourceValueCheck | ||
from typing import Dict, List, Any | ||
|
||
from checkov.common.models.enums import CheckResult, CheckCategories | ||
from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck | ||
|
||
class ACREnableRetentionPolicy(BaseResourceValueCheck): | ||
|
||
class ACREnableRetentionPolicy(BaseResourceCheck): | ||
def __init__(self) -> None: | ||
name = "Ensure a retention policy is set to cleanup untagged manifests." | ||
id = "CKV_AZURE_167" | ||
supported_resources = ("azurerm_container_registry",) | ||
categories = (CheckCategories.GENERAL_SECURITY,) | ||
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources) | ||
|
||
def get_inspected_key(self) -> str: | ||
return "retention_policy/enabled" | ||
def scan_resource_conf(self, conf: Dict[str, List[Any]]) -> CheckResult: | ||
if 'retention_policy_in_days' in conf: | ||
return CheckResult.PASSED | ||
|
||
if 'retention_policy' in conf: | ||
retention_policy = conf['retention_policy'][0] | ||
if isinstance(retention_policy, dict) and retention_policy.get('enabled') == [True]: | ||
return CheckResult.PASSED | ||
|
||
return CheckResult.FAILED | ||
|
||
def get_evaluated_keys(self) -> List[str]: | ||
return ['retention_policy_in_days', 'retention_policy/enabled'] | ||
|
||
|
||
check = ACREnableRetentionPolicy() |
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
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