Set up a geo-filtering WAF policy for Azure Front Door
Article
This tutorial shows how to use Azure PowerShell to create a sample geo-filtering policy and associate the policy with your existing Azure Front Door front-end host. This sample geo-filtering policy blocks requests from all other countries or regions except the United States.
If you don't have an Azure subscription, create a free account now.
Prerequisites
Before you begin to set up a geo-filter policy, set up your PowerShell environment and create an Azure Front Door profile.
Set up your PowerShell environment
Azure PowerShell provides a set of cmdlets that use the Azure Resource Manager model for managing your Azure resources.
You can install Azure PowerShell on your local machine and use it in any PowerShell session. Follow the instructions on the page to sign in with your Azure credentials. Then install the Az PowerShell module.
Connect to Azure with an interactive dialog for sign-in
Install-Module -Name Az
Connect-AzAccount
Make sure you have the current version of PowerShellGet installed. Run the following command and reopen PowerShell.
Create a sample match condition that selects requests not coming from "US" by using New-AzFrontDoorWafMatchConditionObject on parameters when you create a match condition.
Add a geo-filtering match condition to a rule with an action and a priority
Create a CustomRule object nonUSBlockRule based on the match condition, an action, and a priority by using New-AzFrontDoorWafCustomRuleObject. A custom rule can have multiple match conditions. In this example, Action is set to Block. Priority is set to 1, which is the highest priority.
Find the name of the resource group that contains the Azure Front Door profile by using Get-AzResourceGroup. Next, create a geoPolicy object that contains nonUSBlockRule by using New-AzFrontDoorWafPolicy in the specified resource group that contains the Azure Front Door profile. You must provide a unique name for the geo policy.
The following example uses the resource group name myResourceGroupFD1 with the assumption that you've created the Azure Front Door profile by using instructions provided in Quickstart: Create an Azure Front Door. In the following example, replace the policy name geoPolicyAllowUSOnly with a unique policy name.
You only need to set the WebApplicationFirewallPolicyLink property once to link a WAF policy to an Azure Front Door front-end host. Subsequent policy updates are automatically applied to the front-end host.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.