Bylaw

Gallery › App Service › Azure built-in policies

Function apps should enable configuration routing to Azure Virtual Network

Converted Policy Audit Deny Disabled Mode Indexed Version 1.3.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. Not for Flex/Consumption plans. 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 JSONFunctionApp_VnetConfigurationRouting_Audit.json · 117 lines
{
  "properties": {
    "displayName": "Function apps 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. Not for Flex/Consumption plans. Learn more: https://aka.ms/appservice-vnet-configuration-routing.",
    "metadata": {
      "version": "1.3.0",
      "category": "App Service"
    },
    "version": "1.3.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"
          },
          {
            "field": "kind",
            "contains": "functionapp"
          },
          {
            "field": "kind",
            "notContains": "workflowapp"
          },
          {
            "field": "kind",
            "notContains": "azurecontainerapps"
          },
          {
            "anyOf": [
              {
                "allOf": [
                  {
                    "value": "[requestContext().apiVersion]",
                    "less": "2024-11-01"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Web/sites/vnetImagePullEnabled",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/vnetContentShareEnabled",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/vnetBackupRestoreEnabled",
                        "notEquals": "true"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "value": "[requestContext().apiVersion]",
                    "greaterOrEquals": "2024-11-01"
                  },
                  {
                    "field": "Microsoft.Web/sites/outboundVnetRouting.allTraffic",
                    "notEquals": "true"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.Web/sites/outboundVnetRouting.imagePullTraffic",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/outboundVnetRouting.contentShareTraffic",
                        "notEquals": "true"
                      },
                      {
                        "field": "Microsoft.Web/sites/outboundVnetRouting.backupRestoreTraffic",
                        "notEquals": "true"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.3.0",
      "1.2.0",
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5e57f5ad-995a-485b-9f42-4748935ee5d9",
  "name": "5e57f5ad-995a-485b-9f42-4748935ee5d9"
}
Bylaw5e57f5ad-995a-485b-9f42-4748935ee5d9.bylaw.ps1 · 54 lines
# Converted from FunctionApp_VnetConfigurationRouting_Audit.json by ConvertTo-Bylaw.
Policy '5e57f5ad-995a-485b-9f42-4748935ee5d9' {

    Properties @{
        DisplayName   = 'Function apps 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. Not for Flex/Consumption plans. Learn more: https://aka.ms/appservice-vnet-configuration-routing.'
        Version       = '1.3.0'
        Category      = 'App Service'
        PolicyVersion = '1.3.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' {

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

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