Bylaw

Gallery › App Service › Azure built-in policies

Configure App Service app slots to disable local authentication for FTP deployments

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.1.0

Disabling local authentication methods for FTP deployments improves security by ensuring that App Service slots 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 JSONSlots_FTP_DisableBasicAuth_DINE.json · 99 lines
{
  "properties": {
    "displayName": "Configure App Service app slots to disable local authentication for FTP deployments",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disabling local authentication methods for FTP deployments improves security by ensuring that App Service slots exclusively require Microsoft Entra identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.",
    "metadata": {
      "version": "1.1.0",
      "category": "App Service"
    },
    "version": "1.1.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/slots"
          },
          {
            "field": "kind",
            "notContains": "functionapp"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "name": "ftp",
          "type": "Microsoft.Web/sites/slots/basicPublishingCredentialsPolicies",
          "existenceCondition": {
            "field": "Microsoft.Web/sites/slots/basicPublishingCredentialsPolicies/allow",
            "equals": "false"
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "siteName": {
                  "value": "[field('fullName')]"
                },
                "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/slots/basicPublishingCredentialsPolicies",
                    "name": "[concat(parameters('siteName'), '/ftp')]",
                    "apiVersion": "2021-02-01",
                    "location": "[parameters('location')]",
                    "tags": {},
                    "properties": {
                      "allow": "false"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.1.0",
      "1.0.3"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/f493116f-3b7f-4ab3-bf80-0c2af35e46c2",
  "name": "f493116f-3b7f-4ab3-bf80-0c2af35e46c2"
}
Bylawf493116f-3b7f-4ab3-bf80-0c2af35e46c2.bylaw.ps1 · 36 lines
# Converted from Slots_FTP_DisableBasicAuth_DINE.json by ConvertTo-Bylaw.
Policy 'f493116f-3b7f-4ab3-bf80-0c2af35e46c2' {

    Properties @{
        DisplayName   = 'Configure App Service app slots to disable local authentication for FTP deployments'
        Description   = 'Disabling local authentication methods for FTP deployments improves security by ensuring that App Service slots exclusively require Microsoft Entra identities for authentication. Learn more at: https://aka.ms/app-service-disable-basic-auth.'
        Version       = '1.1.0'
        Category      = 'App Service'
        PolicyVersion = '1.1.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/slots' {

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

    DeployIfNotExists 'Microsoft.Web/sites/slots/basicPublishingCredentialsPolicies' -Role 'Website Contributor' -Name 'ftp' -Effect (Param Effect) {
        Require 'allow is false' {
            Field allow | Must -Be 'false'
        }
        Deployment -TemplateFile './templates/f493116f-3b7f-4ab3-bf80-0c2af35e46c2.json' -Parameters ([ordered]@{
                siteName = (Arm '[field(''fullName'')]')
                location = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

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