-
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): Fix CKV_AZURE_227 for Azure V4 (#6906)
* Fix CKV_AZURE_227 * Fix CKV_AZURE_145 * fix flake8 * add flexible servers * fix flake8 * Fix CKV_AZURE_11 * Update checks * Update check * Update check * Add types
- Loading branch information
Showing
23 changed files
with
368 additions
and
77 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
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
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
25 changes: 16 additions & 9 deletions
25
checkov/terraform/checks/resource/azure/AKSNodePublicIpDisabled.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,21 +1,28 @@ | ||
from checkov.common.models.enums import CheckCategories | ||
from checkov.terraform.checks.resource.base_resource_negative_value_check import BaseResourceNegativeValueCheck | ||
from typing import List, Any | ||
from typing import Dict, List, Any | ||
|
||
from checkov.common.models.enums import CheckCategories, CheckResult | ||
from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck | ||
|
||
class AKSNodePublicIpDisabled(BaseResourceNegativeValueCheck): | ||
def __init__(self): | ||
|
||
class AKSNodePublicIpDisabled(BaseResourceCheck): | ||
def __init__(self) -> None: | ||
name = "Ensure AKS cluster nodes do not have public IP addresses" | ||
id = "CKV_AZURE_143" | ||
supported_resources = ['azurerm_kubernetes_cluster'] | ||
categories = [CheckCategories.NETWORKING] | ||
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources) | ||
|
||
def get_inspected_key(self) -> str: | ||
return "default_node_pool/[0]/enable_node_public_ip" | ||
def scan_resource_conf(self, conf: Dict[str, List[Any]]) -> CheckResult: | ||
if 'default_node_pool' in conf: | ||
default_node_pool = conf['default_node_pool'][0] | ||
if isinstance(default_node_pool, dict): | ||
if default_node_pool.get('enable_node_public_ip') == [True] or default_node_pool.get('node_public_ip_enabled') == [True]: | ||
return CheckResult.FAILED | ||
|
||
return CheckResult.PASSED | ||
|
||
def get_forbidden_values(self) -> List[Any]: | ||
return [True] | ||
def get_evaluated_keys(self) -> List[str]: | ||
return ['default_node_pool/[0]/enable_node_public_ip', 'default_node_pool/[0]/node_public_ip_enabled'] | ||
|
||
|
||
check = AKSNodePublicIpDisabled() |
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
66 changes: 66 additions & 0 deletions
66
tests/arm/checks/resource/example_TestMySQLPublicAccessDisabled/fail2.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": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.DBforMySQL/flexibleServers", | ||
"apiVersion": "2024-10-01-preview", | ||
"name": "fail2", | ||
"identity": { | ||
"type": "UserAssigned", | ||
"userAssignedIdentities": { | ||
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {} | ||
} | ||
}, | ||
"location": "eastus", | ||
"properties": { | ||
"administratorLogin": "adminuser", | ||
"administratorLoginPassword": "YourSecurePassword123!", | ||
"availabilityZone": "1", | ||
"backup": { | ||
"backupIntervalHours": 24, | ||
"backupRetentionDays": 7, | ||
"geoRedundantBackup": "Disabled" | ||
}, | ||
"createMode": "Default", | ||
"databasePort": 3306, | ||
"dataEncryption": { | ||
"type": "SystemManaged" | ||
}, | ||
"highAvailability": { | ||
"mode": "ZoneRedundant", | ||
"standbyAvailabilityZone": "2" | ||
}, | ||
"maintenancePolicy": { | ||
"patchStrategy": "Automatic" | ||
}, | ||
"maintenanceWindow": { | ||
"customWindow": "Sun:02:00-Sun:04:00", | ||
"dayOfWeek": 0, | ||
"startHour": 2, | ||
"startMinute": 0 | ||
}, | ||
"network": { | ||
"delegatedSubnetResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/myVNet/subnets/mySubnet", | ||
"privateDnsZoneResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/privateDnsZones/myPrivateDnsZone", | ||
"publicNetworkAccess": "Enabled" | ||
}, | ||
"storage": { | ||
"autoGrow": "Enabled", | ||
"iops": 600, | ||
"storageSizeGB": 128, | ||
"storageRedundancy": "Zone" | ||
}, | ||
"version": "8.0" | ||
}, | ||
"sku": { | ||
"name": "Standard_D2ds_v4", | ||
"tier": "GeneralPurpose" | ||
}, | ||
"tags": { | ||
"Environment": "Production", | ||
"Project": "MySQLMigration" | ||
} | ||
} | ||
] | ||
} |
66 changes: 66 additions & 0 deletions
66
tests/arm/checks/resource/example_TestMySQLPublicAccessDisabled/pass2.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": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.DBforMySQL/flexibleServers", | ||
"apiVersion": "2024-10-01-preview", | ||
"name": "pass2", | ||
"identity": { | ||
"type": "UserAssigned", | ||
"userAssignedIdentities": { | ||
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myIdentity": {} | ||
} | ||
}, | ||
"location": "eastus", | ||
"properties": { | ||
"administratorLogin": "adminuser", | ||
"administratorLoginPassword": "YourSecurePassword123!", | ||
"availabilityZone": "1", | ||
"backup": { | ||
"backupIntervalHours": 24, | ||
"backupRetentionDays": 7, | ||
"geoRedundantBackup": "Disabled" | ||
}, | ||
"createMode": "Default", | ||
"databasePort": 3306, | ||
"dataEncryption": { | ||
"type": "SystemManaged" | ||
}, | ||
"highAvailability": { | ||
"mode": "ZoneRedundant", | ||
"standbyAvailabilityZone": "2" | ||
}, | ||
"maintenancePolicy": { | ||
"patchStrategy": "Automatic" | ||
}, | ||
"maintenanceWindow": { | ||
"customWindow": "Sun:02:00-Sun:04:00", | ||
"dayOfWeek": 0, | ||
"startHour": 2, | ||
"startMinute": 0 | ||
}, | ||
"network": { | ||
"delegatedSubnetResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/myVNet/subnets/mySubnet", | ||
"privateDnsZoneResourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/privateDnsZones/myPrivateDnsZone", | ||
"publicNetworkAccess": "Disabled" | ||
}, | ||
"storage": { | ||
"autoGrow": "Enabled", | ||
"iops": 600, | ||
"storageSizeGB": 128, | ||
"storageRedundancy": "Zone" | ||
}, | ||
"version": "8.0" | ||
}, | ||
"sku": { | ||
"name": "Standard_D2ds_v4", | ||
"tier": "GeneralPurpose" | ||
}, | ||
"tags": { | ||
"Environment": "Production", | ||
"Project": "MySQLMigration" | ||
} | ||
} | ||
] | ||
} |
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
Oops, something went wrong.