Enabling Just-in-Time VM Access
This lesson explains how just-in-time access works, what it needs, and how to enforce it.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how JIT reduces exposure.
- Describe the request mechanism.
- Identify the required permissions.
- Describe how to enforce JIT at scale.
How JIT reduces exposure
Administrators need management ports for a small fraction of the time, yet those ports are often open constantly. Just-in-time VM access keeps them closed, and opens them on request, for a limited time and from a limited source. This applies the idea of Privileged Identity Management to a network port. Even if a port must be reachable, its exposure drops from all day to a few hours in a month.
JIT needs Defender for Servers Plan 2, and the VM must be protected by an NSG, an Azure Firewall or both. It supports Azure Resource Manager VMs, VMs protected by an Azure Firewall on the same virtual network, and AWS EC2 instances in preview. It does not support classic VMs, or VMs protected by firewalls that Azure Firewall Manager controls.
JIT requirements
How the mechanism works
Enabling JIT on a VM creates a policy that lists its ports, and adds deny rules to the NSG, or Azure Firewall rules, for those ports. Nothing is reachable through them. When a user makes a request, Defender for Cloud checks that the user holds the right permission, and then adds an allow rule for that user's source address, at a higher priority than the deny rule. When the time ends, the allow rule is removed.
-
Configure
An administrator enables JIT for a VM and sets ports, the maximum time and the allowed sources.
-
Request
A user asks for access, stating the port, source address and duration.
-
Check
Defender for Cloud verifies the user's Azure permissions.
-
Open
An allow rule is added, and the event is recorded in the activity log.
-
Close
The allow rule is removed when the time expires.
The recommended ports in the Defender interface are 22 for SSH, 3389 for RDP, and 5985 and 5986 for WinRM. When enabling it from the VM's page, the defaults are 3389 on Windows and 22 on Linux, a maximum of three hours, and a source of Any. A stricter source should be set where possible. The name of the policy plus the VM name must not exceed 56 characters.
The following diagram shows the JIT steps and the NSG rules they create.

A JIT request
Permissions
Separate permissions apply to configuring and requesting, which allows tight control. Viewing needs Reader or Security Reader. Configuring needs Microsoft.Security/locations/jitNetworkAccessPolicies/write and Microsoft.Compute/virtualMachines/write. Requesting needs Microsoft.Security/locations/jitNetworkAccessPolicies/initiate/action and related reads.
Built-in roles such as Contributor include these rights, but a custom role can allow an operator only to request access, without changing the VM. This is a good example of a narrow custom role that is worth maintaining. JIT itself has no separate approval workflow, so a person with the permission receives access automatically. If approval is needed, restrict the permission, and grant it through PIM.
JIT permissions
Enforcing use at scale
JIT protects only the VMs that it covers. To enforce it, follow the Defender for Cloud recommendation Management ports of virtual machines should be protected with just-in-time network access control, which lists unprotected VMs and offers a fix. Azure Policy can audit VMs with management ports open. Requests are logged, and they can be examined in the activity log, or downloaded as CSV from the JIT page.
PowerShell can apply policies in bulk. Set-AzJitNetworkAccessPolicy configures a policy, and Start-AzJitNetworkAccessPolicy makes a request, with a time expressed like PT3H.
A request fails
An operator should be able to open RDP on production VMs for short periods, but not change VM settings. The company has Defender for Servers Plan 1. The security team also wants ports to be closed at all other times. What must be in place?
JIT needs Defender for Servers Plan 2, so upgrade the plan. Enable JIT on the VMs with port 3389 and a suitable maximum time. Create a custom role that includes jitNetworkAccessPolicies/initiate/action and the needed reads, and assign it to the operator.
Giving the operator Contributor would allow changes to the VMs. A manual NSG rule added by a person would be slow and easy to leave open. Azure Bastion alone would give a safe path, but it would not fulfil the requirement to open and close access on demand.
Who approves a JIT request?
Show answer
No one. Anyone with the permission receives access, so restrict who holds it.
Exam Tips
Remember for the exam
- JIT needs Defender for Servers Plan 2, plus an NSG or Azure Firewall.
- JIT has no approval workflow of its own.
- A custom role can allow requesting without allowing VM changes.
- Firewall Manager-controlled firewalls are not supported.