-
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): Ensure HTTPS in Azure Function App and App Slots (#5766)
fix(terraform):Ensure HTTPS in Azure Function App and App Slots
- Loading branch information
Showing
4 changed files
with
252 additions
and
51 deletions.
There are no files selected for viewing
41 changes: 34 additions & 7 deletions
41
checkov/terraform/checks/resource/azure/FunctionAppsAccessibleOverHttps.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,17 +1,44 @@ | ||
from checkov.common.models.enums import CheckCategories | ||
from checkov.terraform.checks.resource.base_resource_value_check import BaseResourceValueCheck | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
class FunctionAppsAccessibleOverHttps(BaseResourceValueCheck): | ||
def __init__(self): | ||
from checkov.common.models.enums import CheckCategories, CheckResult | ||
from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck | ||
|
||
|
||
class FunctionAppsAccessibleOverHttps(BaseResourceCheck): | ||
|
||
def __init__(self) -> None: | ||
name = "Ensure that Function apps is only accessible over HTTPS" | ||
id = "CKV_AZURE_70" | ||
supported_resources = ['azurerm_function_app'] | ||
supported_resources = ['azurerm_function_app', 'azurerm_linux_function_app', 'azurerm_windows_function_app', | ||
'azurerm_function_app_slot', 'azurerm_linux_function_app_slot', | ||
'azurerm_windows_function_app_slot'] | ||
categories = [CheckCategories.NETWORKING] | ||
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources) | ||
|
||
def get_inspected_key(self): | ||
return 'https_only' | ||
def scan_resource_conf(self, conf: dict[str, list[Any]]) -> CheckResult: | ||
# default=false for https_only | ||
if 'https_only' not in conf.keys(): | ||
return CheckResult.FAILED | ||
|
||
https_only = conf.get('https_only')[0] | ||
if not https_only: | ||
return CheckResult.FAILED | ||
|
||
# relevant for linux/windows resources | ||
if 'auth_settings_v2' in conf.keys(): | ||
auth_settings_v2 = conf['auth_settings_v2'][0] | ||
|
||
# default=true for require_https | ||
if 'require_https' not in auth_settings_v2.keys(): | ||
return CheckResult.PASSED | ||
|
||
require_https = auth_settings_v2.get('require_https')[0] | ||
if not require_https: | ||
return CheckResult.FAILED | ||
|
||
return CheckResult.PASSED | ||
|
||
|
||
check = FunctionAppsAccessibleOverHttps() |
177 changes: 177 additions & 0 deletions
177
tests/terraform/checks/resource/azure/example_FunctionAppAccessibleOverHttps/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,177 @@ | ||
|
||
## app | ||
|
||
resource "azurerm_function_app" "fail" { | ||
name = "test-azure-functions" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
app_service_plan_id = azurerm_app_service_plan.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
} | ||
resource "azurerm_function_app" "fail2" { | ||
name = "test-azure-functions" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
app_service_plan_id = azurerm_app_service_plan.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
https_only = false | ||
} | ||
resource "azurerm_function_app" "pass" { | ||
name = "test-azure-functions" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
app_service_plan_id = azurerm_app_service_plan.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
https_only = true | ||
} | ||
|
||
## app_slot | ||
|
||
resource "azurerm_function_app_slot" "fail" { | ||
name = "test-azure-functions_slot" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
app_service_plan_id = azurerm_app_service_plan.example.id | ||
function_app_name = azurerm_function_app.example.name | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
} | ||
resource "azurerm_function_app_slot" "fail2" { | ||
name = "test-azure-functions_slot" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
app_service_plan_id = azurerm_app_service_plan.example.id | ||
function_app_name = azurerm_function_app.example.name | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
https_only = false | ||
} | ||
resource "azurerm_function_app_slot" "pass" { | ||
name = "test-azure-functions_slot" | ||
location = azurerm_resource_group.example.location | ||
resource_group_name = azurerm_resource_group.example.name | ||
app_service_plan_id = azurerm_app_service_plan.example.id | ||
function_app_name = azurerm_function_app.example.name | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
https_only = true | ||
} | ||
|
||
#### linux/windows | ||
|
||
## app | ||
|
||
resource "azurerm_linux_function_app" "fail" { | ||
name = "example-linux-function-app" | ||
resource_group_name = azurerm_resource_group.example.name | ||
location = azurerm_resource_group.example.location | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
service_plan_id = azurerm_service_plan.example.id | ||
|
||
site_config {} | ||
} | ||
resource "azurerm_linux_function_app" "fail2" { | ||
name = "example-linux-function-app" | ||
resource_group_name = azurerm_resource_group.example.name | ||
location = azurerm_resource_group.example.location | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
service_plan_id = azurerm_service_plan.example.id | ||
|
||
site_config {} | ||
https_only = false | ||
} | ||
resource "azurerm_linux_function_app" "fail3" { | ||
name = "example-linux-function-app" | ||
resource_group_name = azurerm_resource_group.example.name | ||
location = azurerm_resource_group.example.location | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
service_plan_id = azurerm_service_plan.example.id | ||
|
||
site_config {} | ||
|
||
https_only = true | ||
auth_settings_v2 { | ||
require_https = false | ||
} | ||
} | ||
resource "azurerm_linux_function_app" "pass" { | ||
name = "example-linux-function-app" | ||
resource_group_name = azurerm_resource_group.example.name | ||
location = azurerm_resource_group.example.location | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
service_plan_id = azurerm_service_plan.example.id | ||
|
||
site_config {} | ||
https_only = true | ||
} | ||
resource "azurerm_linux_function_app" "pass2" { | ||
name = "example-linux-function-app" | ||
resource_group_name = azurerm_resource_group.example.name | ||
location = azurerm_resource_group.example.location | ||
storage_account_name = azurerm_storage_account.example.name | ||
storage_account_access_key = azurerm_storage_account.example.primary_access_key | ||
service_plan_id = azurerm_service_plan.example.id | ||
|
||
site_config {} | ||
|
||
https_only = true | ||
auth_settings_v2 { | ||
require_https = true | ||
} | ||
} | ||
|
||
## app slot | ||
|
||
resource "azurerm_linux_function_app_slot" "fail" { | ||
name = "example-linux-function-app-slot" | ||
function_app_id = azurerm_linux_function_app.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
|
||
site_config {} | ||
} | ||
resource "azurerm_linux_function_app_slot" "fail2" { | ||
name = "example-linux-function-app-slot" | ||
function_app_id = azurerm_linux_function_app.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
|
||
site_config {} | ||
https_only = false | ||
} | ||
resource "azurerm_linux_function_app_slot" "fail3" { | ||
name = "example-linux-function-app-slot" | ||
function_app_id = azurerm_linux_function_app.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
|
||
site_config {} | ||
auth_settings_v2 { | ||
require_https = false | ||
} | ||
https_only = true | ||
} | ||
resource "azurerm_linux_function_app_slot" "pass" { | ||
name = "example-linux-function-app-slot" | ||
function_app_id = azurerm_linux_function_app.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
|
||
site_config {} | ||
auth_settings_v2 {} | ||
https_only = true | ||
} | ||
resource "azurerm_linux_function_app_slot" "pass2" { | ||
name = "example-linux-function-app-slot" | ||
function_app_id = azurerm_linux_function_app.example.id | ||
storage_account_name = azurerm_storage_account.example.name | ||
|
||
site_config {} | ||
auth_settings_v2 { | ||
require_https = true | ||
} | ||
https_only = true | ||
} |
83 changes: 40 additions & 43 deletions
83
tests/terraform/checks/resource/azure/test_FunctionAppsAccessibleOverHttps.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
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