Skip to content

Commit e62e6b0

Browse files
authored
Merge pull request #211119 from johndowns/waf-front-door-rate-limit-cli
Front Door WAF - Add Azure CLI instructions to rate limit configuration article
2 parents 0281e09 + c3ef6e8 commit e62e6b0

File tree

2 files changed

+156
-2
lines changed

2 files changed

+156
-2
lines changed

articles/web-application-firewall/afds/waf-front-door-rate-limit-configure.md

Lines changed: 154 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: vhorne
55
ms.service: web-application-firewall
66
ms.topic: article
77
services: web-application-firewall
8-
ms.date: 09/07/2022
8+
ms.date: 10/05/2022
99
ms.author: victorh
1010
ms.custom: devx-track-azurepowershell
1111
zone_pivot_groups: web-application-firewall-configuration
@@ -17,7 +17,7 @@ The Azure Web Application Firewall (WAF) rate limit rule for Azure Front Door co
1717

1818
This article shows how to configure a WAF rate limit rule on Azure Front Door Standard and Premium tiers.
1919

20-
::: zone pivot="portal,powershell"
20+
::: zone pivot="portal,powershell,cli"
2121

2222
## Scenario
2323

@@ -266,6 +266,158 @@ $frontDoorSecurityPolicy = New-AzFrontDoorCdnSecurityPolicy `
266266
-Parameter $securityPolicyParameters
267267
```
268268

269+
::: zone-end
270+
271+
::: zone pivot="cli"
272+
273+
## Prerequisites
274+
275+
Before you begin to set up a rate limit policy, set up your Azure CLI environment and create a Front Door profile.
276+
277+
### Set up your Azure CLI environment
278+
279+
The Azure CLI provides a set of commands that use the [Azure Resource Manager](../../azure-resource-manager/management/overview.md) model for managing your Azure resources.
280+
281+
You can install the [Azure CLI](/cli/azure/install-azure-cli) on your local machine and use it in any shell session. Here you sign in with your Azure credentials and install the Azure CLI extension for Front Door Standard/Premium.
282+
283+
#### Connect to Azure with an interactive dialog for sign-in
284+
285+
Sign in to Azure by running the following command:
286+
287+
```azurecli
288+
az login
289+
```
290+
291+
#### Install the Front Door extension for the Azure CLI
292+
293+
Install the `front-door` extension to work with the Front Door WAF from the Azure CLI:
294+
295+
```azurecli
296+
az extension add --name front-door
297+
```
298+
299+
You use the `az afd` commands to work with Front Door Standard/Premium resources, and you use the `az network front-door waf-policy` commands to work with WAF resources.
300+
301+
### Create a resource group
302+
303+
Use the [az group create](/cli/azure/group#az-group-create) command to create a new resource group for your Front Door profile and WAF policy. Update the resource group name and location for your own requirements:
304+
305+
```azurecli
306+
resourceGroupName='FrontDoorRateLimit'
307+
308+
az group create \
309+
--name $resourceGroupName \
310+
--location westus
311+
```
312+
313+
## Create a Front Door profile
314+
315+
Use the [az afd profile create](/cli/azure/afd/profile#az-afd-profile-create) command to create a new Front Door profile.
316+
317+
In this example, you create a Front Door standard profile named *MyFrontDoorProfile*:
318+
319+
```azurecli
320+
frontDoorProfileName='MyFrontDoorProfile'
321+
322+
az afd profile create \
323+
--profile-name $frontDoorProfileName \
324+
--resource-group $resourceGroupName \
325+
--sku Standard_AzureFrontDoor
326+
```
327+
328+
### Create a Front Door endpoint
329+
330+
Use the [az afd endpoint create](/cli/azure/afd/endpoint#az-afd-endpoint-create) command to add an endpoint to your Front Door profile.
331+
332+
Front Door endpoints must have globally unique names, so update the value of the `frontDoorEndpointName` variable to something unique.
333+
334+
```azurecli
335+
frontDoorEndpointName='<unique-front-door-endpoint-name>'
336+
337+
az afd endpoint create \
338+
--endpoint-name $frontDoorEndpointName \
339+
--profile-name $frontDoorProfileName \
340+
--resource-group $resourceGroupName \
341+
```
342+
343+
## Create a WAF policy
344+
345+
Use the [az network front-door waf-policy create](/cli/azure/network/front-door/waf-policy#az-network-front-door-waf-policy-create) command to create a WAF policy:
346+
347+
```azurecli
348+
wafPolicyName='MyWafPolicy'
349+
350+
az network front-door waf-policy create \
351+
--name $wafPolicyName \
352+
--resource-group $resourceGroupName \
353+
--sku Standard_AzureFrontDoor
354+
```
355+
356+
## Prepare to add a custom rate limit rule
357+
358+
Use the [az network front-door waf-policy rule create](/cli/azure/network/front-door/waf-policy/rule#az-network-front-door-waf-policy-rule-create) command to create a custom rate limit rule. The following example sets the limit to 1000 requests per minute.
359+
360+
Rate limit rules must contain a match condition, which you create in the next step. So, in this command, you include the `--defer` argument, which tells the Azure CLI not to submit the rule to Azure just yet.
361+
362+
```azurecli
363+
az network front-door waf-policy rule create \
364+
--name rateLimitRule \
365+
--policy-name $wafPolicyName \
366+
--resource-group $resourceGroupName \
367+
--rule-type RateLimitRule \
368+
--rate-limit-duration 1 \
369+
--rate-limit-threshold 1000 \
370+
--action Block \
371+
--priority 1 \
372+
--defer
373+
```
374+
375+
When any client IP address sends more than 1000 requests within one minute, the WAF blocks subsequent requests until the next minute starts.
376+
377+
## Add a match condition
378+
379+
Use the [az network front-door waf-policy rule match-condition add](/cli/azure/network/front-door/waf-policy/rule/match-condition#az-network-front-door-waf-policy-rule-match-condition-add) command to add a match condition to your custom rule. The match condition identifies requests that should have the rate limit applied.
380+
381+
The following example matches requests where the *RequestUri* variable contains the string */promo*:
382+
383+
```azurecli
384+
az network front-door waf-policy rule match-condition add \
385+
--match-variable RequestUri \
386+
--operator Contains \
387+
--values '/promo' \
388+
--name rateLimitRule \
389+
--policy-name $wafPolicyName \
390+
--resource-group $resourceGroupName
391+
```
392+
393+
When you submit this command, the Azure CLI creates the rate limit rule and match condition together.
394+
395+
## Configure a security policy to associate your Front Door profile with your WAF policy
396+
397+
Use the [az afd security-policy create](/cli/azure/afd/security-policy#az-afd-security-policy-create) command to create a security policy for your Front Door profile. A security policy associates your WAF policy with domains that you want to be protected by the WAF rule.
398+
399+
In this example, you associate the endpoint's default hostname with your WAF policy:
400+
401+
```azurecli
402+
securityPolicyName='MySecurityPolicy'
403+
404+
wafPolicyResourceId=$(az network front-door waf-policy show --name $wafPolicyName --resource-group $resourceGroupName --query id --output tsv)
405+
frontDoorEndpointResourceId=$(az afd endpoint show --endpoint-name $frontDoorEndpointName --profile-name $frontDoorProfileName --resource-group $resourceGroupName --query id --output tsv)
406+
407+
az afd security-policy create \
408+
--security-policy-name $securityPolicyName \
409+
--profile-name $frontDoorProfileName \
410+
--resource-group $resourceGroupName \
411+
--domains $frontDoorEndpointResourceId \
412+
--waf-policy $wafPolicyResourceId
413+
```
414+
415+
The preceding code looks up the Azure resource identifiers for the WAF policy and Front Door endpoint so that it can associate them with your security policy.
416+
417+
::: zone-end
418+
419+
::: zone pivot="powershell,cli"
420+
269421
> [!NOTE]
270422
> Whenever you make changes to your WAF policy, you don't need to recreate the Front Door security policy. WAF policy updates are automatically applied to the Front Door domains.
271423

articles/zone-pivot-groups.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,5 +1898,7 @@ groups:
18981898
title: Azure portal
18991899
- id: powershell
19001900
title: PowerShell
1901+
- id: cli
1902+
title: Azure CLI
19011903
- id: bicep
19021904
title: Bicep

0 commit comments

Comments
 (0)