You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
+
269
421
> [!NOTE]
270
422
> 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.
0 commit comments