Bylaw

Gallery › Network › Azure built-in policies

[Deprecated]: Web Application Firewall should be a set mode for Application Gateway and Azure Front Door Service

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0-deprecated Deprecated

Mandates detect or prevent mode to be active on all Web Application Firewall policies for Azure Front Door and Application Gateway. Web Application Firewall policies can have a consistent mode configuration across a resource group.

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

Azure Policy JSONModeWAF_Deny.json · 79 lines
{
  "properties": {
    "displayName": "[Deprecated]: Web Application Firewall should be a set mode for Application Gateway and Azure Front Door Service",
    "description": "Mandates detect or prevent mode to be active on all Web Application Firewall policies for Azure Front Door and Application Gateway. Web Application Firewall policies can have a consistent mode configuration across a resource group.",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.0.0-deprecated",
      "category": "Network",
      "deprecated": true
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Deny"
      },
      "modeRequirement": {
        "type": "String",
        "metadata": {
          "displayName": "Mode Requirement",
          "description": "Mode required for all WAF policies"
        },
        "allowedValues": [
          "Prevention",
          "Detection"
        ],
        "defaultValue": "Detection"
      }
    },
    "policyRule": {
      "if": {
        "anyOf": [
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Network/frontdoorwebapplicationfirewallpolicies"
              },
              {
                "field": "Microsoft.Network/frontdoorWebApplicationFirewallPolicies/policySettings.mode",
                "notEquals": "[parameters('modeRequirement')]"
              }
            ]
          },
          {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Network/applicationGatewayWebApplicationFirewallPolicies"
              },
              {
                "field": "Microsoft.Network/applicationGatewayWebApplicationFirewallPolicies/policySettings.mode",
                "notEquals": "[parameters('modeRequirement')]"
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/f6b68e5a-7207-4638-a1fb-47d90404209e",
  "name": "f6b68e5a-7207-4638-a1fb-47d90404209e"
}
Bylawf6b68e5a-7207-4638-a1fb-47d90404209e.bylaw.ps1 · 45 lines
# Converted from ModeWAF_Deny.json by ConvertTo-Bylaw.
Policy 'f6b68e5a-7207-4638-a1fb-47d90404209e' {

    Properties @{
        DisplayName   = '[Deprecated]: Web Application Firewall should be a set mode for Application Gateway and Azure Front Door Service'
        Description   = 'Mandates detect or prevent mode to be active on all Web Application Firewall policies for Azure Front Door and Application Gateway. Web Application Firewall policies can have a consistent mode configuration across a resource group.'
        Version       = '1.0.0-deprecated'
        Category      = 'Network'
        Deprecated    = $true
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter ModeRequirement @{
        AllowedValues = @('Prevention', 'Detection')
        Default       = 'Detection'
        DisplayName   = 'Mode Requirement'
        Description   = 'Mode required for all WAF policies'
    }

    Resource * {

        Require 'type and policySettings.mode are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Network/frontdoorwebapplicationfirewallpolicies' -IfPresent
                Field 'Microsoft.Network/frontdoorWebApplicationFirewallPolicies/policySettings.mode' | Must -Be (Param ModeRequirement)
            }
        }

        Require 'type and policySettings.mode are as required' {
            AnyOf {
                Field type | Must -Not -Be 'Microsoft.Network/applicationGatewayWebApplicationFirewallPolicies' -IfPresent
                Field 'Microsoft.Network/applicationGatewayWebApplicationFirewallPolicies/policySettings.mode' | Must -Be (Param ModeRequirement)
            }
        }
    }

    Effect (Param Effect)
}

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