Bylaw

Gallery › Network › Azure built-in policies

App Service apps should use a virtual network service endpoint

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 2.0.1

Use virtual network service endpoints to restrict access to your app from selected subnets from an Azure virtual network. To learn more about App Service service endpoints, visit https://aka.ms/appservice-vnet-service-endpoint.

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

Azure Policy JSONVirtualNetworkServiceEndpoint_AppService_AINE.json · 56 lines
{
  "properties": {
    "displayName": "App Service apps should use a virtual network service endpoint",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Use virtual network service endpoints to restrict access to your app from selected subnets from an Azure virtual network. To learn more about App Service service endpoints, visit https://aka.ms/appservice-vnet-service-endpoint.",
    "metadata": {
      "version": "2.0.1",
      "category": "Network"
    },
    "version": "2.0.1",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites"
          },
          {
            "field": "kind",
            "notContains": "functionapp"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Web/sites/virtualNetworkConnections",
          "existenceCondition": {
            "field": "Microsoft.Web/sites/virtualnetworkconnections/vnetResourceId",
            "exists": "true"
          }
        }
      }
    },
    "versions": [
      "2.0.1"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/2d21331d-a4c2-4def-a9ad-ee4e1e023beb",
  "name": "2d21331d-a4c2-4def-a9ad-ee4e1e023beb"
}
Bylaw2d21331d-a4c2-4def-a9ad-ee4e1e023beb.bylaw.ps1 · 33 lines
# Converted from VirtualNetworkServiceEndpoint_AppService_AINE.json by ConvertTo-Bylaw.
Policy '2d21331d-a4c2-4def-a9ad-ee4e1e023beb' {

    Properties @{
        DisplayName   = 'App Service apps should use a virtual network service endpoint'
        Description   = 'Use virtual network service endpoints to restrict access to your app from selected subnets from an Azure virtual network. To learn more about App Service service endpoints, visit https://aka.ms/appservice-vnet-service-endpoint.'
        Version       = '2.0.1'
        Category      = 'Network'
        PolicyVersion = '2.0.1'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Web/sites' {

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

    AuditIfNotExists 'Microsoft.Web/sites/virtualNetworkConnections' -Effect (Param Effect) {
        Require 'vnetResourceId exists' {
            Field vnetResourceId | Must -Exist
        }
    }
}

Source: built-in-policies/policyDefinitions/Network/VirtualNetworkServiceEndpoint_AppService_AINE.json in Azure/azure-policy, under the MIT licence.