โ† Back to list

Part 33 ~๐Ÿ” Azure NSGs in Action: From Theory to Real-World Security

Intermidiate Bonus~ Azure Networking

Shubham Barman ยท 2025-11-19 16:32 ยท 0 claps ยท 3.2 min read
#asg #application-security #networking #azure
Open on Medium โ†—
Wiki topics: โ˜๏ธ ยท DevOps & Cloud

Part 33 ~๐Ÿ” Azure NSGs in Action: From Theory to Real-World Security

Intermidiate Bonus~ Azure Networking

Youโ€™ve explored the theory behind NSGs. You know what they are, where they go, and how they work.

But theory isnโ€™t enough.

Now itโ€™s time to apply it โ€” step by step โ€” with real scenarios, best practices, and the kind of decisions cloud architects make every day.

Letโ€™s move from โ€œwhat is an NSGโ€ to โ€œhow do I use it to secure my network?โ€

๐Ÿงช Scenario: A Simple Two-Tier Architecture

Youโ€™re building a basic web app in Azure:

  • A Frontend subnet with web servers
  • A Backend subnet with database servers

Your goals:

  • โœ… Allow users to access the website
  • โœ… Let web servers talk to the database
  • โŒ Block backend servers from reaching the internet
  • ๐Ÿ” Secure admin access with RDP (temporarily)

Letโ€™s build the NSGs to make this happen.

๐Ÿ”ง Step 1: Create NSGs

Youโ€™ll need two NSGs:

  • frontend-nsg โ†’ attach to the frontend subnet
  • backend-nsg โ†’ attach to the backend subnet

๐Ÿง  One subnet = one NSG. But one NSG can be reused across subnets if needed.

๐Ÿ” Step 2: Define Custom Rules

๐Ÿ” Step-by-Step: Building NSGs

๐Ÿข Frontend NSG (Web Department)

โœ… Allow HTTP (Port 80) โ†’ So users can access your website

โœ… Allow RDP (Port 3389) โ†’ For admin access (but consider Bastion for production)

๐Ÿง  Best Practice: Never allow RDP from โ€œAnyโ€ in production. Use IP whitelisting or Bastion.

๐Ÿ—„๏ธ Backend NSG (Database Department)

โœ… Allow SQL (Port 1433) โ†’ So web servers can query the database โ†’ Restrict source to frontend subnet for tighter control

โœ… Allow RDP (Port 3389) โ†’ For admin access

โŒ Deny Internet Outbound โ†’ Prevent data exfiltration or accidental exposure

๐Ÿง  Industry Principle: Backend systems should be shielded from direct internet access. Always.

๐Ÿ” Step 3: Understand Default Rules

Azure includes default rules in every NSG:

๐Ÿง  You canโ€™t delete these โ€” but you can override them with custom rules (priority 100โ€“4096).

๐Ÿง  Rule Evaluation: Who Wins?

NSG rules are evaluated by priority:

  • Lower number = higher priority
  • First match wins
  • Later rules are ignored

Example:

  • Rule 100: Deny internet outbound
  • Rule 200: Allow outbound to 8.8.8.8 โ†’ Result: Deny wins

โ— Always check for rule conflicts. One misordered rule can break or expose your app.

๐Ÿงช Are These Rules Doing Anything Yet?

Not until a VM is deployed.

NSGs are like guards waiting at empty desks. Once a VM is connected to a NIC, traffic starts flowing โ€” and the NSG starts filtering.

๐Ÿง  Subnet-level NSGs apply to all NICs inside. NIC-level NSGs override or complement them.

โœ… Best Practices You Should Follow

Hereโ€™s what experienced teams do:

  • ๐Ÿ” Start with deny-all, then allow only whatโ€™s needed
  • ๐Ÿงฑ Use subnet NSGs for broad control, NIC NSGs for exceptions
  • ๐Ÿงช Test with Network Watcher before going live
  • ๐Ÿšซ Avoid โ€œAnyโ€ in production โ€” use IP ranges or service tags
  • ๐Ÿ“ฆ Group similar VMs into subnets for easier rule management
  • ๐Ÿงญ Name rules clearly: Allow-HTTP-From-Internet, Deny-All-Outbound, etc.
  • ๐Ÿง  Use service tags (like Internet, VirtualNetwork) for cleaner rule
  • ๐Ÿงญ Document rule intent in the NSG name and description

๐Ÿงญ Final Takeaways

  • NSGs are stateless: they donโ€™t remember past traffic
  • Rules apply in both directions โ€” inbound and outbound
  • Priority matters: lower number wins
  • NSGs are your first layer of defense โ€” simple, fast, and essential

๐Ÿ”œ Whatโ€™s Next?

Youโ€™ve built NSGs. Youโ€™ve defined rules. Youโ€™ve secured your subnets.

But hereโ€™s a real-world challenge:

What happens when you deploy 1,000 VMs into a single subnet?

Letโ€™s say half of them are web servers, some are app servers, and others are database nodes. You want to allow HTTP only to web servers, SQL only to databases, and RDP only to a few admin boxes.

Now imagine writing NSG rules for each IP manually. Or worse โ€” trying to track which IP belongs to which role.

Thatโ€™s where things break down.

โ— NSGs donโ€™t understand โ€œroles.โ€ They only understand IPs.

So how do you group VMs by function, not by address?

In the next session, weโ€™ll explore Application Security Groups (ASGs) โ€” Azureโ€™s way of tagging VMs by purpose and writing NSG rules that target those tags.

Itโ€™s like saying:

โ€œAllow HTTP to all machines tagged as WebServers.โ€ โ€œBlock internet access from anything tagged as Backend.โ€

No IPs. No manual tracking. Just clean, scalable logic.

Letโ€™s make NSGs smarter โ€” by combining them with ASGs.


๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
post_id
7e53fde6e59e
slug
part-6-azure-nsgs-in-action-from-theory-to-real-world-security-7e53fde6e59e
url
https://medium.com/@barmanshubham70/part-6-azure-nsgs-in-action-from-theory-to-real-world-security-7e53fde6e59e
canonical_url
https://medium.com/@barmanshubham70/part-6-azure-nsgs-in-action-from-theory-to-real-world-security-7e53fde6e59e
author_url
https://medium.com/@barmanshubham70
status
ok
fetched_at
2026-06-10 08:34:46