Bylaw

Gallery › App Service › Azure built-in policies

App Service app slots should disable public network access

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.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_Slot_PublicNetworkAccess_Audit.json · 67 lines
{
  "properties": {
    "displayName": "App Service app slots 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.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": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites/slots"
          },
          {
            "field": "Microsoft.Web/sites/slots/hostingEnvironmentProfile.id",
            "exists": "false"
          },
          {
            "field": "kind",
            "notContains": "functionapp"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Web/sites/slots/publicNetworkAccess",
                "exists": "false"
              },
              {
                "field": "Microsoft.Web/sites/slots/publicNetworkAccess",
                "notEquals": "Disabled"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/701a595d-38fb-4a66-ae6d-fb3735217622",
  "name": "701a595d-38fb-4a66-ae6d-fb3735217622"
}
Bylaw701a595d-38fb-4a66-ae6d-fb3735217622.bylaw.ps1 · 37 lines
# Converted from WebApp_Slot_PublicNetworkAccess_Audit.json by ConvertTo-Bylaw.
Policy '701a595d-38fb-4a66-ae6d-fb3735217622' {

    Properties @{
        DisplayName   = 'App Service app slots 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.1.0'
        Category      = 'App Service'
        PolicyVersion = '1.1.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/slots' {

        When {
            Field hostingEnvironmentProfile.id | Must -Not -Exist
            Field kind | Must -Not -ContainText 'functionapp'
        }

        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_Slot_PublicNetworkAccess_Audit.json in Azure/azure-policy, under the MIT licence.