How to define IP whitelist in Azure Application Gateway (WAF) or Azure Firewall

Mohsen Akhavan 831 Reputation points
2023-02-10T12:49:11.0033333+00:00

Based on this document, I used Azure Application Gateway (WAF) before Azure Firewall. Also, I have three backend pools (Web Apps). Now I want to limit access to some web apps with IP through Azure Application Gateway or Azure Firewall.
First Azure Application Gateway received a client request and there aren't any configuration to add (Allow/Deny) client IP. After that this request sent to Azure Firewall.

Now, I want to know are there any solution to limit access (IP) on Applization Gateway or Firewall?

User's image

Azure Firewall
Azure Firewall
An Azure network security service that is used to protect Azure Virtual Network resources.
779 questions
Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
1,213 questions
Azure Web Application Firewall
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
{count} votes

Accepted answer
  1. GitaraniSharma-MSFT 50,021 Reputation points Microsoft Employee Moderator
    2023-02-10T13:13:41.2666667+00:00

    Hello @Mohsen Akhavan ,

    I understand that you would like to know how to block IP addresses (Client IP) in Azure Application gateway (WAF).

    You can configure IP restriction on Azure Application gateway to allow access to a few sources IPs by using NSG on the Application Gateway subnet.

    Refer: https://learn.microsoft.com/en-us/azure/application-gateway/configuration-infrastructure#allow-access-to-a-few-source-ips

    In case you are using Application Gateway WAF V2, you can use WAF V2 Custom rules to whitelist/block IP addresses.

    Please refer: https://learn.microsoft.com/en-us/azure/web-application-firewall/ag/custom-waf-rules-overview

    The Azure Application Gateway Web Application Firewall (WAF) v2 can be associated to a WAF policy which contain all the WAF settings and configurations. This includes exclusions, custom rules, managed rules, and so on. Custom rules allow you to create your own rules that are evaluated for each request that passes through the WAF.

    Allowing and blocking traffic is simple with custom rules. For example, you can allow/block all traffic coming from a range of IP addresses.

    To allow something, ensure that the -Action parameter is set to Allow. To block something, ensure that the -Action parameter is set to Block.

    You can create a Custom rule on Azure Application Gateway WAF v2 to block all requests from an IP address/range.

    You can use the "RemoteAddr" variable which is the IPv4 Address/Range of the remote computer connection with operator IPMatch to create such a rule and block all requests from a particular IP address and range.

    Example reference: https://learn.microsoft.com/en-us/azure/web-application-firewall/ag/create-custom-waf-rules#example-3

    To create custom rules, you first need to create a Web Application Firewall policy for Application Gateway.

    Refer: https://learn.microsoft.com/en-us/azure/web-application-firewall/ag/create-waf-policy-ag

    Once the WAF policy is created, you can create a custom rule as below:

    Associate the WAF policy to any of the below combination:

    • Your application gateway - When you associate a WAF policy globally, every site behind your Application Gateway WAF is protected with the same managed rules, custom rules, exclusions, and any other configured settings.
    • Any specific listener - With per-site WAF policies, you can protect multiple sites with differing security needs behind a single WAF by using per-site policies.
    • Any path-based rules - If there are certain pages within a single site that require different policies, you can make changes to the WAF policy that only affect a given URI.

    Refer: https://learn.microsoft.com/en-us/azure/web-application-firewall/ag/policy-overview

    Kindly let us know if the above helps or you need further assistance on this issue.


    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.