An Azure virtual machine can be fully patched and still be taken over by anyone who holds a control-plane role that lets them push an extension or a Run Command into it. Securing Azure VMs means working on two planes at once: the Azure Resource Manager plane, where roles decide who can change disks, extensions and network rules, and the guest operating system, where local accounts, agents and patches live. This guide covers the VM-specific controls: disk encryption options and the move away from Azure Disk Encryption, Trusted Launch, just-in-time (JIT) management port access, the extension and Run Command attack path, serial console, patching with Azure Update Manager, and logging. It is written for Azure platform engineers, cloud security architects and server owners. For brokered RDP and SSH without public IPs, see the Azure Bastion guide; for machines outside Azure managed through Azure Arc, see the Azure Arc Security Guide.
This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft. Product features change, so confirm settings against Microsoft's current documentation.
Key takeaways
- Virtual Machine Contributor is a code execution role. Microsoft describes it as able to "install and run software" and reset the root password through VM extensions; its
Microsoft.Compute/virtualMachines/*action covers executing scripts on VMs. Treat it as equivalent to local administrator on every VM in scope. - Plan the Azure Disk Encryption migration now. Microsoft has scheduled Azure Disk Encryption (ADE) for retirement on 15 September 2028, after which ADE-encrypted disks fail to unlock on reboot. Encryption at host is the documented replacement for new VMs.
- Keep Trusted Launch on and finish the set. Secure Boot, vTPM and the Guest Attestation extension together give boot integrity monitoring and the Defender for Cloud attestation failure alert. Trusted Launch is the default for new Generation 2 VMs created in the portal, CLI and PowerShell.
- Close management ports by default. JIT VM access (Defender for Servers Plan 2) keeps deny rules on ports such as 22 and 3389 and opens them only for an approved source IP and time window; Azure Bastion removes the need for public IPs altogether.
- Logs from inside the VM need an agent. Activity Log records control-plane operations, but guest OS events need the Azure Monitor agent and a data collection rule. Alert on extension writes and Run Command operations as privileged actions.
The two planes of an Azure VM
Many VM compromises start not with a guest exploit but with an identity that already holds rights on the resource, such as a pipeline service principal with Contributor on a subscription. Separate the two planes in your design and your access reviews.
| Plane | What controls it | Main risks | Primary controls |
|---|---|---|---|
| Azure control plane (ARM) | Azure RBAC role assignments, Azure Policy, resource locks | Extension or Run Command execution, disk snapshot and export, NSG changes, password reset through the VMAccess extension | Least-privilege roles, Privileged Identity Management, policy deny effects, Activity Log alerts |
| Guest OS (data plane) | Local accounts, Microsoft Entra ID login roles, SSH keys, OS firewall | Brute force on exposed RDP or SSH, stale local admin passwords, unpatched services | JIT or Bastion, Entra ID login, disabling local accounts where possible, patching, EDR |
| Platform and boot | Trusted Launch, encryption settings, VM size and image | Bootkits and unsigned drivers, unencrypted temp disks and caches | Secure Boot, vTPM, Guest Attestation, encryption at host, Azure Compute Gallery images |
Microsoft's own security baseline for VMs recommends Microsoft Entra ID as the default authentication method for data plane access, says local accounts should be disabled wherever possible, and recommends managed identities over service principals for workloads running on the VM. Managed identity tokens are fetched from the Instance Metadata Service inside the VM, so anyone with code execution on the VM can use that identity: see the Azure Managed Identities Security Guide for scoping those roles.
Roles and the extension attack path
VM extensions are small applications the Azure platform installs and runs inside the VM after deployment, managed entirely from the control plane: Microsoft notes you do not need to connect to the VM to install or remove one. The Azure VM Agent that runs them needs to run as Local System on Windows, and the action form of Run Command executes as the system account on Windows or root on Linux. Anyone who can write an extension or invoke Run Command can therefore run code with full privileges on the guest, without a network path to it and without guest credentials. MITRE ATT&CK tracks this behaviour as T1651 Cloud Administration Command.
| Built-in role | What Microsoft documents | Effective guest impact | Recommended handling |
|---|---|---|---|
| Owner, Contributor | Full management of resources in scope | Code execution on every VM in scope through extensions and Run Command | Eligible only through PIM; never standing for automation at subscription scope |
| Virtual Machine Contributor | Create and manage VMs, manage disks, install and run software, reset the root password and manage local users through VM extensions; no login data actions | Code execution as SYSTEM or root, local credential reset | Treat as privileged; scope to a resource group per workload; eligible through PIM |
| Virtual Machine Administrator Login | View VMs in the portal and log in as administrator | Interactive admin sign-in with Entra ID | Eligible only; pair with Conditional Access |
| Virtual Machine User Login | View VMs in the portal and log in as a regular user | Interactive non-admin sign-in with Entra ID | Default for operators who need to sign in |
| Virtual Machine Data Access Administrator (preview) | Add or remove assignments of the two login roles, with an ABAC condition | Delegated control over who can sign in | Use to delegate login management without granting Owner or User Access Administrator |
| Data Operator for Managed Disks | Upload, read or export data of managed disks not attached to running VMs, and snapshots, via SAS URIs and Entra ID | Offline copy of disk contents | Assign narrowly; monitor disk export and SAS generation |
Control which extensions can run: the built-in Azure Policy "Only approved VM extensions should be installed" (category Compute) takes a list of approved extensions and supports Audit, Deny and Disabled effects, with Audit as the default.
Keep secrets out of extension settings: Microsoft documents a protectedSettings block that encrypts data and decrypts it only inside the target VM, while values under settings, including a Custom Script Extension commandToExecute, are not encrypted and are readable by anyone who can read the resource. Better still, have the script fetch secrets from Key Vault with the VM's managed identity; see the Azure Key Vault Security Guide.
Know the two Run Command types: action Run Command is a POST action for one-off tasks with a 90 minute limit and runs as the system account or root; managed Run Command is an ARM resource type, supports sequencing and recurring execution, and runs as a user you specify, with up to 25 per VM. Include managed Run Command resources in configuration reviews.
Disk encryption: choosing an option
Azure managed disks are always encrypted at rest by server-side encryption (SSE) with platform-managed keys. The choices are whether to cover temp disks, caches and data in flight, and who holds the key.
| Option | Covers | Key control | When to choose it |
|---|---|---|---|
| Server-side encryption (SSE) | OS and data disks at rest on storage clusters; not temp disks or caches | Platform-managed keys, or customer-managed keys through a disk encryption set (DES) | Always on; add a DES with customer-managed keys where regulation requires key control |
| Encryption at host | Extends SSE to temp disks and disk caches at rest and encrypts data flows to storage | Platform-managed or customer-managed via DES (temp disk with platform-managed keys only) | Default choice for new VMs; documented replacement for ADE; no guest CPU cost |
| Confidential disk encryption | OS disk, with keys bound to the VM's TPM and released through attested code; temp disk by opt-in | Customer-managed via DES, Key Vault Premium or Managed HSM | Confidential workloads on confidential VM sizes where the host operator must be excluded |
| Azure Disk Encryption (ADE) | OS and data disks inside the guest with BitLocker or DM-Crypt | Key Vault, optional key encryption key | Existing estates only; migrate before the retirement date |
ADE retirement: Microsoft states that ADE is scheduled for retirement on 15 September 2028. Workloads keep running on that date, but encrypted disks fail to unlock after a reboot, and Microsoft says all ADE-enabled VMs, including backups, must move to encryption at host before then. Inventory ADE-enabled VMs now and include restore points: a backup restored after the date inherits the problem. See the Azure Backup and Recovery Services Vault Security Guide for vault-side protections.
Decision guidance: most organisations need SSE plus encryption at host with platform-managed keys. Add customer-managed keys only when a regulator, contract or internal policy requires key ownership, because it brings key rotation, availability and revocation duties: losing access to the Key Vault key makes the disks unusable.
Trusted Launch and boot integrity
Trusted Launch protects Generation 2 VMs against bootkits, rootkits and kernel-level malware (ATT&CK T1542.003 Bootkit). Microsoft documents four layers that can be enabled independently: Secure Boot (only signed boot loaders, kernels and drivers run), a vTPM 2.0 that measures the boot chain, boot integrity monitoring through remote attestation, and virtualisation-based security for HVCI and Credential Guard on Windows.
- Defaults: Trusted Launch is the default for new Generation 2 VMs and scale sets created in the portal, CLI and PowerShell. ARM, Bicep and Terraform deployments need the
TrustedLaunchByDefaultPreviewfeature registered, or setsecurityProfile.securityTypetoTrustedLaunchwithsecureBootEnabledandvTpmEnabledset to true explicitly. Set it explicitly in templates so the outcome does not depend on feature registration. - Existing VMs: Microsoft documents that Generation 1 VMs can be upgraded to Generation 2 with Trusted Launch, and existing Generation 2 VMs and scale sets can have it enabled after creation. Test on a clone first.
- Sizes and images: some families, including A, Dv2, Dv3 and most M-series sizes, do not support Generation 2; Managed Image is replaced by Azure Compute Gallery for Trusted Launch. On Linux, GRID GPU drivers need Secure Boot disabled, so isolate those VMs and document the exception.
- Complete the attestation chain: Defender for Cloud raises low-severity recommendations to enable Secure Boot, enable vTPM and install the Guest Attestation extension. With all three in place it assesses attestation health and raises a medium-severity VM attestation failure alert when the boot log deviates from a trusted baseline, plus a low-severity alert when an untrusted Linux kernel module is blocked.
Management access: JIT, Bastion and serial console
Exposed RDP (T1021.001) and SSH (T1021.004) remain the most common way into cloud VMs from the internet. Pick one controlled path per environment and remove the rest.
| Approach | How it works | Fits | Watch for |
|---|---|---|---|
| Azure Bastion | Managed broker in the virtual network; no public IP on the VM | Production and any VM without a business need for public exposure | Who holds the Reader roles and shareable links; covered in the Bastion guide |
| JIT VM access | Defender for Cloud keeps deny rules in the NSG and Azure Firewall (Rules Classic) and opens the port for an approved source IP and time | VMs that must keep a public IP or a firewall path; break-glass access | Default source is Any when enabled from the VM blade; restrict it to known ranges |
| Serial console | Text console through the portal over TLS 1.2 or later | Recovery when networking or boot fails | Enabled by default for subscriptions; needs Virtual Machine Contributor or higher; commands and output land in boot diagnostics logs |
JIT details: JIT is part of Defender for Servers Plan 2. When enabled from the VM configuration page, the defaults are port 3389 for Windows and 22 for Linux, a 3 hour maximum request window and allowed source IPs of Any; Defender for Cloud also recommends 5985 and 5986 for WinRM. Requesting access needs Microsoft.Security/locations/jitNetworkAccessPolicies/initiate/action plus read actions, while editing the policy needs jitNetworkAccessPolicies/write and Microsoft.Compute/virtualMachines/write, so separate requesters from policy editors. JIT does not cover VMs behind an Azure Firewall managed by Firewall Manager policies.
Serial console: commands and output, including any secrets typed, are written to boot diagnostics logs, so disable it at subscription level where it is not needed and restrict read access to boot diagnostics storage where it stays on.
Patching, images and endpoint protection
- Azure Update Manager: assesses and installs updates for Windows and Linux on Azure VMs and Arc-connected machines, with periodic assessment every 24 hours, customer-defined maintenance windows, dynamic scoping and hotpatching for critical updates without a restart on supported images. Turn on periodic assessment by Azure Policy so every new VM reports compliance from day one.
- Automatic guest patching: applies Critical and Security updates automatically; Microsoft's baseline notes it is not enabled by default. Use it for stateless or scale-set tiers, and scheduled maintenance windows for stateful servers.
- Golden images: build hardened images in Azure Compute Gallery and rebuild on a schedule.
- EDR and anti-malware: Defender for Servers integrates with Microsoft Defender for Endpoint for EDR; Microsoft Defender Antivirus is installed by default on Windows Server 2016 and later. Defender for Servers is not enabled by default, so assign it by policy at management group scope.
- Vendor updates: apply Microsoft security updates for the VM Agent and extensions promptly; Microsoft notes you cannot opt out of extension hotfix updates that carry security fixes, and recommends keeping
autoUpgradeMinorVersionenabled.
Implementation roadmap
- Inventory (week 1): list VMs with public IPs, VMs with Secure Boot or vTPM off, ADE-enabled VMs and their backups, deployed extensions and managed Run Commands, and every principal holding Owner, Contributor or Virtual Machine Contributor over VM scopes.
- Reduce standing privilege (weeks 2 to 4): move human Contributor and Virtual Machine Contributor assignments to PIM eligibility; scope pipeline identities to the resource groups they deploy; give operators Virtual Machine User Login instead of management roles. See the Privileged Identity Management (PIM) Guide.
- Audit-mode policies (weeks 2 to 6): assign "Only approved VM extensions should be installed" in Audit, plus policies for periodic update assessment and Defender for Servers, and review compliance before changing effects. The Azure Policy and Management Groups Guide covers assignment scope and exemptions.
- Close management ports (weeks 4 to 8): deploy Bastion in hub networks, enable JIT for VMs that keep a public path, restrict JIT source ranges, and disable serial console where not needed.
- Encryption and boot (weeks 6 to 16): enable encryption at host on new builds through templates; pilot ADE-to-encryption-at-host migration on a non-production ring with a tested restore; enable Trusted Launch and Guest Attestation on supported VMs.
- Enforce (after a clean audit period): switch the extension policy to Deny at management group scope, keep a documented exemption process, and set Trusted Launch explicitly in every template.
- Rollback: every Deny assignment has a named owner who can flip it back to Audit; every disk migration keeps a verified backup until the VM has rebooted cleanly on the new configuration.
Small and large estates: a team with a few dozen VMs can enforce most of this in one subscription in a quarter, with Bastion replacing JIT entirely. Large estates should drive it from management group policy and run the ADE migration as a tracked programme; see the Azure Landing Zones Security Guide.
Logging, detection and metrics
| Signal | Source | Why it matters |
|---|---|---|
| Extension write or delete on a VM | Activity Log (Microsoft.Compute/virtualMachines/extensions/write) | Code execution path into the guest; unexpected publishers or Custom Script Extension use outside pipelines |
| Run Command invocation | Activity Log (Microsoft.Compute/virtualMachines/runCommand/action) and managed Run Command resource changes | Direct SYSTEM or root execution by a control-plane identity |
| Disk export, SAS generation or snapshot creation | Activity Log on disks and snapshots | Offline copy of data that bypasses guest controls |
| JIT request and NSG rule changes | Activity Log, JIT Activity Log view (exportable to CSV) | Who opened which port, from where, for how long |
| VM attestation failure, untrusted kernel module | Defender for Cloud alerts | Boot chain tampering or unexpected drivers |
| Guest sign-ins, process and service creation | Azure Monitor agent with a data collection rule, Defender for Endpoint | Activity after access, which control-plane logs do not show |
Alert on the first three rows when the caller is not a known deployment identity. The Azure Monitor, Activity Log and Diagnostic Settings Guide covers export and retention.
Metrics that show progress:
- Percentage of VMs with no public IP on management ports, or covered by JIT.
- Percentage of supported VMs with Secure Boot, vTPM and Guest Attestation all enabled.
- Count of ADE-enabled VMs and restore points remaining, trending to zero before September 2028.
- Number of standing (non-PIM) assignments of Owner, Contributor or Virtual Machine Contributor over VM scopes.
- Extension and Run Command operations by non-pipeline identities per month, each with a ticket reference.
Common failure patterns
- Treating Virtual Machine Contributor as low risk: the role is handed to helpdesk or monitoring teams because it "cannot log in", yet it can run scripts as SYSTEM and reset local passwords through extensions.
- Secrets in plain extension settings: passwords placed in
settings.commandToExecuterather thanprotectedSettings, readable by any principal with read access to the VM resource and visible in deployment history. - JIT with source Any: JIT enabled from the VM blade with default allowed source IPs, which opens the port to the internet for three hours on each request.
- Half-finished Trusted Launch: Secure Boot and vTPM on but no Guest Attestation extension, so boot integrity monitoring and attestation alerts never fire.
- ADE migration that forgets backups: live VMs moved to encryption at host while old restore points remain ADE-encrypted and fail to unlock after the retirement date.
Framework mapping
| Control area | NIST SP 800-53 Rev 5 | NIST CSF 2.0 | ISO/IEC 27001:2022 Annex A | MITRE ATT&CK |
|---|---|---|---|---|
| Control-plane least privilege, extension and Run Command governance | AC-6, CM-7 | PR.AA-05 | A.8.2 Privileged access rights | T1651, T1078.004 |
| Disk encryption and key management | SC-28 | PR.DS-01 | A.8.24 Use of cryptography | |
| Trusted Launch and boot integrity | SI-7 | PR.PS-01 | A.8.9 Configuration management | T1542.003 |
| Management port access (JIT, Bastion) | AC-17 | PR.AA-05 | A.8.20 Networks security | T1021.001, T1021.004 |
| Patching and images | SI-2, SA-22 | PR.PS-02 | A.8.8 Management of technical vulnerabilities | |
| Logging and detection | AU-12 | DE.CM-09 | A.8.15 Logging, A.8.16 Monitoring activities | T1552.005 |
CIS Controls v8.1 safeguards that apply directly include 3.11 (encrypt sensitive data at rest), 4.1 (secure configuration process), 5.4 (restrict administrator privileges to dedicated accounts), 7.3 (automated operating system patch management) and 8.2 (collect audit logs).
Practitioner checklist
- Every Owner, Contributor and Virtual Machine Contributor assignment over VM scopes is PIM-eligible or a scoped workload identity, and reviewed quarterly.
- "Only approved VM extensions should be installed" is assigned, moving from Audit to Deny after review.
- No secrets in extension
settings; scripts read secrets from Key Vault with a managed identity. - New VMs use encryption at host through templates; ADE-enabled VMs and restore points have a migration date before 15 September 2028.
- Templates set
securityTypetoTrustedLaunchwith Secure Boot and vTPM enabled, and Guest Attestation is installed. - No management ports open to the internet: Bastion or JIT with restricted source ranges only.
- Serial console disabled where not needed; boot diagnostics storage access restricted.
- Periodic update assessment and Defender for Servers assigned by policy at management group scope.
- Alerts exist for extension writes, Run Command, disk export and JIT requests by unexpected identities.
- Azure Monitor agent and a data collection rule collect guest security events.
Standards and references
- Microsoft Learn: Overview of managed disk encryption options
- Microsoft Learn: Trusted Launch for Azure virtual machines
- Microsoft Learn: Enable just-in-time access on VMs
- Microsoft Learn: Virtual machine extensions and features for Windows
- Microsoft Learn: Run scripts in your VM by using Run Command
- Microsoft Learn: Azure built-in roles for Compute
- Microsoft Learn: Security recommendations for virtual machines in Azure
- MITRE ATT&CK: T1651 Cloud Administration Command
Related NHI Mgmt Group resources: Azure Bastion, Azure Arc Security Guide, Azure Managed Identities Security Guide, Azure RBAC and Service Principals Guide, Azure Security Checklist.