While deploying my application to Azure Web App, I would like to use the Cloudflare Access to protect my web application. So that only I can use the web application.
But the problem is the Azure Web App always assigns a custom domain to the web app (ex
webapp-name.azurewebservices.net) so it could be scanned and accessed in public if anyone knows that domain. How we can prevent that?
1 It could be resolved if we can restrict access to the app from everywhere but Cloudflare Access.
There’re 4 steps we need to be done.
- Configure the Cloudflare Access to deny all.
- Add custom domain for Azure Web App.
- Enable the proxy mode for the DNS on cloudflare.
- Restrict all the traffic to the Azure Web App to be allowed from Cloudflare only.
1. Configure the Cloudflare Access to deny user
Go to Cloudflare Access and add an application with a policy to deny all users (except mine :D)
2. Add custom domain for Azure Web App
Ensure that the custom domain has been added and configured on Azure Web App…
3. Enable proxy mode for Cloudflare DNS
…and Cloudflare as well, but remember to enable proxy mode for it. So now all the traffic to Azure Web App will be proxied to Cloudflare.
4. Restrict all the traffic to the Azure Web App
Add the Cloudflare Outbound IP Ranges to the rules.
But the issue is Azure Portal does not allow to add more than one IP range so you will see this error when adding it.
So you need to run the powershell scripts to add those IP Ranges directly on the Azure Portal Cloud Shell. Click on the Cloud Shell icon on the top-right of the portal, change the command prompt to PowerShell
And run the following commands
1 2 3 Add-AzWebAppAccessRestrictionRule -ResourceGroupName "resource-group-name" -WebAppName "web-app-name" -Name "Cloudflare Part 1" -IpAddress "188.8.131.52/20,184.108.40.206/22,220.127.116.11/22,18.104.22.168/22,22.214.171.124/18,126.96.36.199/18,188.8.131.52/20,184.108.40.206/20" -Priority 100 -Action Allow Add-AzWebAppAccessRestrictionRule -ResourceGroupName "resource-group-name" -WebAppName "web-app-name" -Name "Cloudflare Part 2" -IpAddress "220.127.116.11/22,18.104.22.168/17,22.214.171.124/15,126.96.36.199/13,188.8.131.52/14,184.108.40.206/13,220.127.116.11/22" -Priority 100 -Action Allow
We need to slit them to 2 rules because of this error.
1 Add-AzWebAppAccessRestrictionRule: Cannot validate argument on parameter 'IpAddress'. Only 8 ip addresses are allowed per rule