Bylaw

Gallery › App Service › Azure built-in policies

App Service apps should disable public network access

Converted Policy Audit Deny Disabled Mode Indexed Version 1.2.0

Disabling public network access improves security by ensuring that the App Service is not exposed on the public internet. Creating private endpoints can limit exposure of an App Service. 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 JSONWebApp_PublicNetworkAccess_Audit.json · 63 lines
{
  "properties": {
    "displayName": "App Service apps should disable public network access",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disabling public network access improves security by ensuring that the App Service is not exposed on the public internet. Creating private endpoints can limit exposure of an App Service. Learn more at: https://aka.ms/app-service-private-endpoint.",
    "metadata": {
      "version": "1.2.0",
      "category": "App Service"
    },
    "version": "1.2.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "Microsoft.Web/sites/hostingEnvironmentProfile.id",
            "exists": "false"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Web/sites/publicNetworkAccess",
                "exists": "false"
              },
              {
                "field": "Microsoft.Web/sites/publicNetworkAccess",
                "notEquals": "Disabled"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.2.0",
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/1b5ef780-c53c-4a64-87f3-bb9c8c8094ba",
  "name": "1b5ef780-c53c-4a64-87f3-bb9c8c8094ba"
}
Bylaw1b5ef780-c53c-4a64-87f3-bb9c8c8094ba.bylaw.ps1 · 36 lines
# Converted from WebApp_PublicNetworkAccess_Audit.json by ConvertTo-Bylaw.
Policy '1b5ef780-c53c-4a64-87f3-bb9c8c8094ba' {

    Properties @{
        DisplayName   = 'App Service apps should disable public network access'
        Description   = 'Disabling public network access improves security by ensuring that the App Service is not exposed on the public internet. Creating private endpoints can limit exposure of an App Service. Learn more at: https://aka.ms/app-service-private-endpoint.'
        Version       = '1.2.0'
        Category      = 'App Service'
        PolicyVersion = '1.2.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Web/sites' {

        When {
            Field hostingEnvironmentProfile.id | Must -Not -Exist
        }

        Require 'publicNetworkAccess exists' {
            Field publicNetworkAccess | Must -Exist
        }

        Require 'publicNetworkAccess is Disabled' {
            Field publicNetworkAccess | Must -Be 'Disabled'
        }
    }

    Effect (Param Effect)
}

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