-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(terraform): Fix CKV_AZURE_227 for Azure V4 #6906
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d09fab7
Fix CKV_AZURE_227
tsmithv11 85b8bc9
Fix CKV_AZURE_145
tsmithv11 12b5b61
fix flake8
tsmithv11 3afec0e
add flexible servers
tsmithv11 5d63a08
fix flake8
tsmithv11 8f8498a
Fix CKV_AZURE_11
tsmithv11 f358902
Update checks
tsmithv11 b4e1a51
Update check
tsmithv11 1eeefb7
Update check
tsmithv11 b7d99e7
Add types
tsmithv11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to update the evaluated_keys here? What is the reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For highlighting in the platform (and fix suggestions, but not relevant for this check)