Skip to main content

A Higher-Priority NSG Allow Rule Silently Overrides Subnet-Level Deny

High severityMicrosoft Azure About 20 minutes to fix

Overview

An NSG allow rule with a lower priority number sits in the same subnet NSG as a deny rule, is processed first and silently overrides it, exposing a workload despite an apparently correct subnet policy.

At a glance

Symptom
A workload behind a subnet with an explicit deny rule for inbound traffic on port 3389 remains reachable from the internet.
Likely cause
A broad allow rule in the subnet NSG, with a lower priority number than the intended deny rule, permits inbound RDP from any source.
Impact
The workload is reachable on RDP from any source IP address despite an apparently correct subnet-level deny policy, materially widening the network attack surface for brute-force and credential-stuffing…
Verification signal
Validation confirms the previously succeeding external connection is now refused and that legitimate maintenance access from the documented range still functions.
Safe correction
Correct the exposure by tightening the specific over-broad allow rule in the subnet NSG rather than removing NSG associations wholesale, since removing an NSG association can have wider…
Rollback or recovery
If the narrowed rule blocks required maintenance access that was not fully captured before the change, restore the previous source address prefix value on the same rule ID…

Symptom

A workload behind a subnet with an explicit deny rule for inbound traffic on port 3389 remains reachable from the internet. The platform team confirms the subnet NSG shows a deny rule, yet connection attempts from an external test host succeed, and Azure Network Watcher’s IP flow verify tool reports the traffic as allowed rather than denied.

False Assumption

The team treats the one NSG attached to the subnet as the only enforcement point, and expects a deny rule in that NSG’s rule list to block traffic to every network interface inside the subnet. But Azure evaluates NSGs independently at both the subnet and the network interface (NIC) level when both are assigned.

For inbound traffic it evaluates the subnet NSG first and then the NIC NSG, so traffic must be allowed by both. Priority numbers are compared only within a single NSG, so a deny rule is only effective if no lower-numbered allow rule in the same NSG matches the traffic first.

Root Cause

Alongside the visible deny rule at priority 400, the subnet NSG holds an allow rule at priority 200 for inbound TCP 3389 from a maintenance IP range. At some point that range was widened to Any during a troubleshooting session, and nobody put it back.

Within a single NSG, lower priority numbers are evaluated first and processing stops at the first match, so the allow rule at priority 200 matches before the deny rule at priority 400 is reached. The subnet NSG therefore allows the traffic, and any NIC-level NSG that also allows it does not change the outcome.

Impact

The workload is reachable on RDP from any source IP address even though the subnet-level deny policy looks correct, which leaves a management port open to brute-force and credential-stuffing attempts from anywhere.

Treating the subnet NSG as one authoritative choke point is not enough, because a broad allow rule with a lower priority number can sit in the same NSG as the deny rule.

That rule is easy to add during ad hoc troubleshooting and easy to miss in a later review, since the subnet NSG rule list still shows the intended deny rule unchanged.

Diagnosis

Find out what Azure actually enforces before changing anything. Start by listing every NSG associated with both the subnet and the specific NIC, because a NIC can have its own NSG in addition to, not instead of, the subnet NSG.

Then open Azure Network Watcher’s effective security rules view for the NIC, which shows the rules from the subnet NSG and the NIC NSG, each evaluated independently. Finally, run IP flow verify with the actual source IP, destination port and protocol under test to observe the matched rule name directly, rather than inferring behaviour from the rule list alone.

# Read-only: list NSGs associated with the subnet
az network vnet subnet show \
  --resource-group "rg-workload-prod" \
  --vnet-name "vnet-workload" \
  --name "snet-app" \
  --query "networkSecurityGroup.id" -o tsv

# Read-only: list the NSG associated directly with the NIC
az network nic show \
  --resource-group "rg-workload-prod" \
  --name "nic-vm-app01" \
  --query "networkSecurityGroup.id" -o tsv

# Read-only: list the rules in the subnet NSG, including priority, access and source
az network nsg rule list \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" -o table

# Read-only: view the effective security rules applied to the NIC
az network nic list-effective-nsg \
  --resource-group "rg-workload-prod" \
  --name "nic-vm-app01" -o json

# Read-only: verify actual flow disposition for the specific traffic under test
az network watcher test-ip-flow \
  --resource-group "rg-workload-prod" \
  --vm "vm-app01" \
  --direction Inbound \
  --protocol TCP \
  --local 10.20.1.5:3389 \
  --remote 203.0.113.10:51000

The IP flow verify result names the rule that determined the disposition. If an allow rule with a lower priority number than the intended deny rule appears as the match, that rule, not the deny rule, is governing the traffic.

Correction

Tighten the one over-broad allow rule in the subnet NSG. Don’t remove NSG associations wholesale: other traffic may already rely on an association, and removing it can have wider effects nobody intended. Narrow the source address prefix on the offending rule back to the documented maintenance range, or remove the rule entirely if no current business justification exists, and record the change against a specific rule ID and priority so the action is auditable.

# Read-only: record the current source scope first (needed for rollback)
az network nsg rule show \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" \
  --name "Allow-RDP-Maintenance" \
  --query "[sourceAddressPrefix, sourceAddressPrefixes]" -o json

# State-changing: narrow the over-broad allow rule to the documented maintenance range
az network nsg rule update \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" \
  --name "Allow-RDP-Maintenance" \
  --priority 200 \
  --source-address-prefixes "198.51.100.0/24" \
  --access Allow

If the maintenance range is undocumented, or the requesting team cannot confirm it within the change window, stop and do not guess a replacement range. Set the rule’s access to Deny as an interim containment step and escalate for the correct scope: a wrongly narrowed range can break legitimate maintenance access without anyone noticing, and still leave other exposure unexamined.

Validation

After the change, the external connection that used to succeed should be refused, and maintenance access from the documented range should still work. Re-run the IP flow verify command from the diagnosis step using the same external test source; the result must now report a deny disposition matching the subnet deny rule.

Separately, run IP flow verify with a source address inside the documented maintenance range to confirm that path still reports allow, so you know the correction has not blocked required access. Re-run the effective security rules listing to confirm the rule priority and scope shown match the intended, documented state.

Rollback

If the narrowed rule blocks required maintenance access that was not fully captured before the change, restore the previous source address prefix value on the same rule ID and priority rather than recreating the rule, since recreating it under a new priority can produce a different, unreviewed evaluation order.

# Rollback: restore prior source scope on the same rule if maintenance access breaks
az network nsg rule update \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" \
  --name "Allow-RDP-Maintenance" \
  --priority 200 \
  --source-address-prefixes "<PREVIOUS_SOURCE_PREFIX>" \
  --access Allow

Record the previous source-address-prefixes value before applying the correction so the rollback command above has a concrete value to restore; do not proceed with the correction if that prior value has not been captured.

Prevention

Treat subnet-level and NIC-level NSGs as two independent, sequential filters: inbound traffic must be allowed by both, and priority numbers are compared only within a single NSG.

Where practical, standardise on associating NSGs at the subnet level only and avoid NIC-level NSG associations unless a documented exception requires them, since one enforcement point per subnet removes this kind of hidden override.

Where NIC-level NSGs are required, require that any temporary widening made during troubleshooting carries an explicit expiry review, and check the effective security rules as well as the rule list for any change affecting network access controls.

Infrastructure as code can produce the same inversion: rules generated from a list usually receive incrementing priorities, so an emergency deny appended later lands below every existing allow. Reserve priority bands, for example 100 to 999 for denies and higher numbers for allows, and have the pipeline reject any rule outside its band.

3

Apply the safer control

Before you change production

Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.

Fix commands and configuration

# Read-only: list NSGs associated with the subnet
az network vnet subnet show \
  --resource-group "rg-workload-prod" \
  --vnet-name "vnet-workload" \
  --name "snet-app" \
  --query "networkSecurityGroup.id" -o tsv

# Read-only: list the NSG associated directly with the NIC
az network nic show \
  --resource-group "rg-workload-prod" \
  --name "nic-vm-app01" \
  --query "networkSecurityGroup.id" -o tsv

# Read-only: list the rules in the subnet NSG, including priority, access and source
az network nsg rule list \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" -o table

# Read-only: view the effective security rules applied to the NIC
az network nic list-effective-nsg \
  --resource-group "rg-workload-prod" \
  --name "nic-vm-app01" -o json

# Read-only: verify actual flow disposition for the specific traffic under test
az network watcher test-ip-flow \
  --resource-group "rg-workload-prod" \
  --vm "vm-app01" \
  --direction Inbound \
  --protocol TCP \
  --local 10.20.1.5:3389 \
  --remote 203.0.113.10:51000
# Read-only: record the current source scope first (needed for rollback)
az network nsg rule show \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" \
  --name "Allow-RDP-Maintenance" \
  --query "[sourceAddressPrefix, sourceAddressPrefixes]" -o json

# State-changing: narrow the over-broad allow rule to the documented maintenance range
az network nsg rule update \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" \
  --name "Allow-RDP-Maintenance" \
  --priority 200 \
  --source-address-prefixes "198.51.100.0/24" \
  --access Allow
# Rollback: restore prior source scope on the same rule if maintenance access breaks
az network nsg rule update \
  --resource-group "rg-workload-prod" \
  --nsg-name "<SUBNET_NSG_NAME>" \
  --name "Allow-RDP-Maintenance" \
  --priority 200 \
  --source-address-prefixes "<PREVIOUS_SOURCE_PREFIX>" \
  --access Allow
4

When to escalate

Validation and rollback are covered in the sections above.

Escalate

Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.

The KBY Brief

Fixed? Get the next one before it hits you: The KBY Brief

Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.

About this page

Credited to

Dates

Published

Last updated

Corrections

  • : Corrected during a review of published articles. Details
  • : Corrected during a review of published articles. Details
  • : Corrected during a review of published articles. Details

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

More from KBY that goes with this config trap.

Discover more

Connected KBY resources