Forum Discussion

Mahmoud_Yaseen_AZHero's avatar
Mahmoud_Yaseen_AZHero
Copper Contributor
May 24, 2025

Azure NSG Challenge : When NIC and Subnet Rules Collide

Imagine this real-world scenario:

🔹 A VM needs to connect outbound via RDP (TCP 3389) to an external server for management. 

🔹 The NIC-level NSG allows outbound RDP, ensuring the VM can initiate connections. 

🔹 However, the Subnet-level NSG has an inbound deny rule specifically for RDP.

💭 Question for IT Pros: 

👉 Would the outbound RDP session succeed or be blocked due to the subnet-level NSG? 

👉 How do you design NSG rules to prevent misconfigurations while maintaining security? 

#######################################################

Great challenge! Let's break it down:

🚦 Would the outbound RDP session succeed or be blocked?
The outbound RDP session would succeed because the subnet-level NSG applies to inbound traffic coming into the subnet, not traffic leaving the VM. Since outbound RDP is explicitly allowed at the NIC level, the VM can initiate connections without issue.

However, if the external server tries to respond back, the inbound deny rule at the subnet level would block the return traffic. This effectively disrupts the session, making it seem like the connection failed.

🔒 How to design NSG rules effectively?
To prevent misconfigurations while maintaining security:

1- Understand NSG processing – Rules are evaluated independently at the NIC and Subnet levels, but both must allow the required traffic.

2- Use least privilege principles – Only allow necessary traffic and explicitly deny everything else.

3- Be careful with inbound rules at the subnet level – Blocking inbound traffic here can unintentionally interfere with legitimate outbound sessions.

4- Log traffic flows with NSG Flow Logs – Use diagnostic settings to capture insights for troubleshooting.

5- Consider Application Security Groups (ASGs) – These simplify NSG management by grouping resources dynamically.

4 Replies

  • SubhroMajumder's avatar
    SubhroMajumder
    Copper Contributor

    A) The outbound RDP connection will succeed.

    Because Azure NSGs are stateful, only outbound rules are evaluated for outbound traffic. The inbound deny rule at the subnet level doesn't impact return traffic from an outbound-initiated session.


    B) NSG Best Practices to Avoid Misconfiguration:

    Remember: A response traffic to an outbound is considered as a "reply" traffic, not as an "inbound" traffic.
    An inbound traffic is a traffic which originated outside the subnet where NSG is applied.

    1) Use subnet NSGs for broad control, and NIC NSGs for fine-grained access.

    2) Be aware and follow Azure’s stateful behavior—don’t block return traffic by mistake.

    3) Prefer service tags and ASGs over hardcoded IPs.

    4) Regularly audit traffic using NSG Flow Logs and Network Watcher.

    5) Follow the principle of least privilege—only allow what's truly needed.

  • SubhroMajumder's avatar
    SubhroMajumder
    Copper Contributor

    Answer: The outbound RDP connection will succeed.

    Because Azure NSGs are stateful, only outbound rules are evaluated for outbound traffic. The inbound deny rule at the subnet level doesn't impact return traffic from an outbound-initiated session.

  • Walli's avatar
    Walli
    Copper Contributor

    Since the NIC-level NSG explicitly permits outbound RDP, the VM can successfully initiate the session. However, given the inbound deny rule at the subnet level, the return traffic from the external server would be blocked, effectively disrupting the connection. Would you say the subnet-level inbound restriction is primarily intended to mitigate external threats, or is it designed around a specific network segmentation strategy? 

    • Mahmoud_Yaseen_AZHero's avatar
      Mahmoud_Yaseen_AZHero
      Copper Contributor

      NSG is a Stateful F.W allows RDP response session, NSG on the subnet will not interfere with this because it denies inbound if initiated from external networks 

Resources

OSZAR »