Associate Azure AppService to a Subnet - azure

Ive created an Azure app service in my VPN. My VPN has a few subnets, but I need my AppService to use just a specific subnet. Unfortunately, I can't seem to find any way of linking the AppService to a subnet. I need the traffic on that subnet to pass through a special NSG.
Any advice?
Thanks

The multi-tenant App Service connects to your VNET over Point-to-site VPN, it will use the Point-to-site address space as source IP address. Conversely, App Service Isolated (ASE/ASEv2) is deployed in a subnet inside the VNET.
Assuming multi-tenant App Service, this is how traffic flows —
There is no way to initiate traffic from the VM through the Point-to-site VPN and reach the Web App over the private channel. Only the other way around works. This limitation does not exist in App Service Isolated.
App Service Isolated —

Related

Why Azure App service IP address not the in the integrated VNet IP address range?

I do not have networking background. I hope someone can explain to me about the Azure App service IP address. I have App Services which are integrated with my Azure VNet. But the inbound/outbound IP Addresses of those App Services are not in the range of VNet IP addresses. Why? What's the purpose of VNet integration?
In a on-premise network, if your service is running on a server in a subnet, the IP address of the service is normally the IP address of the server. Why it is so different on Azure.
VNet integration is meant to allow outbound traffic from your App Service app to be pushed into a private VNet rather than go directly to the public internet. It is not meant to grant inbound private access / deploy your App Service within the VNet.
If you want to isolate your App Service, then you should have a look to Azure Service Environments that allows you to deploy your App inside a VNet. Then, the IP of your App Service will be in sync with the IP range of your VNet.

why Extra subnet for VNET integration for app services

Why do we have to create a new subnet or add the app service to an empty subnet in our vnet?
I don't understand the reasoning since I'm trying to use my app service (function app) as a reverse proxy to access the resources in the vnet.
By default, the Azure function is a PaaS as the other Azure Platform-as-a-Services that have inbound and outbound traffic over the Internet. We can host our applications without the need to worry about the maintenance of the servers and their operating systems.
To use Azure Functions to connect to resources in an Azure virtual network, we can use the VNet integration feature. To use this feature, we need to create a subnet in the virtual network for your function app to use. VNet Integration must be configured to use an empty subnet. It doesn't matter that your functions use a different subnet than your VM. The virtual network automatically routes traffic between the two subnets. Read Connect your function app to the virtual network
The extra empty subnet is used to hosting your app instance. To let the app instance outbound traffic work like from a VNet, Azure mounts NICs with assigned private IP addresses in that subnet. With VNet integration, your function app is connected to both the internet and your virtual network.
For more information, you may read How regional VNet Integration works and How gateway-required VNet Integration works
For an app to access resources in a Virtual Network, it needs to be either part of that network, or use a VPN gateway, which in turn can be used access resources inside the Virtual Network.
App Services provides 2 methods to communicate with resources in the Virtual Network:
Regional VNet Integration
Gateway-Required VNet Integration
With Regional VNet Integration, the infrastructure allocates a private IP interface on the VM that is hosting your Web App. This interface is allocated an IP address from the integrated subnets address prefix. This interface is later used to communicate with the VNet hosted resources. This is in a way similar to how IaaS VM work, however the limitation of this interface is that it can be only used for making outbound connections.
This way, if the ASP is configured to scale out to multiple VM's then each VM is allocated a corresponding private IP interface. However, the allocation of these IP address is limited to the subnets Address prefix. Nancy has already included this in her post. App Services have overlapped recycling so during scale up/maintenance, the App Service Plan may run on twice the number of VM's to ensure minimal downtime. However this also means, that the Integrated Subnet should have sufficient addresses available, so that these allocations can happen.
The IP Address of this interface is exposed via the environment variable WEBSITE_PRIVATE_IP. Here is a screenshot of my Kudu Console
If your site is running on multiple instances, then you can use the Instance menu to toggle through the instances.
With Gateway-required VNet Integration, there is a pre-requisite of provisioning a Virtual Network route-based gateway configured with an SSTP point-to-site VPN. In this case, the VM's hosting the Web App download the VPN package on the respective VM's to setup a VPN, and this is used to connect to the resources in the Virtual Network.
Even here, you can use the WEBSITE_PRIVATE_IP environment variable to see the IP Address used by the VPN client on the App Service VM.
HTH,
Kaushal

How to integrate Azure Web App with a VNet with gateway transit

I have two VNets: A and B.
VNet B has a VPN gateway and connected to an on-premise network. VNet A is peered with VNet B with transit gateway enabled. This works perfectly for virtual machines. I deploy VMs to VNet A and can access on-premise resources from there VMs.
Now I want to deploy a Web App and connect it to VNet A, so the web app will have access to on-premise resources. But to do so, I need to add a VPN gateway into the network A, which is impossible when the network is peered with another network with Use remote gateway option on. But I need this option to be on to have access to on-premise resources.
What should I do? How I can give access from Web App to on-premise resources without using App Service Environment? Is it possible?
Basically, I need the combination of these two schemes
In this case, you should integrate with VNet B from the Azure web app. Also, It will be integrated with a point-to-site VPN enabled VNet. There is a new version of the VNet Integration feature that is in preview. It doesn't depend on point-to-site VPN. From your scenario, the web app is working like " VPN clients" in a P2S connection on the second picture.
Here are some things to keep in mind before connecting your web app to a virtual network:
A target virtual network must have point-to-site VPN enabled with a
route-based gateway before it can be connected to app. The VNet must
be in the same subscription as your App Service Plan(ASP). The apps
that integrate with a VNet use the DNS that is specified for that
VNet.
Ref: https://learn.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet

How can I connect an azure app service plan to a vnet which is also connected through peering to another vnet

I am trying to seup this hub-spoke toplogy where I have a hub vnet connected to an expressroute circuit https://learn.microsoft.com/en-us/azure/architecture/reference-architectures/hybrid-networking/hub-spoke
I have another VNET (lets call it the app vnet) set up with peering to this hub VNET where I can create a virtual machine and ping resources on the other end of just fine using the remote gateway setting on the peering.
The problem is by using remote gateway, my app vnet cannot have its own gateway, and so I cannot integrate an app service plan with the vnet.
Is there another way I could accomplish this?
I would like to suggest setting up a VNet-to-VNet VPN gateway connection instead of Vnet peering between hub vNet and app vNet. If so, Each of vNet will have their own gateway. The App vNet will be integrated with your web app. You need to ensure that the address prefixes don’t overlap among all the connected networks.
Update
Perhaps you can use the new preview VNet Integration.
There is a new version of the VNet Integration capability that doesn't
depend on Point-to-Site VPN technology. Unlike the pre-existing
feature, the new Preview feature will work with ExpressRoute and
Service Endpoints.
The new version is in Preview and has the following characteristics.
No gateway is required to use the new VNet Integration feature You can
access resources across ExpressRoute connections without any
additional configuration beyond integrating with the ExpressRoute
connected VNet. The app and the VNet must be in the same region
...
Ref: https://learn.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet#new-vnet-integration
The limitation that you are encountering is from the Vnet gateway perspective. Using remote gateway over peering handicaps one from deploying the Gateway in that Vnet.
The alternative as suggested by #nancy should do the trick. But, you will have to incur the cost of having the gateway. Secondly, this will require a co-existence set-up.
That is you will have to deploy another VPN gateway:
Change of reference:
VNET-HUB (Your hub VNET with ExR)
VNET-SPOKE1 (Current peered as referred to as your Application VNet)
Your VNET-HUB has an ExR gateway, it needs to have another VPN gateway.
Your VNET-SPOKE1 needs to have a VPN gateway deployed as well.
Allowing for the VNET-HUB to talk to the App Service Environment that you would integrate via point-to-site.
Note: The On-premise will not be able to access the App VNet as we can't have a Point-to-site co-exist with Express Route.
I hope this has provided an insight into the limitations.
References/good reads:
https://learn.microsoft.com/en-us/azure/expressroute/expressroute-routing
https://learn.microsoft.com/en-us/azure/expressroute/expressroute-howto-coexist-classic
https://learn.microsoft.com/en-us/azure/expressroute/expressroute-faqs
https://learn.microsoft.com/en-us/azure/app-service/environment/app-service-app-service-environment-network-configuration-expressroute

How do you connect Azure VMs, App Services, and on-prem machines to the same vnet?

We need a configuration set up exactly like the one described by the diagram in this support document. However, we already have the bottom right 2/3 configured, and it is not clear to me how the Point-to-site VPN should be configured:
Our Azure VMs and our on-premises machines share a VNet, connected via a site-to-site route-based VPN tunnel. We want to add our App Services to that VNet so they can also communicate privately with the VMs, but the documentation for configuring a Point to Site connection assumes you are starting from scratch, rather than adding to an existing VNet, and it does not cover Point-to-site connections to App Services.
It seems like a Point-to-site configuration needs to be added to the existing gateway, but I am unclear on several issues not covered by the documentation: How are certificates handled? What tunnel type is supported/preferred in App Services. Should the address pool of the Point-to-site config match the VNet's Gateway subnet range?
Update: After adding an address pool value for the Point-to-side configuration in the existing VNet gateway, the VNet could be added to our App Service. But even though The App Service VNet config reports that certs are in sync and that the gateway status is online, the App Service does not seem to be able to communicate with a VM, and nothing is listed under Allocated IP addresses in the Point-to-side configuration.
I am not sure if additional configuration is needed or if this implies a problem with the VNet addressing. The VNet default subnet is 10.1.0.0/24, the VNet gateway subnet is 10.1.1.0/24, and the Point-to-site pool is 10.1.2.0/24.
How are certificates handled?
You don't need to create certificates for the Point-to-Site configuration. Certificates are automatically created when you connect your WebApp to the VNet using the portal.
What tunnel type is supported/preferred in App Services?
This is a reference to the P2S VPN features, you can take a look at this link. P2S supports the protocols such as Secure Sockets Tunneling Protocol (SSTP) and IPsec.
Should the address pool of the Point-to-site config match the VNet's
Gateway subnet range?
You should not match the address pool of P2S with VNet's Gateway subnet. They are two address pools with different network.

Resources