We have a web app that is deployed as an App Service in Azure. We would like to restrict access to it by having a white list of IP addresses that can be done in some Azure App Service setting and not in web.config
that we have inside the project.
Currently, this is how we do IP address restriction in our environments.
- Production: We have VNet Integration setup for the App Service. We attached an
NSG
to theVNet's
Subnet
and from theNSG
we can control inbound and outbound access. Staging: We have the following block of configuration in our
web.config
that contains the whitelisted IP addresses that are allowed to access the App Service in our staging server.<security> <ipSecurity allowUnlisted="false" denyAction="NotFound"> <add allowed="true" ipAddress="some ip address" subnetMask="255.255.255.254"></add> <add allowed="true" ipAddress="some ip address" subnetMask="255.255.255.254"></add> </ipSecurity> </security>
Development(local): We have to uncomment the
<security>
configuration block in our local development machines coz we don't really need it. And it causes an error, please see screenshot below.
This is some the contents of the HttpFailre_09-07-33.html
Module IpRestrictionModule
Notification BeginRequest
Handler aspNetCore
Error Code 0x80070021
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
We would like to completely remove this <security>
block from web.config because for another reason, we don't want the IP addresses to reach production.
And also, we are not allowed to do VNet Integration in our Staging server (management stuff, duh! cost-cutting whatever!).
So is there a way to restrict IP addresses in Azure App Service?