VNet Integration For Azure Web App and Azure SQL Server
Asked Answered
K

4

3

I have an Azure Web App and an Azure SQL Server, both in the same subscription. Both of them are connected to the same VNet Subnet as shown in the below snapshots. The SQL Server is configured not to Allow Azure Resources and Services to access the server, as it should only permit access from either the connected subnet or a set of IP rules.

Unfortunately, the SQL Server is actively refusing any connection from the web app stating that the web app IP is not allowed to access the server.

The interesting thing is that I have the exact same configuration working on another subscription.

What could I be missing?

Snapshots:

1- Here you can see the web application connected to the "webapps" subnet

enter image description here

2- And here you can see the SQL Server connected to the same subnet

enter image description here

3- And that's the error I get

enter image description here

Keele answered 9/6, 2020 at 6:34 Comment(2)
Is the service endpoint for SQL Database enabled on the subnet?Thrasher
@Thrasher Yes, and also Delegated to Microsoft.Web/serverFarmsKeele
W
1

TLDR

The configuration is correct, but an app service restart may be required.

VNET Integration

The configuration of using a virtual network to connect a web app to a SQL database is correct: if the web app is connected to the same subnet/vnet which is allowed in the database's ACLs, and the Microsoft.Sql service endpoint is enabled on the subnet, the web app is able to communicate to the database. This is the whole reason for service endpoints: you do not need to configure with IP allowances on the database.

As to why the configuration still resulted in an error, it could be the order in which the resources were configured. We were experiencing the exact same setup and issue (which is what let me to this question)!

We connected our web app to the subnet/vnet but had not enabled the service endpoint on the subnet. We then added/allowed the subnet/vnet as an ACL in the database, during which we were prompted to enable the Microsoft.Sql service endpoint (we did). However, even after waiting ~20 minutes, we were still seeing the same connection issue.

However, once we restarted the app service, the issue went away and the web app could connect to the SQL database.

I suspect the issue is due to enabling the subnet's service endpoint after the app service was connected to the subnet. The app service must need a restart to refresh the app service's vnet config/routing.

Configuration NOT needed

Contrary to other answers, you do not need to configure firewall IP allowances nor enable access to Azure services and resources. In fact, there are downsides to both approaches:

  • Enabling access to Azure services and resources allows any Azure-based resource to connect to your database, which includes resources not owned by you. From doc:

    This option configures the firewall to allow all connections from Azure, including connections from the subscriptions of other customers.

  • Unless you're using an App Service Environment (which is significantly more expensive than normal App Service plans), your web app's outbound IP addresses are neither static nor specific to your application. From doc:

    Azure App Service is a multi-tenant service, except for App Service Environments. Apps that are not in an App Service environment (not in the Isolated tier) share network infrastructure with other apps. As a result, the inbound and outbound IP addresses of an app can be different, and can even change in certain situations.

The second point is further elaborated upon in this Github issue:

IPs are indeed shared with other App Service plans (including other customer's plans) that are deployed into the same shared webspace. The network resources are shared among the plans in a workspace even if the computing instances are dedicated (e.g. in Standard tier). This is inherent to the App Service multi-tenant model. The only way to have a dedicated webspace (i.e. outbound IPs) is to deploy an App Service plan into an App Service Environment (ASE) (i.e. Isolated tier). ASE is the only thing that offers true single-tenency in App Service.

So neither of the above options will truly harden your SQL database if you want to isolate communication from only your web app. If you have resources in the same subnet, using vnet integration is the correct way to solve the problem.

If resources cannot be in the same subnet, the solution is to use Private Endpoints.

Whidah answered 5/7, 2021 at 21:9 Comment(0)
D
1

Virtual networking in Azure is quite different from how it would work on premises.

I had similar problems in production environment and digging deep, the working solution (meeting security standards and create a secure connection to the database) was to create a private endpoint for SQL access in the virtual network. Then all the calls to the SQL were performed internally (it did not go on the internet), and the databases were denying all public calls.

In your case now, you deactivated the Allow Azure apps to access so when your app is trying to access the SQL the server checks the ip to find out if it is white listed or not. So fast solutions would be one of the following:

  1. Enable Azure Web apps to access SQL
  2. Find all outbound IPs of your web app and register them in you SQL firewall/ security settings.

If you talk about a proper production environment with security regulations I would suggest you go down the more tedious path of private endpoints.

Dwarf answered 9/6, 2020 at 10:42 Comment(1)
Actually, the Azure SQL Firewall allows connection from subnets it's connected to if the application making the call is connected thorough the same subnet. without the need for a private end point and without whitelisting the IPs of the data center. Actually, yesterday, I was able to make it work by deleting the vnet and creating it again with a different IP range. It doesn't make sense, and U still don't understand what was the problem with the previous IP range. But it's working at least now... fingers crossed in my deployment to production :)Keele
W
1

TLDR

The configuration is correct, but an app service restart may be required.

VNET Integration

The configuration of using a virtual network to connect a web app to a SQL database is correct: if the web app is connected to the same subnet/vnet which is allowed in the database's ACLs, and the Microsoft.Sql service endpoint is enabled on the subnet, the web app is able to communicate to the database. This is the whole reason for service endpoints: you do not need to configure with IP allowances on the database.

As to why the configuration still resulted in an error, it could be the order in which the resources were configured. We were experiencing the exact same setup and issue (which is what let me to this question)!

We connected our web app to the subnet/vnet but had not enabled the service endpoint on the subnet. We then added/allowed the subnet/vnet as an ACL in the database, during which we were prompted to enable the Microsoft.Sql service endpoint (we did). However, even after waiting ~20 minutes, we were still seeing the same connection issue.

However, once we restarted the app service, the issue went away and the web app could connect to the SQL database.

I suspect the issue is due to enabling the subnet's service endpoint after the app service was connected to the subnet. The app service must need a restart to refresh the app service's vnet config/routing.

Configuration NOT needed

Contrary to other answers, you do not need to configure firewall IP allowances nor enable access to Azure services and resources. In fact, there are downsides to both approaches:

  • Enabling access to Azure services and resources allows any Azure-based resource to connect to your database, which includes resources not owned by you. From doc:

    This option configures the firewall to allow all connections from Azure, including connections from the subscriptions of other customers.

  • Unless you're using an App Service Environment (which is significantly more expensive than normal App Service plans), your web app's outbound IP addresses are neither static nor specific to your application. From doc:

    Azure App Service is a multi-tenant service, except for App Service Environments. Apps that are not in an App Service environment (not in the Isolated tier) share network infrastructure with other apps. As a result, the inbound and outbound IP addresses of an app can be different, and can even change in certain situations.

The second point is further elaborated upon in this Github issue:

IPs are indeed shared with other App Service plans (including other customer's plans) that are deployed into the same shared webspace. The network resources are shared among the plans in a workspace even if the computing instances are dedicated (e.g. in Standard tier). This is inherent to the App Service multi-tenant model. The only way to have a dedicated webspace (i.e. outbound IPs) is to deploy an App Service plan into an App Service Environment (ASE) (i.e. Isolated tier). ASE is the only thing that offers true single-tenency in App Service.

So neither of the above options will truly harden your SQL database if you want to isolate communication from only your web app. If you have resources in the same subnet, using vnet integration is the correct way to solve the problem.

If resources cannot be in the same subnet, the solution is to use Private Endpoints.

Whidah answered 5/7, 2021 at 21:9 Comment(0)
R
0

You have to configure the outbound IPs from the app service in the sql fw. You can find them under properties of your app service. Documentation. The reason why is that the VNET integration doesn't give your app service an outbound IP in the VNET you configured it in, so the FW you configured doesn't work.

Romine answered 9/6, 2020 at 9:41 Comment(3)
The problem is that I have a lot of app services. I assumed that if both the apps and DB server are connected to the same subnet, they would communicate using private IPs. I have around 20 app services sharing the same app plan. is there a better solution other than whitelisting the IPs for all the 20 apps?Keele
Not at the moment, I believe you will be able to use your configuration once Azure deploys in GA private endpoint for app service. You could configure 'Deny all public network access', then only app service that have access to the sql private endpoint from the VNET will access it, but you wouldn't be able to whitelist app services (because it disables FW rules).Romine
We used terraform to easily retrieve and configure all the IPs within the FW rules.Romine
T
0

I have working web apps which access storage accounts and KVs. These storage accounts and KVs accept traffic from a particular subnet and the web apps have been configured to integrate with those subnets. I did face an issue where even after integration apps were not able to access these resources. What worked for me was, I changed the App service SKU from Standard to Premium and restarted the app. As you can see, it warns that "Outgoing IPs of your app might change". This is not guaranteed solution but it worked for me.. several times! Not sure about SQL server though. Private endpoint does seem like the way to go but you can give this a try. enter image description here

Thrasher answered 9/6, 2020 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.