terraform.azure.security.azure-functionapps-enable-auth.azure-functionapps-enable-auth

profile photo of semgrepsemgrep
Author
unknown
Download Count*

Ensure that function apps enables Authentication

Run Locally

Run in CI

Defintion

rules:
  - id: azure-functionapps-enable-auth
    message: Ensure that function apps enables Authentication
    patterns:
      - pattern: resource
      - pattern-not-inside: |
          resource "azurerm_function_app" "..." {
          ...
          auth_settings {
            ...
            enabled = true
            ...
          }
          ...
          }
      - pattern-inside: |
          resource "azurerm_function_app" "..." {
          ...
          }
    metadata:
      owasp:
        - A05:2017 - Broken Access Control
        - A01:2021 - Broken Access Control
      cwe:
        - "CWE-284: Improper Access Control"
      category: security
      technology:
        - terraform
        - azure
      references:
        - https://owasp.org/Top10/A01_2021-Broken_Access_Control
      subcategory:
        - audit
      likelihood: LOW
      impact: LOW
      confidence: LOW
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
      vulnerability_class:
        - Improper Authorization
    languages:
      - hcl
    severity: WARNING

Examples

azure-functionapps-enable-auth.tf

# fail
# ruleid: azure-functionapps-enable-auth
resource "azurerm_function_app" "example" {
  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"
}

# fail
# ruleid: azure-functionapps-enable-auth
resource "azurerm_function_app" "example" {
  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"
  auth_settings {
    enabled = false
  }
}

# pass
resource "azurerm_function_app" "example" {
  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"
  auth_settings {
    enabled = true
  }
}