Skip to content
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

feat(arm): add CKV_AZURE_145 to check that the function app uses the latest version of TLS encryption #6323

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions checkov/arm/checks/resource/FunctionAppMinTLSVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Any, List

from checkov.common.models.enums import CheckResult, CheckCategories
from checkov.arm.base_resource_value_check import BaseResourceValueCheck


class FunctionAppMinTLSVersion(BaseResourceValueCheck):
def __init__(self) -> None:
name = "Ensure Function app is using the latest version of TLS encryption"
id = "CKV_AZURE_145"
supported_resources = ('Microsoft.Web/sites', 'Microsoft.Web/sites/slots',)
categories = [CheckCategories.NETWORKING]
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources,
missing_block_result=CheckResult.PASSED)

def get_inspected_key(self) -> str:
return "properties/siteConfig/minTlsVersion"

def get_expected_value(self) -> Any:
return 1.2

def get_expected_values(self) -> List[Any]:
return ["1.2", 1.2]


check = FunctionAppMinTLSVersion()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2021-02-01",
"name": "fail",
"location": "[resourceGroup().location]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'example-app-service-plan')]",
"siteConfig": {
"minTlsVersion": "1.1"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/sites/slots",
"apiVersion": "2021-02-01",
"name": "fail2",
"location": "[resourceGroup().location]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'example-app-service-plan')]",
"siteConfig": {
"minTlsVersion": "1.1"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2021-02-01",
"name": "pass",
"location": "[resourceGroup().location]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'example-app-service-plan')]",
"siteConfig": {
"minTlsVersion": "1.2"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2021-02-01",
"name": "pass2",
"location": "[resourceGroup().location]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'example-app-service-plan')]",
"siteConfig": {
"minTlsVersion": 1.2
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/sites/slots",
"apiVersion": "2021-02-01",
"name": "pass3",
"location": "[resourceGroup().location]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'example-app-service-plan')]",
"siteConfig": {
"minTlsVersion": "1.2"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/sites/slots",
"apiVersion": "2021-02-01",
"name": "pass4",
"location": "[resourceGroup().location]",
"kind": "functionapp,linux",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'example-app-service-plan')]",
"siteConfig": {
"minTlsVersion": 1.2
}
}
}
]
}
44 changes: 44 additions & 0 deletions tests/arm/checks/resource/test_FunctionAppMinTLSVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import unittest
from pathlib import Path

from checkov.arm.checks.resource.FunctionAppMinTLSVersion import check
from checkov.arm.runner import Runner
from checkov.runner_filter import RunnerFilter


class TestFunctionAppMinTLSVersion(unittest.TestCase):
def test_summary(self):
# given
test_files_dir = Path(__file__).parent / "example_FunctionAppMinTLSVersion"

# when
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[check.id]))

# then
summary = report.get_summary()

passing_resources = {
"Microsoft.Web/sites.pass",
"Microsoft.Web/sites.pass2",
"Microsoft.Web/sites/slots.pass3",
"Microsoft.Web/sites/slots.pass4",
}
failing_resources = {
"Microsoft.Web/sites.fail",
"Microsoft.Web/sites/slots.fail2",
}

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()
Loading