Just trying to wrap my head around how NSG rules work when there are rules on a subnet and a NIC, so for the following scenario:
We have a machine vm1
with a NIC NIC1
whch is inside a subnet subnet1
.
Subnet1 Has an NSG with the default allow/deny rules, and also a rule to allow incoming SSH on port 22
NIC Has an NSG with the default allow/deny rules, and no additional rules.
You attempt to SSH into VM1, will it be allowed?
My understanding is this connection is not allowed, as the NSG for subnet1 is first evaluated which allows the connection, but then the NSG on NIC1 only has the default rules which would include DenyAll, because the NSG on NIC1 does not have an allow for SSH on port 22 it will be blocked
2
Answers
Yes that is correct. The connection will not be allowed in your scenario. This Microsoft documentation clearly explains this scenario as well.
Refer to the diagram below:
And the explanation from Microsoft:
Access should be blocked on your scenario. Bear in mind that Microsoft recommends to have NSG either applied on the subnet or NIC for simplified management.