-
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: Update CKV_AZURE_164 to correct check on trust policy
- Loading branch information
1 parent
c1c6ef6
commit 01f3513
Showing
4 changed files
with
66 additions
and
41 deletions.
There are no files selected for viewing
28 changes: 21 additions & 7 deletions
28
checkov/terraform/checks/resource/azure/ACRUseSignedImages.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,23 +1,37 @@ | ||
from __future__ import annotations | ||
|
||
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_value_check import BaseResourceCheck | ||
|
||
|
||
class ACRUseSignedImages(BaseResourceValueCheck): | ||
class ACRUseSignedImages(BaseResourceCheck): | ||
|
||
def __init__(self): | ||
# IN ARM - Set properties.trustPolicy.status to enabled, set | ||
# properties.trustPolicy.type to Notary | ||
# IN ARM - Set properties.policies.trustPolicy.status to enabled, set | ||
# properties.policies.trustPolicy.type to Notary | ||
# This is the default behaviour by the tf provider when the trust policy is enabled | ||
name = "Ensures that ACR uses signed/trusted images" | ||
id = "CKV_AZURE_164" | ||
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): | ||
return "trust_policy/[0]/enabled" | ||
def scan_resource_conf(self, conf: Dict[str, List[Any]]) -> CheckResult: | ||
if 'trust_policy_enabled' in conf: | ||
trust_policy_enabled = conf.get('trust_policy_enabled') | ||
if isinstance(trust_policy_enabled, list) and trust_policy_enabled == [True]: | ||
return CheckResult.PASSED | ||
|
||
if 'trust_policy' in conf: | ||
trust_policy = conf['trust_policy'][0] | ||
if isinstance(trust_policy, dict) and trust_policy.get('enabled') == [True]: | ||
return CheckResult.PASSED | ||
|
||
return CheckResult.FAILED | ||
|
||
def get_evaluated_keys(self) -> List[str]: | ||
return ['trust_policy_enabled', 'trust_policy/enabled'] | ||
|
||
|
||
check = ACRUseSignedImages() |
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
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