-
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.
Check which version of TLS is enforced (#2484)
* Check which version of TFL is enforced * I see typos
- Loading branch information
1 parent
5d081f7
commit 9ac786c
Showing
6 changed files
with
92 additions
and
7 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
21 changes: 21 additions & 0 deletions
21
checkov/terraform/checks/resource/azure/PostgreSQLMinTLSVersion.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from checkov.common.models.enums import CheckResult, CheckCategories | ||
from checkov.terraform.checks.resource.base_resource_value_check import BaseResourceValueCheck | ||
|
||
|
||
class PostgreSQLMinTLSVersion(BaseResourceValueCheck): | ||
def __init__(self): | ||
name = "Ensure PostgreSQL is using the latest version of TLS encryption" | ||
id = "CKV_AZURE_147" | ||
supported_resources = ['azurerm_postgresql_server'] | ||
categories = [CheckCategories.NETWORKING] | ||
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources, | ||
missing_block_result=CheckResult.FAILED) | ||
|
||
def get_inspected_key(self): | ||
return "ssl_minimal_tls_version_enforced" | ||
|
||
def get_expected_value(self): | ||
return 'TLS1_2' | ||
|
||
|
||
check = PostgreSQLMinTLSVersion() |
23 changes: 23 additions & 0 deletions
23
tests/terraform/checks/resource/azure/example_PostgreSQLMinTLSVersion/main.tf
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,23 @@ | ||
resource "azurerm_postgresql_server" "fail" { | ||
name = "fail" | ||
|
||
public_network_access_enabled = true | ||
ssl_enforcement_enabled = true | ||
ssl_minimal_tls_version_enforced = "TLS1_1" | ||
} | ||
|
||
|
||
resource "azurerm_postgresql_server" "pass" { | ||
name = "fail" | ||
|
||
public_network_access_enabled = true | ||
ssl_enforcement_enabled = true | ||
ssl_minimal_tls_version_enforced = "TLS1_2" | ||
} | ||
|
||
resource "azurerm_postgresql_server" "fail2" { | ||
name = "fail" | ||
|
||
public_network_access_enabled = true | ||
ssl_enforcement_enabled = true | ||
} |
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
42 changes: 42 additions & 0 deletions
42
tests/terraform/checks/resource/azure/test_PostgreSQLMinTLSVersion.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import unittest | ||
from pathlib import Path | ||
|
||
from checkov.runner_filter import RunnerFilter | ||
from checkov.terraform.checks.resource.azure.PostgreSQLMinTLSVersion import check | ||
from checkov.terraform.runner import Runner | ||
|
||
|
||
class TestPostgreSQLMinTLSVersion(unittest.TestCase): | ||
|
||
def test(self): | ||
# given | ||
test_files_dir = Path(__file__).parent / "example_PostgreSQLMinTLSVersion" | ||
|
||
# when | ||
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[check.id])) | ||
|
||
# then | ||
summary = report.get_summary() | ||
|
||
passing_resources = { | ||
"azurerm_postgresql_server.pass", | ||
} | ||
failing_resources = { | ||
"azurerm_postgresql_server.fail", | ||
"azurerm_postgresql_server.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"], 1) | ||
self.assertEqual(summary["failed"], 2) | ||
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() |