Subnet to subnet peering in azure - azure

We have our application and database in different VNETs in different subscription.
Also we have different environments (Pre-Production and Production).
Currently the database for PROD and PRE-PROD is in different subnet but same VNET.
I see we can have peering at VNET level.
We want the peering between the application and database at subnet level so that PRE-PROD application should not be able to connect to PROD database and vice-versa.

From Microsoft documentation:
Azure routes traffic between all subnets within a virtual network, by default. You can create your own routes to override Azure's default routing.
https://learn.microsoft.com/en-us/azure/virtual-network/tutorial-create-route-table-portal

You would want to look at network segmentation patterns. You can achieve basic microsegmentation by using Network Security Groups in Azure.
Based on your question, I assume you want to allow traffic only from one subnet into another subnet (over a peered network though, but that does not matter much) - and maybe even only allow one database port to be accessed from your application subnet - and lock everything else down.
This approach is described here: https://learn.microsoft.com/en-us/azure/architecture/framework/security/design-network-segmentation
You would want to create one NSG per subnet, make a rule to block all inbound traffic and then allow only traffic that is required. Note that NSG's are stateful, so you do not need to specify outbound rules for your traffic. Also make sure you apply the rules in the right order from top to bottom. The rule with the lowest id is applied first.

Related

Communication between 2 VMs in a Virtual Network on Azure

I have an access problem between two resources located in the same virtual network.
Concretely, I have a VM with an SQL instance on the SubNet "Data" inside the VNet "Common".
I have another VM with a Reporting Service instance on the "Front" SubNet, also inside the "Common" VNet.
The two VMs are therefore under the same VNet but under two different SubNets.
When I try to connect to the SQL database from the Reporting instance, I get an error message telling me that it cannot be accessed.
I solved the problem by adding, by hand, a rule in the NSG of my SubNet "Data" to allow communications from the IP of the "Reporting" VM on the SQL port.
And as soon as I do that, it works. I can connect to the SQL database which is on the SubNet "Data" from the Reporting of the SubNet "Front".
But what I don't understand is that my SubNet "Data" already contains an inbound rule on its NSG that allows all inbound connections (on all ports) if the call is from the virtual network. It is a rule present by default (called AllowVnetInBound).
Normally, I shouldn't have to add a specific rule for my VM Reporting. Especially since my VM has a dynamic IP, so this solution is not viable.
What am I missing?
Why the rule "AllowVnetInBound" which takes as source "VirtualNetwork" not enough?
Edit :
This is the NSG inbound rules for "Data" SubNet. I have outlined in green the rule that I must add for the communication to work. Without this rule, communication does not work.
By default, the VM in subnet "Data" should be able to communicate to the VM in subnet "Front" as both the subnets are in the same Virtual Network. We do not need to create any additional inbound or outbound rules
Sometimes, even though the VMs are in same virtual network, they might not be able to communicate to each other because of the firewall settings inside the VMs
So, the firewall needs to be turned off inside both the VMs so that both the VMs will be able to communicate to each other
Once the firewall inside both the VMs is turned off, you would be able to connect to the SQL database from the Reporting Instance
Is there any other custom lower priority rules above the default "AllowVnetInbound" rule?
This kind of scenario typically happens when you have added a lower priority custom rule on top of the default rule (like "AllowVnetInbound"), which logically would be blocking the default rule.
If this does not answer your question, please share a screenshot of the NSG rules in the earlier state before you set up the custom rule manually.
If this answers your questions, please mark the explanation as accepted.
subnets within one virtual network can communicate with each other without any extra configuration

GitHub self hosted runner have access to Azure resources behind a separate virtual network

I created some GitHub self-hosted runners and would like them to have access to my resources behind a separate virtual network. I know that whitelisting the IP address of the machine will give it access, but I will end up having any number of virtual machines that could be a self-hosted runner, so adding/deleting those IP addresses whitelist for each of my resources seems like a lot of manual work or having automation to whitelist IP addresses to each of my resources when creating the self-hosted runners.
I tried to peer the virtual network that my self-hosted runners would be connected to, to the virtual network of the rest of my resources thinking it would grant access to the self-hosted runners to those resources but I get a 403 firewall error when I attempt any changes or reading of the resource... Am I missing something here? Reading through Microsoft documentation makes it seem like peering the virtual networks would work.
I have bidirectional peering on both Vnets and forward traffic to and from the Vnets in the peering settings. My NSG on both VNet subnets are just the basic one that allows inbound and outbound VNet traffic
https://learn.microsoft.com/en-us/azure/virtual-network/virtual-network-peering-overview
Is there a recommended way of going at this?
If you just want to access the resources in one VNet from another VNet, the network peering is enough. But there is a limitation, there must be no NSG associated with resources or the VNet. If the NSGs exist, you need to add rules to allow the traffics. For example, if the resources are the VMs, then it should work as need. Of course, the firewall inside the VMs should also allow the traffics.

Azure App Service VNET integration and network optimization

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

Azure Subnet-to-Subnet Security Rules without Application Security Groups

I'm trying to understand the Network Security Groups and Application Security Groups. What I'm trying to achieve is I have a basic set up as below.
In my vnet, I have 2 subnets which are front-end and back-end and I have 2 NSGs that each subnet is assigned to.
Let's say I decided to allow RDP requests on my "back-end" subnet only for requests coming from the "front-end" subnet and deny any other RDP requests coming from other subnets.
I know that if I create ASGs and assign the FrontEnd VM and BackEnd VM an application security group then I can create a rule on NSG which is to allow RDP request from one ASG to the other ASG to achieve this but if you have dozens of VMs in a subnet then you wouldn't want to waste time to assign an ASG to every VM.
Is there a way to define a rule on a subnet that allows specific requests coming from other subnets?
create a rule and set the source to VirtualNetwork that will allow anyone from inside the Virtual Network (and peered ones) to send that type of traffic. If you want subnet granularity - you'd have to use subnet IP address ranges to allow\deny specific traffic patterns. You might also want to override the default rule to allow anything inside the virtual network

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.

Resources