09 / 13Network and compute
Azure Virtual Network security hardening
Harden Azure Virtual Network: NSGs without internet management ports, private subnets, Azure Firewall egress, private endpoints, DDoS, Bastion, flow logs.
- Service
- Virtual Network
- Category
- Network and compute
- Baseline
- 11 controls
- Updated
On this page
Azure Virtual Network (VNet) is the private network your VMs, containers and private endpoints live in, filtered by network security groups (NSGs) and routed by user-defined routes. Identity is the primary perimeter in Azure, but the network still decides what is reachable from the internet before an attacker has a credential, and how far they can move after. Internet-facing RDP and SSH remain among the most common initial access vectors for cloud VMs (MITRE ATT&CK T1133, External Remote Services), and mass scanners find a newly opened port 3389 within minutes. At defaults, a VNet allows all traffic between subnets, VMs in older VNets get implicit outbound internet access, and PaaS services keep a public endpoint even after you add a private endpoint. This page maps to the Network Security (NS) and Logging and Threat Detection (LT) domains of the Microsoft cloud security benchmark (MCSB) and to the Networking section of the CIS Microsoft Azure Foundations Benchmark.
Baseline controls
CIS numbers refer to the CIS Microsoft Azure Foundations Benchmark v7.0.0.
| Control | Why | How to check | ID |
|---|---|---|---|
| NSG on every subnet | Unfiltered subnets allow free lateral movement | Policy "Subnets should be associated with a Network Security Group" | MCSB NS-1 / CIS 7.4 |
| No management ports from the internet | RDP and SSH exposure is a top initial access vector | Resource Graph query on securityRules | MCSB NS-1 / CIS 7.1.1, 7.1.2, 7.1.5 |
| Rules by ASG and service tag | IP lists drift, role-based rules stay correct | az network asg list | MCSB NS-7 |
| No public IPs on VM NICs, WAF in front of web apps | Few controlled entry points | Policy "Network interfaces should not have public IPs" | MCSB NS-6 / CIS 7.2.6, 7.10 |
| Private subnets and forced egress | Implicit internet egress enables C2 and exfiltration | az network vnet subnet show --query defaultOutboundAccess | MCSB NS-3 / CIS 7.11 |
| Firewall threat intelligence and IDPS | Blocks known malicious destinations and exploits | Firewall policy threatIntelMode | MCSB NS-4 |
| Private endpoints, public access disabled | Removes PaaS data stores from the internet | publicNetworkAccess on each resource | MCSB NS-2 |
| Central private DNS | Wrong DNS silently sends traffic to the public endpoint | privatelink.* zones linked to the hub | MCSB NS-10 |
| DDoS Network Protection | Volumetric attacks on public IPs | Policy "Virtual networks should be protected by Azure DDoS Protection" | MCSB NS-5 / CIS 8.6 |
| Azure Bastion for administration | RDP and SSH without public IPs on VMs | az network bastion list | CIS 8.4.1 |
| VNet flow logs | Network evidence for investigations | az network watcher flow-log list -l <region> | MCSB LT-4 / CIS 6.1.1.6 |
Network security groups on every subnet
NSGs are stateful layer 4 filters attached to subnets and network interfaces. Design in a hub and spoke topology: the hub VNet (connectivity subscription) holds Azure Firewall, Azure Bastion, gateways and the DNS Private Resolver; spoke VNets hold workloads only and are peered to the hub. Azure Virtual WAN with a secured virtual hub implements the same pattern as a managed service.
Associate an NSG with every subnet, except those that forbid or restrict it (GatewaySubnet, AzureFirewallSubnet; AzureBastionSubnet accepts one only with specific rules). Add a low-priority deny rule for intra-VNet traffic and explicit allows above it, because the default AllowVnetInBound rule lets every subnet talk to every other.
az network nsg create -g rg-app1 -n nsg-snet-app
az network vnet subnet update -g rg-app1 --vnet-name vnet-app1 -n snet-app \
--network-security-group nsg-snet-app
Enforce with the built-in policy Subnets should be associated with a Network Security Group (Audit, or Deny in landing zones) and its companion Gateway subnets should not be configured with a network security group. Defender for Cloud also flags Internet-facing virtual machines should be protected with network security groups and Non-internet-facing virtual machines should be protected with network security groups.
No management ports from the internet
The CIS benchmark checks for inbound rules that allow RDP (3389, CIS 7.1.1), SSH (22, CIS 7.1.5), UDP (CIS 7.1.4) and HTTP(S) (CIS 7.1.3) from the internet where not needed. The red flags are a source of *, 0.0.0.0/0, Internet or Any. Add a high-priority deny as a backstop, so a later "temporary" allow is the visible exception:
az network nsg rule create -g rg-app1 --nsg-name nsg-snet-app \
--name deny-mgmt-from-internet --priority 100 \
--direction Inbound --access Deny --protocol Tcp \
--source-address-prefixes Internet \
--destination-port-ranges 22 3389 5985 5986
Find risky rules across all subscriptions with Resource Graph:
resources
| where type =~ "microsoft.network/networksecuritygroups"
| mv-expand rule = properties.securityRules
| extend access = tostring(rule.properties.access),
direction = tostring(rule.properties.direction),
src = tostring(rule.properties.sourceAddressPrefix),
ports = strcat(tostring(rule.properties.destinationPortRange), " ",
tostring(rule.properties.destinationPortRanges))
| where access == "Allow" and direction == "Inbound"
| where src in ("*", "0.0.0.0/0", "Internet", "Any")
| project nsg = name, resourceGroup, subscriptionId, rule = tostring(rule.name), ports
Note that this misses port ranges such as 1-65535 written as a range; review any rule whose port field contains - or *. Audit with Management ports should be closed on your virtual machines (AuditIfNotExists only, it cannot deny) and, for remaining legitimate needs, Management ports of virtual machines should be protected with just-in-time network access control (see Virtual Machines).
Application security groups and service tags
Write rules by role, not by IP. Application security groups (ASGs) group NICs (asg-web, asg-db), so a rule like "asg-web to asg-db on 1433" stays correct when the scale set grows. Service tags (Storage.WestEurope, AzureMonitor, AzureActiveDirectory) represent Microsoft-maintained prefixes for outbound allows.
az network asg create -g rg-app1 -n asg-db
az network nsg rule create -g rg-app1 --nsg-name nsg-snet-data \
--name allow-web-to-sql --priority 200 --direction Inbound --access Allow \
--protocol Tcp --source-asgs asg-web --destination-asgs asg-db \
--destination-port-ranges 1433
For organization-wide rules that application teams cannot override (for example "deny inbound 3389 from Internet everywhere"), use Azure Virtual Network Manager security admin rules. They are evaluated before NSG rules.
One front door for inbound traffic
Public inbound traffic should arrive through a small number of controlled entry points:
- Azure Front Door or Application Gateway with Web Application Firewall in prevention mode for HTTP(S).
- Azure Firewall DNAT rules for the rare non-HTTP service that must be public.
VMs should not have public IPs. Assign Network interfaces should not have public IPs with Deny to landing zone management groups, and Azure Web Application Firewall should be enabled for Azure Front Door entry-points and Azure Application Gateway should be deployed with Azure WAF for web workloads. List current exposure:
resources
| where type =~ "microsoft.network/publicipaddresses"
| extend attachedTo = tostring(properties.ipConfiguration.id)
| project name, resourceGroup, subscriptionId, ip = tostring(properties.ipAddress), attachedTo
Private subnets and forced tunneling egress
A VM without an explicit outbound method historically reached the internet through "default outbound access", an implicit public IP owned by Microsoft. For the network API versions released after March 31, 2026, subnets in new VNets default to private (defaultOutboundAccess: false); the portal already did this. Existing VNets are not changed, and deployments that pin older API versions (common in Terraform and older templates) still create non-private subnets. Set it explicitly:
az network vnet subnet update -g rg-app1 --vnet-name vnet-app1 -n snet-app --default-outbound false
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2024-05-01' = {
parent: vnet
name: 'snet-app'
properties: {
addressPrefix: '10.20.1.0/24'
defaultOutboundAccess: false
networkSecurityGroup: { id: nsg.id }
routeTable: { id: rt.id }
}
}
Existing VMs must be stopped and deallocated for the change to take effect. Audit with Subnets should be private.
Then provide egress explicitly, through Azure Firewall rather than a plain NAT Gateway where you want inspection. Force all spoke egress through the hub firewall with a route table:
az network route-table create -g rg-app1 -n rt-spoke-app1 --disable-bgp-route-propagation true
az network route-table route create -g rg-app1 --route-table-name rt-spoke-app1 \
-n default-to-firewall --address-prefix 0.0.0.0/0 \
--next-hop-type VirtualAppliance --next-hop-ip-address 10.0.1.4
az network vnet subnet update -g rg-app1 --vnet-name vnet-app1 -n snet-app \
--route-table rt-spoke-app1
Routes with next hop Internet (often used to bypass the firewall for service tags) break in private subnets without an explicit outbound method; avoid them anyway, since they are an uninspected path out.
Azure Firewall policy
Use a Firewall Policy (not classic rules) with:
- Application rules allowing only the FQDNs each workload needs, plus FQDN tags such as
WindowsUpdate. Default deny everything else. - Threat intelligence mode Alert and deny.
- IDPS in Alert and deny, and TLS inspection for HTTPS egress where legally and technically feasible (both require the Premium SKU).
- DNS proxy enabled, with spokes using the firewall as DNS server, so FQDN network rules resolve consistently.
az network firewall policy update -g rg-connectivity -n fwp-hub \
--threat-intel-mode Deny --enable-dns-proxy true
az network firewall policy show -g rg-connectivity -n fwp-hub \
--query "{ti:threatIntelMode, dns:dnsSettings.enableProxy, sku:sku.tier}"
Enforce with Azure Firewall Policy should enable Threat Intelligence, Azure Firewall Policy should have DNS Proxy Enabled and Azure Firewall Classic Rules should be migrated to Firewall Policy. Egress filtering stops a compromised workload from reaching attacker infrastructure (T1041, Exfiltration Over C2 Channel) and is where you see it happen, if you log it.
Private endpoints and public network access
A private endpoint gives a PaaS resource (Storage, Key Vault, SQL Database, App Service and many more) a private IP in your VNet. It does not disable the public endpoint: you must also set publicNetworkAccess to Disabled on the resource.
az network private-endpoint create -g rg-app1 -n pe-kv-app1 \
--vnet-name vnet-app1 --subnet snet-private-endpoints \
--private-connection-resource-id <key-vault-id> \
--group-id vault --connection-name kv-app1
az keyvault update -g rg-app1 -n kv-app1 --public-network-access Disabled
NSGs and route tables only apply to private endpoint traffic when network policies are enabled on the subnet:
az network vnet subnet update -g rg-app1 --vnet-name vnet-app1 \
-n snet-private-endpoints --private-endpoint-network-policies Enabled
Per-service policies such as Azure Key Vault should disable public network access and Azure SQL Database should restrict or disable Public network access enforce the second half. Private endpoints are preferable to service endpoints for sensitive data, because they bind to a specific resource and prevent exfiltration to another tenant's instance of the same service.
Private DNS for private endpoints
Clients must resolve kv-app1.vault.azure.net to the private IP through the privatelink.vaultcore.azure.net zone. Keep all privatelink.* private DNS zones centrally in the connectivity subscription, linked to the hub VNet and the DNS Private Resolver, and deny teams from creating their own copies (a duplicate zone in a spoke breaks resolution for everyone using it). Use the built-in DeployIfNotExists policies such as Configure Azure Key Vaults to use private DNS zones or Configure a private DNS Zone ID for blob groupID so records are created automatically when a private endpoint is deployed.
Verify from a VM in a spoke:
nslookup kv-app1.vault.azure.net
# Expected: CNAME to kv-app1.privatelink.vaultcore.azure.net, A record in 10.x
DDoS protection
Every public IP gets infrastructure-level DDoS protection, but it is tuned for Azure as a whole, not for your application. Azure DDoS Network Protection (per VNet, through a DDoS protection plan) or DDoS IP Protection (per public IP) adds adaptive tuning, attack telemetry and mitigation reports. Enable it on VNets that hold public IPs for important services.
az network ddos-protection create -g rg-connectivity -n ddos-plan-hub
az network vnet update -g rg-connectivity -n vnet-hub \
--ddos-protection true --ddos-protection-plan ddos-plan-hub
Audit with Virtual networks should be protected by Azure DDoS Protection. Enable diagnostic logs on protected public IPs (DDoSProtectionNotifications, DDoSMitigationFlowLogs, DDoSMitigationReports) and alert on the IfUnderDDoSAttack metric.
Azure Bastion
Azure Bastion provides RDP and SSH to VMs over TLS through the portal or the native client, without public IPs on the VMs.
az network public-ip create -g rg-connectivity -n pip-bastion --sku Standard
az network bastion create -g rg-connectivity -n bas-hub \
--vnet-name vnet-hub --public-ip-address pip-bastion \
--sku Standard --enable-tunneling true
az network bastion ssh -g rg-connectivity -n bas-hub \
--target-resource-id <vm-resource-id> --auth-type AAD
AzureBastionSubnet must be /26 or larger. If you attach an NSG, it needs inbound 443 from Internet and GatewayManager, outbound to VirtualNetwork on 22 and 3389, and to AzureCloud on 443. The Premium SKU adds session recording and private-only deployment (no public IP on Bastion itself). Restrict who can connect: users need Reader on the Bastion, the VM and its NIC, plus Virtual Machine User Login or Administrator Login for Entra authentication. Send Bastion BastionAuditLogs to the workspace.
VNet flow logs
NSG flow logs are retiring: creation of new NSG flow logs is no longer supported, and the feature retires on September 30, 2027, after which Azure deletes the remaining NSG flow log resources. Use VNet flow logs through Network Watcher. They log at VNet, subnet or NIC level, include traffic evaluated by Virtual Network Manager admin rules, and record encryption status.
az network watcher flow-log create --location westeurope \
--resource-group rg-app1 --name fl-vnet-app1 --vnet vnet-app1 \
--storage-account <storage-account-id> \
--traffic-analytics true --workspace <workspace-id> --interval 10
az network watcher flow-log list --location westeurope -o table
At scale, assign Deploy VNet Flow Logs with Traffic Analytics for VNets with regional Storage and centralized Log Analytics or Configure virtual network to enable Flow Log and Traffic Analytics, and audit with Audit flow logs configuration for every virtual network. If you still have NSG flow logs, migrate them with Microsoft's migration script before the retirement date rather than after. Set retention on the storage account (lifecycle rules) to at least 90 days, longer if your investigations need it.
Logging and detection
- Flow data: VNet flow logs with Traffic Analytics populate
NTANetAnalyticsin the workspace. - Azure Firewall: structured logs (
AZFWNetworkRule,AZFWApplicationRule,AZFWThreatIntel,AZFWIdpsSignature,AZFWDnsQuery) through a diagnostic setting in resource-specific mode. - Activity log alerts on NSG and public IP create, update and delete (CIS list) as described on the Azure Monitor page.
- Defender for Cloud recommendations for open management ports and missing NSGs (see Defender for Cloud).
Internal hosts talking to many distinct external destinations suggest scanning or beaconing:
AZFWNetworkRule
| where TimeGenerated > ago(1d)
| where Action == "Allow"
| summarize Destinations = dcount(DestinationIp) by SourceIp
| where Destinations > 200
New NSG rules that open inbound access from anywhere:
AzureActivity
| where OperationNameValue =~ "MICROSOFT.NETWORK/NETWORKSECURITYGROUPS/SECURITYRULES/WRITE"
| where ActivityStatusValue == "Success"
| extend body = parse_json(tostring(parse_json(Properties).requestbody))
| extend src = tostring(body.properties.sourceAddressPrefix),
access = tostring(body.properties.access),
dir = tostring(body.properties.direction)
| where access == "Allow" and dir == "Inbound" and src in ("*", "0.0.0.0/0", "Internet", "Any")
| project TimeGenerated, Caller, CallerIpAddress, _ResourceId, src
Threat intelligence hits from the firewall deserve an immediate look:
AZFWThreatIntel
| where TimeGenerated > ago(1d)
| project TimeGenerated, SourceIp, DestinationIp, Fqdn, ThreatDescription, Action
Common mistakes
- "Temporary" RDP rule from Any. It stays for months and is found by scanners within minutes. Use Bastion or just-in-time access and a high-priority deny backstop.
- Private endpoint added, public access left on. The data store remains reachable from the internet with a leaked key.
- Private DNS zones created per spoke. Resolution breaks or, worse, silently falls back to the public endpoint.
- Relying on default outbound access. Implicit egress means no inspection and no log of where compromised workloads connect.
- Assuming new VNets are private everywhere. Templates pinned to older network API versions still create non-private subnets.
- Keeping NSG flow logs. They cannot be created anymore and stop working at retirement; plan the move to VNet flow logs now.
- Firewall logs not collected. Egress control without logs stops some attacks and leaves no trace of the ones it did not stop.
References
- Network security groups overview (Microsoft Learn)
- Default outbound access in Azure (Microsoft Learn)
- Virtual network flow logs overview (Microsoft Learn)
- NSG flow logs overview and retirement (Microsoft Learn)
- Azure Firewall Premium features (Microsoft Learn)
- Azure Private Endpoint DNS configuration (Microsoft Learn)
- Azure DDoS Protection overview (Microsoft Learn)
- What is Azure Bastion? (Microsoft Learn)
- Azure security baseline for Virtual Network (Microsoft Learn)
- T1133: External Remote Services (MITRE ATT&CK)
- CIS Microsoft Azure Foundations Benchmark (Center for Internet Security)
Filed under virtual-network, network-security, cis-benchmark
Written by
Florian Amette, Cloud Security Engineer & EditorSecurity engineer writing practical hardening pages for Microsoft Azure tenants and subscriptions, aligned with the CIS Microsoft Azure Foundations Benchmark.