Bylaw

Gallery › App Service › Azure built-in policies

[Deprecated]: Configure App Services to disable public network access

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0-deprecated Deprecated

Disable public network access for your App Services so that it is not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://aka.ms/app-service-private-endpoint.

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

Azure Policy JSONPublicNetworkAccess_DINE.json · 88 lines
{
  "properties": {
    "displayName": "[Deprecated]: Configure App Services to disable public network access",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disable public network access for your App Services so that it is not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://aka.ms/app-service-private-endpoint.",
    "metadata": {
      "version": "1.0.0-deprecated",
      "category": "App Service",
      "deprecated": true
    },
    "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": {
        "field": "type",
        "equals": "Microsoft.Web/sites"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/config",
          "existenceCondition": {
            "field": "Microsoft.Web/sites/config/publicNetworkAccess",
            "equals": "Disabled"
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "webAppName": {
                  "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": {
                  "webAppName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "name": "[concat(parameters('webAppName'), '/web')]",
                    "type": "Microsoft.Web/sites/config",
                    "apiVersion": "2020-09-01",
                    "location": "[parameters('location')]",
                    "properties": {
                      "publicNetworkAccess": "Disabled"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/81dff7c0-4020-4b58-955d-c076a2136b56",
  "name": "81dff7c0-4020-4b58-955d-c076a2136b56"
}
Bylaw81dff7c0-4020-4b58-955d-c076a2136b56.bylaw.ps1 · 32 lines
# Converted from PublicNetworkAccess_DINE.json by ConvertTo-Bylaw.
Policy '81dff7c0-4020-4b58-955d-c076a2136b56' {

    Properties @{
        DisplayName   = '[Deprecated]: Configure App Services to disable public network access'
        Description   = 'Disable public network access for your App Services so that it is not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://aka.ms/app-service-private-endpoint.'
        Version       = '1.0.0-deprecated'
        Category      = 'App Service'
        Deprecated    = $true
        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'

    DeployIfNotExists 'Microsoft.Web/sites/config' -Role 'Website Contributor' -Effect (Param Effect) {
        Require 'publicNetworkAccess is Disabled' {
            Field publicNetworkAccess | Must -Be 'Disabled'
        }
        Deployment -TemplateFile './templates/81dff7c0-4020-4b58-955d-c076a2136b56.json' -Parameters ([ordered]@{
                webAppName = (Arm '[field(''name'')]')
                location   = (Arm '[field(''location'')]')
            })
    }
}

Its deployment templates are written beside it:

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