Bylaw

Gallery › App Service › Azure built-in policies

App Service app slots should enable configuration routing to Azure Virtual Network

Converted Policy Audit Deny Disabled Mode Indexed Version 1.2.0

By default, configuration traffic (image pull, content share, backup/restore) is not routed through regional VNET integration. For API < 2024-11-01, set 'vnetImagePullEnabled', 'vnetContentShareEnabled', 'vnetBackupRestoreEnabled' to true. For API >= 2024-11-01, set the corresponding 'outboundVnetRouting' properties or 'outboundVnetRouting.allTraffic' to true. Learn more: https://aka.ms/appservice-vnet-configuration-routing.

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

Azure Policy JSONWebApp_Slot_VnetConfigurationRouting_Audit.json · 108 lines
{
  "properties": {
    "displayName": "App Service app slots should enable configuration routing to Azure Virtual Network",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "By default, configuration traffic (image pull, content share, backup/restore) is not routed through regional VNET integration. For API < 2024-11-01, set 'vnetImagePullEnabled', 'vnetContentShareEnabled', 'vnetBackupRestoreEnabled' to true. For API >= 2024-11-01, set the corresponding 'outboundVnetRouting' properties or 'outboundVnetRouting.allTraffic' to true. Learn more: https://aka.ms/appservice-vnet-configuration-routing.",
    "metadata": {
      "version": "1.2.0",
      "category": "App Service"
    },
    "version": "1.2.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Web/sites/slots"
          },
          {
            "field": "kind",
            "notContains": "functionapp"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "value": "[requestContext().apiVersion]",
                    "less": "2024-11-01"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Web/sites/slots/vnetImagePullEnabled",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/slots/vnetContentShareEnabled",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/slots/vnetBackupRestoreEnabled",
                        "notEquals": "true"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "value": "[requestContext().apiVersion]",
                    "greaterOrEquals": "2024-11-01"
                  },
                  {
                    "field": "Microsoft.Web/sites/slots/outboundVnetRouting.allTraffic",
                    "notEquals": "true"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Web/sites/slots/outboundVnetRouting.imagePullTraffic",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/slots/outboundVnetRouting.contentShareTraffic",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/slots/outboundVnetRouting.backupRestoreTraffic",
                        "notEquals": "true"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.2.0",
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5747353b-1ca9-42c1-a4dd-b874b894f3d4",
  "name": "5747353b-1ca9-42c1-a4dd-b874b894f3d4"
}
Bylaw5747353b-1ca9-42c1-a4dd-b874b894f3d4.bylaw.ps1 · 52 lines
# Converted from WebApp_Slot_VnetConfigurationRouting_Audit.json by ConvertTo-Bylaw.
Policy '5747353b-1ca9-42c1-a4dd-b874b894f3d4' {

    Properties @{
        DisplayName   = 'App Service app slots should enable configuration routing to Azure Virtual Network'
        Description   = 'By default, configuration traffic (image pull, content share, backup/restore) is not routed through regional VNET integration. For API < 2024-11-01, set ''vnetImagePullEnabled'', ''vnetContentShareEnabled'', ''vnetBackupRestoreEnabled'' to true. For API >= 2024-11-01, set the corresponding ''outboundVnetRouting'' properties or ''outboundVnetRouting.allTraffic'' to true. Learn more: https://aka.ms/appservice-vnet-configuration-routing.'
        Version       = '1.2.0'
        Category      = 'App Service'
        PolicyVersion = '1.2.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Web/sites/slots' {

        When {
            Field kind | Must -Not -ContainText 'functionapp'
        }

        Require 'vnetImagePullEnabled, vnetContentShareEnabled and vnetBackupRestoreEnabled are as required' {
            AnyOf {
                Arm '[requestContext().apiVersion]' | Must -BeGreaterOrEqual '2024-11-01'
                AllOf {
                    Field vnetImagePullEnabled | Must -Be 'true'
                    Field vnetContentShareEnabled | Must -Be 'true'
                    Field vnetBackupRestoreEnabled | Must -Be 'true'
                }
            }
        }

        Require 'outboundVnetRouting.allTraffic, outboundVnetRouting.imagePullTraffic, outboundVnetRouting.contentShareTraffic and 1 more are as required' {
            AnyOf {
                Arm '[requestContext().apiVersion]' | Must -BeLessThan '2024-11-01'
                Field outboundVnetRouting.allTraffic | Must -Be 'true'
                AllOf {
                    Field outboundVnetRouting.imagePullTraffic | Must -Be 'true'
                    Field outboundVnetRouting.contentShareTraffic | Must -Be 'true'
                    Field outboundVnetRouting.backupRestoreTraffic | Must -Be 'true'
                }
            }
        }
    }

    Effect (Param Effect)
}

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