How to force traffic to an Azure web app to go through a WAF Gateway?

Ijaz M 206 Reputation points
2022-12-03T06:37:39.897+00:00

I have an App Service as the backend of a WAF App Gateway on Azure. Apparently, the Request metric for the App Service shows much much larger values than the Total Requests metric for the WAF Gateway. Does this indicate that there is a leakage of traffic?

Do I need to do any DNS stuff with the DNS name of the public IP associated with the WAF. Note that there is a custom domain for the backend App Service. Or do I need to add the front IP of the gateway to the allow list of any network rule of the App Service's network restriction?

Thanks in advance.

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
956 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,848 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yannic Graber 586 Reputation points MVP
    2022-12-03T11:40:28.243+00:00

    Hello @Ijaz M

    With the statements you make, it is not clear to me, how the App Service itself is configured exactly. Since there seems to be a significant difference in the metrics between WAF and App Service, I assume that there are multiple entry points.

    To achieve to get all the traffic through the WAF, I suggest making the App Service private and use a private endpoint / private link.

    1. Make your App Service private
    2. Configure Private Endpoint / private link
    3. Configure your WAF to point to the App Service Private Endpoint
    4. Make sure there are no other entry points into your private network, from where you can access the Private Endpoint of your App Service

    The following overview by Microsoft shows this configuration pretty good and is explained in this link on Microsoft learn.
    266807-private-endpoint-appgw.png

    If this answer is helpful, please accept it as the answer and upvote as a token of appreciation.
    Otherwise, please do not hesitate to add some more details.


  2. 2022-12-05T13:28:16.657+00:00

    To manage the Azure application gateway on-demand with PowerShell, you first need to install the Az PowerShell module on your computer. This happens by starting Windows PowerShell as an administrator and running the below command.

    Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

    After you’ve installed the Az module, you are ready to run the script below. It will first connect to your Azure subscription, prompting you for credentials. It will then get the application gateway object and check its status. If the application gateway is running and you’ve specified that you want it stopped, the script will stop the gateway. And vice versa, if the application gateway is stopped and you’ve specified that you want it up and running again, the script will start the gateway.

    param(
    [Parameter(Mandatory)]
    [String]$subscriptionId,
    [Parameter(Mandatory)]
    [String]$resourceGroupName,
    [Parameter(Mandatory)]
    [String]$appGatewayName,
    [Parameter(Mandatory)]
    [Boolean]$enabled
    )

    Connect-AzAccount -Subscription $subscriptionId
    $appGateway = Get-AzApplicationGateway -Name $appGatewayName -ResourceGroupName $resourceGroupName

    if ($enabled -eq $true -and $appGateway.OperationalState -eq "Stopped") {
    Write-Host "Starting the application gateway."
    Start-AzApplicationGateway -ApplicationGateway $appGateway
    }
    if ($enabled -eq $false -and $appGateway.OperationalState -eq "Running") {
    Write-Host "Stopping the application gateway."
    Stop-AzApplicationGateway -ApplicationGateway $appGateway
    }
    view rawset-application-gateway-state.ps1 hosted with ❤ by GitHub
    To execute the script, you need to provide the Azure subscription ID, the resource group name, the app application gateway name, and either $true (to start) or $false (to stop) to change the application gateway state. So, for example, to stop the application gateway, you’d run the following command in Windows PowerShell.

    . "<local script file directory path>.ps1" -subscriptionId "<your subscription ID>" -resourceGroupName "<your resource group name>" -appGatewayName "<your application gateway name>" -enabled $false