Bylaw

Gallery › Network › Azure built-in policies

Enable Rate Limit rule to protect against DDoS attacks on Azure Front Door WAF

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

The Azure Web Application Firewall (WAF) rate limit rule for Azure Front Door controls the number of requests allowed from a particular client IP address to the application during a rate limit duration.

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

Azure Policy JSONEnableRateLimitRuletoProtectAgainstDDoSAttacksonAFDWAFPolicy.json · 64 lines
{
  "properties": {
    "displayName": "Enable Rate Limit rule to protect against DDoS attacks on Azure Front Door WAF",
    "policyType": "BuiltIn",
    "version": "1.0.0",
    "mode": "Indexed",
    "description": "The Azure Web Application Firewall (WAF) rate limit rule for Azure Front Door controls the number of requests allowed from a particular client IP address to the application during a rate limit duration.",
    "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/frontdoorWebApplicationFirewallPolicies"
          },
          {
            "count": {
              "field": "Microsoft.Network/frontdoorWebApplicationFirewallPolicies/customRules.rules[*]",
              "where": {
                "allOf": [
                  {
                    "field": "Microsoft.Network/frontdoorWebApplicationFirewallPolicies/customRules.rules[*].rateLimitThreshold",
                    "exists": "false"
                  },
                  {
                    "field": "Microsoft.Network/frontdoorWebApplicationFirewallPolicies/customRules.rules[*].rateLimitDurationInMinutes",
                    "exists": "false"
                  }
                ]
              }
            },
            "greater": 0
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/e52e8487-4a97-48ac-b3e6-1c3cef45d298",
  "name": "e52e8487-4a97-48ac-b3e6-1c3cef45d298"
}
Bylawe52e8487-4a97-48ac-b3e6-1c3cef45d298.bylaw.ps1 · 33 lines
# Converted from EnableRateLimitRuletoProtectAgainstDDoSAttacksonAFDWAFPolicy.json by ConvertTo-Bylaw.
Policy 'e52e8487-4a97-48ac-b3e6-1c3cef45d298' {

    Properties @{
        DisplayName   = 'Enable Rate Limit rule to protect against DDoS attacks on Azure Front Door WAF'
        Description   = 'The Azure Web Application Firewall (WAF) rate limit rule for Azure Front Door controls the number of requests allowed from a particular client IP address to the application during a rate limit duration.'
        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/frontdoorWebApplicationFirewallPolicies' {

        Require 'customRules.rules, rateLimitThreshold and rateLimitDurationInMinutes are as required' {
            Each 'customRules.rules[*]' {
                AnyOf {
                    Field rateLimitThreshold | Must -Exist
                    Field rateLimitDurationInMinutes | Must -Exist
                }
            }
        }
    }

    Effect (Param Effect)
}

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