Bylaw

Gallery › Network › Azure built-in policies

Migrate WAF from WAF Config to WAF Policy on Application Gateway

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

If you have WAF Config instead of WAF Policy, then you may want to move to the new WAF Policy. Going forward, the firewall policy will support WAF policy settings, managed rulesets, exclusions, and disabled rule-groups.

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

Azure Policy JSONMigratefromWAFConfigtoWAFPolicyonAppGw.json · 58 lines
{
  "properties": {
    "displayName": "Migrate WAF from WAF Config to WAF Policy on Application Gateway",
    "policyType": "BuiltIn",
    "version": "1.0.0",
    "mode": "Indexed",
    "description": "If you have WAF Config instead of WAF Policy, then you may want to move to the new WAF Policy. Going forward, the firewall policy will support WAF policy settings, managed rulesets, exclusions, and disabled rule-groups.",
    "metadata": {
      "version": "1.0.0",
      "category": "Network"
    },
    "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.Network/applicationGateways"
          },
          {
            "field": "Microsoft.Network/applicationGateways/sku.tier",
            "equals": "WAF_v2"
          },
          {
            "field": "Microsoft.Network/applicationGateways/webApplicationFirewallConfiguration",
            "exists": "true"
          },
          {
            "field": "Microsoft.Network/applicationGateways/firewallPolicy",
            "exists": "false"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/882e19a6-996f-400e-a30f-c090887254f4",
  "name": "882e19a6-996f-400e-a30f-c090887254f4"
}
Bylaw882e19a6-996f-400e-a30f-c090887254f4.bylaw.ps1 · 33 lines
# Converted from MigratefromWAFConfigtoWAFPolicyonAppGw.json by ConvertTo-Bylaw.
Policy '882e19a6-996f-400e-a30f-c090887254f4' {

    Properties @{
        DisplayName   = 'Migrate WAF from WAF Config to WAF Policy on Application Gateway'
        Description   = 'If you have WAF Config instead of WAF Policy, then you may want to move to the new WAF Policy. Going forward, the firewall policy will support WAF policy settings, managed rulesets, exclusions, and disabled rule-groups.'
        Version       = '1.0.0'
        Category      = 'Network'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Network/applicationGateways' {

        When {
            Field sku.tier | Must -Be 'WAF_v2'
            Field webApplicationFirewallConfiguration | Must -Exist
        }

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

    Effect (Param Effect)
}

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