Bylaw

Gallery › App Service › Azure built-in policies

Configure Function apps to disable local authentication for SCM sites

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Disabling local authentication methods for SCM sites improves security by ensuring that function apps exclusively require Microsoft Entra identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONFunctionApp_SCM_DisableBasicAuth_DINE.json · 106 lines
{
  "properties": {
    "displayName": "Configure Function apps to disable local authentication for SCM sites",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disabling local authentication methods for SCM sites improves security by ensuring that function apps exclusively require Microsoft Entra identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.",
    "metadata": {
      "version": "1.0.0",
      "category": "App Service"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "contains": "functionapp"
          },
          {
            "field": "kind",
            "notContains": "workflowapp"
          },
          {
            "field": "kind",
            "notContains": "azurecontainerapps"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "name": "scm",
          "type": "Microsoft.Web/sites/basicPublishingCredentialsPolicies",
          "existenceCondition": {
            "field": "Microsoft.Web/sites/basicPublishingCredentialsPolicies/allow",
            "equals": "false"
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "siteName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "siteName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "variables": {},
                "resources": [
                  {
                    "type": "Microsoft.Web/sites/basicPublishingCredentialsPolicies",
                    "name": "[concat(parameters('siteName'), '/scm')]",
                    "apiVersion": "2025-01-01",
                    "location": "[parameters('location')]",
                    "tags": {},
                    "properties": {
                      "allow": "false"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/93059548-9cbe-4cdf-a2d1-63cc8db22550",
  "name": "93059548-9cbe-4cdf-a2d1-63cc8db22550"
}
Bylaw93059548-9cbe-4cdf-a2d1-63cc8db22550.bylaw.ps1 · 41 lines
# Converted from FunctionApp_SCM_DisableBasicAuth_DINE.json by ConvertTo-Bylaw.
Policy '93059548-9cbe-4cdf-a2d1-63cc8db22550' {

    Properties @{
        DisplayName   = 'Configure Function apps to disable local authentication for SCM sites'
        Description   = 'Disabling local authentication methods for SCM sites improves security by ensuring that function apps exclusively require Microsoft Entra identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.'
        Version       = '1.0.0'
        Category      = 'App Service'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.Web/sites' {

        When {
            Field kind | Must -ContainText 'functionapp'
            Field kind | Must -Not -ContainText 'workflowapp'
        }

        Require 'kind contains azurecontainerapps' {
            Field kind | Must -ContainText 'azurecontainerapps'
        }
    }

    DeployIfNotExists 'Microsoft.Web/sites/basicPublishingCredentialsPolicies' -Role 'Website Contributor' -Name 'scm' -Effect (Param Effect) {
        Require 'allow is false' {
            Field allow | Must -Be 'false'
        }
        Deployment -TemplateFile './templates/93059548-9cbe-4cdf-a2d1-63cc8db22550.json' -Parameters ([ordered]@{
                siteName = (Arm '[field(''name'')]')
                location = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: built-in-policies/policyDefinitions/App Service/FunctionApp_SCM_DisableBasicAuth_DINE.json in Azure/azure-policy, under the MIT licence.