Azure App Service VNET integration and network optimization - azure

An Azure support engineer suggested that I put two app services on the same VNET in order to optimize my traffic. I'm new to VNETs so I'm trying to grok how this works. So far I've successfully added both the app services to the same VNET. However, it's unclear to me if it's "working" or not. I've tried reading the docs but they are incredibly dense and difficult for me to see the forest for the trees. So here's where I'm at:
Based on what I've read it seems like if services are in the same VNET the traffic between them will be routed differently. For example, say I have two services: service1.mydomain.com and service2.mydomain.com. Service 1 makes calls to service 2 via the service2.mydomain.com url. Normally, that traffic would go all the way back out to the internet and back in. But it sounds like just by adding them to the same VNET the traffic is somehow routed differently on an optimized and cheaper path. Is that accurate or is there more configuration required? If so, how can I verify that it's working?
Thanks!

It depends on the App Service Plan you're using for your App Service. If you're using Azure App Services on an App Service Environment, you'll have your own VNet for routing and it should work like that (I'm not too familiar with ASEs)
However, if you're using a Premium or lower tier, VNet integration is only useful for outbound calls, meaning that an App Service will be able to access resources on that VNet, but other integrated App Services are not on that VNet, they are just able to access resources on it as well (https://learn.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet).
If you want the App Services to be accessed through that VNet you'll need to set up Service Endpoints or Private Endpoints. See https://learn.microsoft.com/en-us/azure/app-service/networking-features for more details

Support is correct. Since both these services are on the same VNET, traffic will not flow outside the VNET and will be optimized. This is because the default routes for all VNETs have a route with a next hop of Virtual Network.
Virtual network: Routes traffic between address ranges within the address space of a virtual network. Azure creates a route with an address prefix that corresponds to each address range defined within the address space of a virtual network. If the virtual network address space has multiple address ranges defined, Azure creates an individual route for each address range. Azure automatically routes traffic between subnets using the routes created for each address range. You don't need to define gateways for Azure to route traffic between subnets. Though a virtual network contains subnets, and each subnet has a defined address range, Azure does not create default routes for subnet address ranges, because each subnet address range is within an address range of the address space of a virtual network.
https://learn.microsoft.com/en-us/azure/virtual-network/virtual-networks-udr-overview

Related

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

Azure web app request is not going through VNET after inegration

I have created one Web app on Azure portal and its integrated with subnet under specific VNET.
Now, when I am trying to do telnet to one of my organisation's internal relay server IP from my web app its not getting connected. The request is going from web app's APIPA address range not from subnet's address range. I checked the IP as well of the web app using ifconfig and I found out that its taking from APIPA address range not from subnet one.
Any idea what steps do I need to take so that web app will take IP from subnet address range of the VNET not from APIPA address range.
Thanks in advance.
After my validation, when the app service on Linux is integrated with a virtual network. There is an extra NIC binding to the app service. It's IP address from APIPA address range. It looks like a design behavior as the app service on Linux is running in a standard Docker Container, read here. Also, for a normal app service is a multi-tenant environment, you can not get a dedicated IP address unless you are using a dedicated environment---ASE, read here.
Furthermore, from how regional VNet Integration works, you will see the app service integrated with a vNet is not the same as a VM from a VNet.
Regional VNet Integration works by mounting virtual interfaces with
addresses in the delegated subnet. Because the from address is in your
VNet, it can access most things in or through your VNet like a VM in
your VNet would. The networking implementation is different than
running a VM in your VNet. That's why some networking features aren't
yet available for this feature.
In this case, if you wan assign a private IP address for app service, you can use Azure Private Endpoint with web apps(Preview). Read this blog for more details.
Azure Private Endpoint provides private IP address access by using a
network interface controller (NIC) attached to a virtual network
subnet for an Azure web app, allowing access from an on-premise VPN or
ExpressRoute. Implementing an endpoint effectively blocks the public
inbound access. This technology is very similar to an internal App
Service Environment (ASE) but much cheaper.

Azure WebApp Static Outbound IP

I am trying to solve a problem. I have to access APIs that are hosted on my on premises server (on-prem) from Azure hosted Web API.
The problem is that my on-prem server only allows white listed IPs. I know we can get outbound IPs from our Web App (Azure hosted). But I am not sure whether they are static or will change based on scaling.
Another Solution is to create VNET and add that Web app into that VNET. But I would like someone to suggest better solutions.
There are couple of choices you have.
First, you can have a look at the possibleOutboundIpAddress of your App Service and whitelist this IPs. This however also opens up the door for IPs not really in use by your App Service.
az webapp show --resource-group <group_name> --name <app_name> --query possibleOutboundIpAddresses --output tsv
Secondly, you can put a NAT Gateway in-front of your App Service. This however requires an App Service Plan that supports virtual network integration.
Configure regional virtual network integration from within your app service.
Force all outbound traffic originating from that app to travel through the virtual network. This is done by setting WEBSITE_VNET_ROUTE_ALL=1 property in your web app configuration
Create a public IP address.
Add a NAT gateway, attach it to the subnet that contains the app service and make use of the public IP created in step 3.
If you would also like to use a static inbound IP you can find more information here
The outbound IPs for Azure App service are generally static and will not change on scaling. There are normally 4 outbound IPs and they only change if you change the SKU or there is a need at MS end to increase the capacity of their data center (rare or may never happen in near future).
I would recommend creating a VNET as that is more secure than whitelisting IPs at your on prem service. But if you want to want list the outbound IPs, I would recommend creating a wrapper for your on prem APIs in Azure and whitelist IPs for these in your on prem firewall. This will ensure that you don't have to whitelist every time you want to create an API in Azure that needs to access on prem APIs.
Unfortunately there is no straight forward way to do this in Azure for App Services, I also had this issue recently.
The only solution (for now anyway) is to add the list of outbound IPs of the App Service to your allow rules.
Just be careful with scaling between the tiers because it will change the outbound IP addresses. (https://learn.microsoft.com/en-us/azure/app-service/overview-inbound-outbound-ips#when-outbound-ips-change)
The simplest way would be to use an Azure VM with a static public IP which is used for both inbound and outbound.
Sam Cogan has a good blog post where he does go through a couple of options.
(https://samcogan.com/obtaining-a-static-outbound-ip-from-an-azure-virtual-network/)
A hybrid connection might be a solution https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections? I think they are designed for accessing on premise services.

Routing traffic between VNets in Azure

If two vnets are connected to each other via multiple set of peering vnets, how does azure route the traffic? Fo example, lets consider the below: A, B, C, D are 5 VNets and the they are peered (bi-directionally with traffic forwarding allowed).
Now if A wants to send a packet to D, how it is determined whether it will take the A-B-C-D path or the A-E-D path?
Any docs will be helpful.
As far as I know, VNet Peering connections are non-transitive. It seems that it's still on the roadmap. See the feedback here.
From your picture, If only VNet Peering connections between them, then A could not reach D, also A could not reach C. A only could reach direct-connected B and E.
If you want to allow much VNets communication. You could implement a hub-spoke network topology in Azure. As the hub network, you could deploy a VPN gateway then enable allow gateway transit to other spoke VNets and enable use remote gateways in each spoke VNets. If you require connectivity between spokes, consider implementing an NVA for routing in the hub, and using UDR(custom routes) in the spoke to forward traffic to the hub. In this scenario, you must configure the peering connections to allow forwarded traffic.
VNet Peering enables you to connect VNets through the Azure backbone network. Azure automatically creates a route table for each subnet within an Azure VNet and adds system default routes to the table. You can also override some of Azure's system routes with custom routes.
If multiple routes contain the same address prefix, Azure selects the
route type, based on the following priority:
User-defined
route BGP route
System route
You could get more details about Virtual network traffic routing
According to this article you'd need an NVA somewhere, vnet peering is non transitive.
At the beggining of the same article they talk a bit more about this.
To sum it up. packet wont reach D from A unless you fix your networking setup
Some years ago but i think service chaining allows that as far as i understand the documentation
To enable service chaining, configure user-defined routes that point
to virtual machines in peered virtual networks as the next hop IP
address. User-defined routes could also point to virtual network
gateways to enable service chaining.

Does Azure Point-to-Site or Site-to-Site VPN support cloud services?

I haven't dug in completely, but I'm trying to figure out if the new Azure VPN offerings are just for your own VMs or if they will allow cloud services to connect to your corporate network. For example, I can I use it to have my worker role print to a network printer on my corporate network.
As long as your cloud service is part of a virtual network, it will have an IP address of the VPN subnet assigned to it, and all addresses are accessible (subject to your own networking configuration). Two things to be careful of:
The VPN IP address of the individual instances are subject to change. Every time a role recycles, or you redeploy, the instance IP address will change. This may be a problem if your security requires specific IP addresses. This can be helped by maintaining these ip addresses in your own DNS.
The cloud service load balancer is 'external' and cannot be placed on the virtual network. This means that your cloud service is not addressable as a single endpoint. You have to communicate with each individual role and load balance yourself. Similarly, outgoing data comes from individual roles, not the cloud service (see 1 above).
I haven't tried personally, but you should be able to do just that by joining your cloud service to a virtual network. See this article for details on how to do this: http://convective.wordpress.com/2012/08/26/windows-azure-cloud-services-and-virtual-networks/.

Resources