Restricting VM network exposure: the basics
What does an over-exposed virtual machine actually look like?
A virtual machine becomes attack surface the moment one of its ports answers from the public internet, and the exposure shows up in a few distinct shapes rather than one setting. A management port can be open: RDP on 3389 or SSH on 22 reachable from any address, which is a standing invitation to credential brute force. An internet-facing VM can have no network security group at all, so nothing filters inbound traffic before it reaches the operating system. Or a VM can have a network security group that exists but is too permissive, with an inbound rule that allows a management port from 'Any' or 'Internet'. Each is its own Defender for Cloud recommendation, but the underlying risk is the same: a machine that more of the internet can reach than you meant.
Microsoft Defender for Cloud turns each of these into its own recommendation, which is why one VM-heavy subscription can fail several network checks at once. 'Management ports should be closed on your virtual machines' and 'Management ports of virtual machines should be protected with just-in-time network access control' are the two that close the widest doors on the management plane, and they pair with 'Internet-facing virtual machines should be protected with network security groups' to form a single capability. They read as separate problems on the report, but they are one job: stop machines being reachable on ports you did not mean to expose, and gate the management ports you do need behind access that opens on request and closes again.
Most of this exposure is drift, not intent. A VM spun up with the portal default that opens 3389 to the world for a quick login, a subnet that never had a network security group attached, a test rule that allowed SSH from anywhere and was never tightened. The work is to find every machine that is reachable more widely than intended, attach and tighten the network security groups that filter inbound traffic, and replace standing open management ports with just-in-time access so the port is shut by default and opened only for the minutes someone actually needs it.
In this lesson you will learn how Azure expresses virtual-machine network exposure, how to find every over-exposed machine in a subscription, and how to lock them down with network security groups and just-in-time access without losing the management access your team needs. The Controls this lesson covers section lists every Defender for Cloud recommendation in this capability, each linking to a deep page with the exact check and a copy-and-paste fix.
The port the whole internet is already knocking on
Point a fresh virtual machine at the internet with RDP open and you do not have to wait long for the first login attempt. Internet-wide scanners catalogue millions of open RDP and SSH endpoints, and automated brute-force tooling works through them constantly, which is why a VM with 3389 open to 'Any' typically starts seeing failed logins within minutes of going live. Just-in-time access flips the default: the management port stays shut, an authorised user requests access for a bounded window, often up to three hours, and Defender for Cloud opens a temporary, source-scoped rule that closes itself again when the window expires. The attacker scanning the internet finds a closed port the rest of the time.
Finding VM network exposure across a subscription
Sam is the security lead at a scale-up preparing for its first ISO 27001 audit. Defender for Cloud shows VM network findings spread across a dozen machines in two subscriptions that pre-date the team's current guardrails.
Rather than work the findings one by one, Sam starts by listing which network security group rules still allow a management port from the internet, so the genuinely exposed machines can be separated from drift before anything changes.
Start by listing the network security group rules that allow RDP or SSH from any internet source. These are the widest-open doors.
A rule that allows a management port from '*' or 'Internet' is the highest-value target in this group. Close these first, then put the ports you genuinely need behind just-in-time access.
How Defender for Cloud decides a virtual machine is over-exposeddeep dive
Most VM network recommendations resolve to the relationship between a machine's network interface, its subnet and the network security group rules that govern inbound traffic. A network security group is an ordered list of rules evaluated by priority; each rule matches on source, source port, destination, destination port and protocol, and either allows or denies. Defender for Cloud flags 'Management ports should be closed' when an effective inbound rule allows 3389, 22 or another management port from a broad source such as '*' or the 'Internet' service tag. It flags 'Internet-facing virtual machines should be protected with network security groups' when a VM it has identified as reachable from the internet has no network security group filtering its traffic at all.
Just-in-time access changes the steady state rather than the rule logic. When you enable it on a VM, Defender for Cloud ensures a deny rule covers the protected management ports, so they are closed by default. When an authorised user requests access, Defender for Cloud inserts a temporary, higher-priority allow rule scoped to that user's source address and the requested ports for a bounded time window, then removes it when the window expires. The recommendation 'Management ports should be protected with just-in-time network access control' clears once that protection is in place. Just-in-time access requires Microsoft Defender for Servers Plan 2 on the subscription.
Defender for Cloud evaluates these against the Microsoft Cloud Security Benchmark, mapping management-port closure and just-in-time access to control PA-2 (avoid standing access for user accounts and permissions), the benchmark control that ties the Defender for Cloud just-in-time VM access feature to restricting inbound traffic on management ports, and internet-facing network security group coverage to NS-1 (establish network segmentation boundaries). Assessment runs on a periodic cycle, so a fix does not flip the recommendation to Healthy instantly; the control-plane change is immediate, but the posture catches up on the next assessment. The strongest position combines the per-machine fix with an Azure Policy backstop that audits or denies VMs left without network security group protection or just-in-time control, so no machine can be created back into the open state unnoticed.
What is the impact of leaving virtual machines exposed?
The direct impact is compromise. A management port open to the internet is found within minutes by automated scanners and ground against by brute-force tooling until a weak or reused credential gives way. Once an attacker has a session on the VM, the machine becomes a foothold: its data is readable, its identity and any attached managed identity can be abused, and it becomes a launch point for lateral movement into the rest of the network. The overwhelming majority of these incidents start with an accident, a port that could be left open was left open by a portal default or a test rule nobody intended.
The second-order impact is blast radius. Every machine reachable on a management port, and every internet-facing machine with no network security group filtering its traffic, is attack surface that has to be defended continuously. Locking VM exposure down shrinks that surface to the handful of front doors you actually operate and the bounded windows in which management ports are open, which are the ones you can monitor, source-scope and time-box.
On the compliance side, every modern framework, ISO 27001, SOC 2, HIPAA, PCI DSS and the UK and EU data-protection regimes, expects evidence that management interfaces are not exposed to the internet and that internet-facing systems are segmented behind network controls. A passing set of VM network recommendations across every subscription, with just-in-time access in place for the management ports you do need, is the cheapest and most defensible artefact you can hand an auditor.
How do you lock virtual machine exposure down safely?
Work the capability as one loop rather than chasing individual findings. The order matters: identify the management access your team genuinely needs before you start closing things, so you do not lock yourself out of a machine you still have to administer.
1. Inventory every machine by exposure
List the network security group rules that allow a management port from '*' or 'Internet', the internet-facing machines with no network security group attached, and the machines whose management ports are not yet protected by just-in-time access. Treat this inventory as the source of truth, not the Defender finding count, because one machine can trigger several recommendations at once.
2. Attach a default-deny network security group to anything without one
Every internet-facing machine needs a network security group filtering its inbound traffic. Attach one to each machine or subnet that has none, allowing only the application ports the workload genuinely serves (for example 443 on a web server) and denying the rest. This closes the 'internet-facing VMs should be protected with network security groups' finding directly.
3. Close standing open management ports, highest impact first
Remove or tighten any rule that allows 3389, 22 or another management port from a broad source. Prioritise production machines and anything that can reach sensitive systems over isolated test boxes. Each change is a single rule update and takes effect immediately. Where the workload never needs inbound management access at all, leave the port denied entirely and use Azure Bastion or a private path instead.
4. Gate the management ports you do need behind just-in-time access
For the machines an operator still has to log in to, enable just-in-time network access control so the management port stays shut by default and opens only on an authorised, time-boxed, source-scoped request. Then assign an Azure Policy that audits or denies any VM left without network security group protection or just-in-time control, so the safe configuration is enforced rather than merely encouraged.
# 1. Close the highest-impact exposure first: delete any rule that
# allows a management port from the whole internet.
for rule in $(az network nsg rule list -g prod-rg --nsg-name prod-nsg \
--query "[?access=='Allow' && (sourceAddressPrefix=='*' || sourceAddressPrefix=='Internet') && (destinationPortRange=='3389' || destinationPortRange=='22')].name" -o tsv); do
az network nsg rule delete -g prod-rg --nsg-name prod-nsg -n "$rule"
echo "$rule: open management-port rule removed"
done
# 2. Add an explicit deny on the management ports as a backstop.
az network nsg rule create -g prod-rg --nsg-name prod-nsg \
--name deny-mgmt-ports --priority 4000 --access Deny --direction Inbound \
--protocol Tcp --source-address-prefixes Internet \
--destination-port-ranges 22 3389
# 3. Gate the ports you still need behind just-in-time access.
# JIT is configured via PowerShell or the portal; request access with the CLI:
az security jit-policy list -o table # confirm the JIT policy is in place
# 4. Ratchet it shut: audit any VM left without an NSG (Defender built-in policy).
az policy assignment create \
--name audit-internet-facing-nsg \
--policy f6de0be7-9a8a-4b8a-b349-43cf02d22f7c \
--scope "/subscriptions/00000000-0000-0000-0000-000000000000" Quick quiz
Question 1 of 5Defender for Cloud shows VM network findings across open management ports, missing network security groups and just-in-time access on several machines. What is the most efficient way to think about them?
You scored
0 / 5
Keep learning
Go deeper on how Azure filters virtual-machine traffic and how just-in-time access gates the management ports in this capability.
- Understand just-in-time virtual machine access How Defender for Cloud keeps management ports closed and opens them only on a time-boxed request.
- Enable just-in-time access on VMs How to turn on just-in-time access and what Defender for Servers plan it needs.
- Network security groups overview How network security group rules filter inbound traffic to your virtual machines.
You can now treat virtual-machine network exposure as one capability rather than a scatter of findings: inventory what is reachable too widely, attach a network security group to every internet-facing machine, close standing open management ports highest-impact first, gate the ports you genuinely need behind just-in-time access, and ratchet the estate shut with an Azure Policy backstop. The Controls this lesson covers section below links every recommendation in this group to its deep page and fix.
Back to the library