Securing Azure Networks: NSGs, Application Security Groups, Azure Firewall, Bastion, DDoS Protection and WAF
Layers of Network Defense
text
Internet ─► DDoS Protection ─► Front Door / Application Gateway + WAF (layer 7)
─► Azure Firewall (central filtering) ─► NSGs on subnets / NICs ─► workloads
Admins: Azure Bastion or JIT, never open RDP/SSH to the internet. PaaS: Private Endpoints.
Network Security Groups (NSGs)
- A list of allow/deny rules for inbound and outbound traffic, attached to a subnet and/or a NIC
- Each rule has priority (100 to 4096, lower first), source, destination, port, protocol and action
- NSGs are stateful: return traffic is allowed automatically
- Default rules allow VNet-to-VNet and outbound internet, deny inbound from internet
bash
az network nsg create -g rg-net -n nsg-web
az network nsg rule create -g rg-net --nsg-name nsg-web -n allow-https --priority 100 --direction Inbound --access Allow --protocol Tcp \
--source-address-prefixes Internet --destination-port-ranges 443
az network nsg rule create -g rg-net --nsg-name nsg-web -n deny-all-other --priority 4000 --direction Inbound --access Deny --protocol '*' \
--source-address-prefixes '*' --destination-port-ranges '*'
az network vnet subnet update -g rg-net --vnet-name vnet-app -n web --network-security-group nsg-web
| Helper | Meaning |
|---|---|
| Service tags | Named groups of Azure IP ranges that Microsoft updates (Internet, VirtualNetwork, Storage, AzureLoadBalancer, Sql) |
| Application security groups (ASGs) | Group VMs by role (asg-web, asg-db) and write rules between groups, not IP addresses |
| Augmented rules | Many IPs and ports in one rule |
| NSG flow logs / VNet flow logs | Record allowed and denied traffic for analysis with Traffic Analytics |
bash
az network asg create -g rg-net -n asg-web
az network asg create -g rg-net -n asg-db
az network nsg rule create -g rg-net --nsg-name nsg-data -n web-to-db --priority 100 --direction Inbound --access Allow --protocol Tcp \
--source-asgs asg-web --destination-asgs asg-db --destination-port-ranges 1433
Azure Firewall
- A managed, stateful firewall as a service with built-in high availability and autoscaling
- Filters by **network rules (IP and port), application rules (FQDN like
*.windows.net), DNAT rules** - Tiers: Basic (small business), Standard, Premium (TLS inspection, IDPS intrusion detection, URL filtering, web categories)
- Managed centrally with Firewall Policy, inherited by child policies
- Usually deployed in the hub VNet of a hub-and-spoke design, with spokes routed through it using UDRs
bash
az network firewall policy create -g rg-hub -n fwpol-main --sku Standard
az network firewall create -g rg-hub -n fw-hub --sku AZFW_VNet --tier Standard --firewall-policy fwpol-main --vnet-name vnet-hub --public-ip fw-pip
Azure Bastion
- Secure RDP/SSH from the portal or native client over TLS (443) to VMs with private IPs only
- Needs the
AzureBastionSubnet(/26 or larger). Tiers: Developer (free for dev), Basic, Standard, Premium - Replaces exposing management ports to the internet
DDoS Protection
| Tier | Description |
|---|---|
| Infrastructure protection | Default on for Azure, protects the platform |
| DDoS IP Protection / Network Protection | Adaptive tuning, attack analytics, mitigation reports, cost protection and rapid response support for your public IPs |
Web Application Firewall (WAF)
- Protects web apps from OWASP top 10 attacks such as SQL injection and cross-site scripting
- Runs on Application Gateway (regional) or Azure Front Door (global)
- Modes: Detection (log) and Prevention (block). Start in detection, tune rules, then prevent
- Add custom rules and bot protection, rate limiting, geo filtering
Private Link
- Private endpoints put PaaS services (Storage, SQL, Key Vault, Cosmos DB, App Service) on private IPs in your VNet
- Combine with Private DNS zones and then disable public network access on the service
Putting It Together
| Need | Use |
|---|---|
| Allow only HTTPS from the internet to the web tier | NSG on web subnet |
| Only web servers talk to database servers | ASGs or subnet NSG rules |
| Control and log outbound internet | Azure Firewall + UDR |
| Admin access without public ports | Bastion or JIT |
| Stop web attacks | WAF on Front Door or Application Gateway |
| Keep storage off the internet | Private endpoint + disable public access |
Practice
- Create an NSG that allows 443 only and apply it to a subnet
- Use ASGs to allow web to database on port 1433
- Draw a hub-and-spoke design with Azure Firewall
- Connect to a VM through Bastion
- Turn on a WAF policy in detection mode
Conclusion
Use NSGs and ASGs for basic filtering, Azure Firewall for central control, Bastion or JIT for admin access, DDoS and WAF for edge protection and private endpoints to keep PaaS services off the internet.
Quick Summary: layers; NSG; Firewall; Bastion; DDoS; WAF; Private Link; summary.

