AZ-500Chapter 5 of 103Objective 2.1

Azure VM Security

This chapter covers Azure VM security, a critical topic for the AZ-500 exam, typically representing 15-20% of questions in the Compute Security domain. You will learn how to secure virtual machines at the OS, network, and disk levels using Azure-native controls like just-in-time access, disk encryption, and Azure Bastion. Mastery of these concepts is essential for implementing defense-in-depth strategies and passing the exam.

25 min read
Intermediate
Updated May 31, 2026

VM Security as a Fortified Embassy

Think of an Azure VM as a sovereign embassy in a foreign country. The embassy building (the VM) is protected by multiple layers: a perimeter fence (Network Security Groups), a guard at the door (Azure Firewall), and internal security cameras (Azure Monitor). The ambassador (the application) resides inside, and only authorized personnel (RBAC roles) can enter specific rooms. Just as an embassy has a secure vault (Azure Disk Encryption) for classified documents, the VM uses BitLocker or DM-Crypt to encrypt its disks. The embassy also has a policy that all visitors must present identification (Azure AD authentication) and be logged (diagnostic logs). If an intruder breaches the fence, the guards (just-in-time VM access) can lock down the building and alert the host country (Azure Security Center). This layered defense ensures that even if one layer fails, others still protect the sovereign asset.

How It Actually Works

Azure VM Security Overview

Azure Virtual Machines (VMs) are IaaS compute resources that run in a virtualized environment. Securing them requires a multi-layered approach covering network access, identity and access management, OS configuration, data protection, and monitoring. The AZ-500 exam tests your ability to implement and manage these controls.

Network Security Groups (NSGs)

NSGs filter traffic to and from Azure VMs at the subnet or NIC level. Each NSG contains a set of security rules that are evaluated in priority order (from 100 to 4096). Each rule specifies source/destination IP, port, protocol (TCP/UDP/Any), and action (Allow/Deny). By default, inbound traffic is denied, and outbound traffic is allowed. NSGs are stateful: if you allow inbound traffic on port 443, the return traffic is automatically allowed regardless of outbound rules. However, this statefulness does not apply to outbound rules—you must explicitly allow return traffic.

Example rule to allow RDP from a specific IP:

$nsg = Get-AzNetworkSecurityGroup -Name "myNSG" -ResourceGroupName "myRG"
$nsg | Add-AzNetworkSecurityRuleConfig -Name "AllowRDP" -Access Allow -Protocol Tcp -Direction Inbound -Priority 1000 -SourceAddressPrefix "203.0.113.0/24" -SourcePortRange "*" -DestinationAddressPrefix "*" -DestinationPortRange 3389
$nsg | Set-AzNetworkSecurityGroup

Common exam trap: NSGs do not replace firewalls—they are layer 4 filters. Application-level filtering requires Azure Firewall or a WAF.

Azure Bastion

Azure Bastion provides secure RDP/SSH connectivity to VMs over SSL, eliminating public IP exposure. It deploys as a PaaS service inside your virtual network (VNet) and connects to VMs via private IPs. Bastion uses the HTML5 client, so no additional software is needed. It supports both Azure AD authentication and local credentials. Key limitations: Bastion cannot be used to connect to on-premises VMs or VMs in peered VNets unless the VNet is in the same region and the Bastion is deployed in the spoke VNet.

Deployment example:

az network bastion create --name "myBastion" --public-ip-address "myBastionIP" --resource-group "myRG" --vnet-name "myVNet" --location "eastus"

Just-in-Time (JIT) VM Access

JIT reduces attack surface by locking inbound traffic to VMs except when users request access via Azure Security Center or Azure Policy. When a request is approved (via RBAC), NSG rules are temporarily created to allow traffic to specific ports (e.g., 3389, 22) for a defined duration (default 3 hours, max 24 hours). After the duration, rules are removed. JIT works with both NSGs and Azure Firewall. It requires Microsoft Defender for Cloud (formerly ASC) enabled on the subscription.

Configuration via Azure CLI:

az security jit-policy create --resource-group "myRG" --location "eastus" --name "myJITPolicy" --vm "myVM" --ports "3389=3h"

Trap: JIT does not protect against attacks that use already-authorized access (e.g., compromised credentials). It only reduces the window of exposure.

Azure Disk Encryption (ADE)

ADE uses BitLocker (Windows) or DM-Crypt (Linux) to encrypt OS and data disks at rest. It integrates with Azure Key Vault to manage encryption keys and secrets. Encryption is performed at the hypervisor level, meaning the VM host encrypts data before writing to Azure Storage. ADE requires the VM to be deallocated for the initial encryption (for Windows) or can be done while running (Linux). Key vault must have 'Soft Delete' and 'Purge Protection' enabled.

Enable ADE:

az vm encryption enable --resource-group "myRG" --name "myVM" --disk-encryption-keyvault "myVault" --volume-type "ALL"

Common exam point: ADE does not encrypt temporary disks; those are encrypted at the host level by Azure Storage Service Encryption (SSE).

Azure Policy for VM Security

Azure Policy can enforce compliance by applying built-in or custom policies. Key policies for VM security include:

Allowed locations (restrict VM deployment to compliant regions)

Audit VMs that do not use managed disks

Audit VMs without JIT enabled

Audit VMs without disk encryption

Enforce the latest OS patches

Example custom policy to require a specific tag:

{
  "if": {
    "allOf": [
      {
        "field": "type",
        "equals": "Microsoft.Compute/virtualMachines"
      },
      {
        "field": "tags.environment",
        "exists": "false"
      }
    ]
  },
  "then": {
    "effect": "deny"
  }
}

Azure Update Management

Update Management in Azure Automation ensures VMs are patched with the latest security updates. It uses the Azure Update Management solution (part of Azure Monitor Logs) and requires a Log Analytics workspace and a Hybrid Runbook Worker. You can schedule updates, define maintenance windows, and get compliance reports. For Azure VMs, you can also use Azure Automanage for automatic updates.

Azure Backup for VMs

Azure Backup provides backup and restore capabilities for VMs. It uses the Backup extension, stores data in a Recovery Services vault, and supports application-consistent backups (using VSS for Windows). Backup frequency can be daily or weekly, with retention up to 99 years. Encryption is at rest using platform-managed keys (PMK) or customer-managed keys (CMK).

Identity and Access Management (IAM) for VMs

RBAC roles control who can manage VMs (e.g., Virtual Machine Contributor, VM Operator). Azure AD authentication can be used for RDP/SSH access (via Azure AD join or Azure AD Domain Services). For Linux, SSH key authentication is recommended over passwords. Managed identities allow VMs to access other Azure resources securely without storing credentials.

Monitoring and Threat Detection

Azure Monitor collects metrics and logs from VMs. The Azure Monitor Agent (AMA) replaces the legacy Log Analytics agent. Security alerts from Microsoft Defender for Cloud detect threats like brute force attacks, malware, and suspicious processes. Enable Defender for Cloud's 'Servers' plan for full coverage. Network Watcher provides packet capture and NSG flow logs.

Secure Boot and vTPM (Generation 2 VMs)

Generation 2 VMs support Secure Boot and virtual Trusted Platform Module (vTPM). Secure Boot ensures only signed OS kernels are loaded, preventing bootkits. vTPM provides hardware-based key storage for encryption and attestation. These features are enabled by default for Gen2 VMs.

Host Encryption and Confidential Computing

Azure offers host-level encryption (encryption of VM data at the hypervisor) and confidential computing (encryption in use using Intel SGX or AMD SEV-SNP). Confidential computing protects data even from the host OS. These are advanced topics that appear less frequently but are tested in the 'Compute Security' domain.

Summary of Key Defaults and Limits

NSG rule priority range: 100-4096

JIT default max duration: 3 hours (configurable up to 24)

ADE requires Key Vault with Soft Delete and Purge Protection

Azure Bastion supports up to 25 concurrent RDP sessions per VM (limit may vary)

Backup retention: up to 99 years

Generation 2 VMs required for Secure Boot and vTPM

Walk-Through

1

Design NSG rules

Identify required inbound and outbound traffic. Create NSG rules with appropriate priorities (100-4096). For example, allow RDP from a management subnet (priority 1000) and deny all other inbound (default). Associate NSG to subnet or NIC. Use application security groups (ASGs) to group VMs by application tier and apply rules based on ASG tags.

2

Deploy Azure Bastion

Create a Bastion subnet (AzureBastionSubnet) with a /27 or larger prefix. Deploy Bastion with a public IP. Ensure the VNet has the Bastion subnet and VMs are in the same or peered VNet (same region). Configure RBAC to grant users 'Reader' access to Bastion and 'Virtual Machine Administrator Login' or 'Virtual Machine User Login' for RDP/SSH.

3

Enable JIT VM Access

In Microsoft Defender for Cloud, enable JIT on VMs. Configure approved ports (e.g., 3389, 22) and requestor roles. When a user requests access, Defender for Cloud creates temporary NSG rules with source IP of the user. After the set duration (default 3 hours), rules are removed. Monitor JIT requests in activity logs.

4

Encrypt VM disks

Create an Azure Key Vault with Soft Delete and Purge Protection enabled. Grant the Azure Disk Encryption service principal access to the vault. Run `az vm encryption enable` for each VM. For Windows, the VM may need to be deallocated. Verify encryption status with `az vm encryption show`. Ensure backup vaults are in the same region.

5

Apply Azure Policy

Assign built-in policies like 'Audit VMs without disk encryption' at the subscription or management group level. Create custom policies for specific requirements (e.g., require a specific tag). Use policy initiatives (policy sets) to group related policies. Remediate non-compliant resources using remediation tasks.

What This Looks Like on the Job

Enterprise Scenario 1: Financial Services Company A financial firm must comply with PCI-DSS, which requires encryption of cardholder data at rest. They deploy Azure Disk Encryption on all production VMs. They use a Key Vault with hardware security module (HSM) backed keys (Premium tier) and enable soft delete and purge protection. They also enforce JIT VM access for all administrators, requiring approval from a manager for any RDP session. Network security groups are used to restrict access to only necessary ports (e.g., 443 for web servers, 1433 for SQL). Azure Bastion eliminates the need for public IPs on VMs. The firm monitors all access via Azure Monitor and Defender for Cloud alerts.

Scenario 2: E-commerce Platform An e-commerce company runs a multi-tier application with web, app, and database VMs. They use application security groups (ASGs) to group VMs by tier. NSG rules allow traffic only between ASGs (e.g., web to app on port 8080, app to DB on 1433). They deploy Azure Bastion for admin access and enable JIT for all management ports. They use Azure Update Management to patch VMs monthly. For backup, they use Azure Backup with daily backups and 30-day retention. They also enable host encryption for an extra layer of protection.

Common Pitfalls: Misconfigured NSG rules (e.g., allowing all inbound from Internet) can expose VMs. Forgetting to enable soft delete on Key Vault prevents ADE from working. JIT not being enabled on all VMs leaves some exposed. Overlooking Gen2 VM requirements for Secure Boot. Over-provisioning Bastion concurrent sessions can cause connectivity issues.

How AZ-500 Actually Tests This

The AZ-500 exam tests Azure VM security under objective 'Manage compute security' (2.1). Key areas: (1) Configure remote access (Azure Bastion, JIT, NSG rules). (2) Configure disk encryption (ADE, SSE, host encryption). (3) Configure update management and backup. (4) Implement Azure Policy for compliance.

Common Wrong Answers: - 'Azure Bastion requires a public IP on the VM' – False; Bastion uses private IPs. - 'JIT access is enabled by default for all VMs' – False; it must be explicitly enabled. - 'Disk encryption encrypts temporary disks' – False; temporary disks are encrypted by SSE, not ADE. - 'NSGs can filter application-layer traffic' – False; NSGs are layer 4 only. - 'Azure Backup can back up to any region' – False; backup vault must be in same region as VM.

Specific Numbers: NSG priority range 100-4096; JIT default duration 3 hours; ADE requires Key Vault with soft delete and purge protection; Bastion subnet must be /27 or larger; Backup retention max 99 years.

Edge Cases:

JIT does not work if the VM has no NSG associated.

ADE cannot encrypt VMs that are already encrypted with SSE (but SSE is default).

Bastion does not support VMs in a different region.

Gen2 VMs are required for Secure Boot; Gen1 VMs do not support it.

Eliminate Wrong Answers: If a question asks about 'encryption at rest' for temporary disks, the correct answer is SSE, not ADE. If asking about 'secure remote access without public IP', the answer is Azure Bastion. If asking about 'temporary opening of ports', the answer is JIT.

Key Takeaways

Azure Bastion provides secure RDP/SSH access without public IPs on VMs; requires a /27 subnet named AzureBastionSubnet.

Just-in-Time VM access (JIT) reduces attack surface by creating temporary NSG rules; default max duration is 3 hours.

Azure Disk Encryption (ADE) uses BitLocker (Windows) or DM-Crypt (Linux) and requires Key Vault with Soft Delete and Purge Protection.

NSG rules are evaluated in priority order (100-4096); they are stateful for inbound traffic but not outbound.

Generation 2 VMs support Secure Boot and vTPM; required for features like UEFI boot.

Azure Backup supports application-consistent backups via VSS for Windows; retention up to 99 years.

Azure Policy can enforce VM compliance including disk encryption, JIT, and allowed locations.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Azure Disk Encryption (ADE)

Encrypts OS and data disks using BitLocker/DM-Crypt

Uses Key Vault for key management (customer-managed keys)

VM-level encryption; requires VM deallocation for Windows

Encrypts data at rest within Azure Storage

Not available for temporary disks

Azure Storage Service Encryption (SSE)

Encrypts all data at rest in Azure Storage (including temporary disks)

Uses platform-managed keys by default (or customer-managed keys)

Storage-level encryption; no VM impact

Enabled by default for all managed disks

Does not encrypt OS or data disks separately; encrypts the underlying storage

Watch Out for These

Mistake

Azure Disk Encryption encrypts all disks including temporary disks.

Correct

ADE encrypts OS and data disks only. Temporary disks are encrypted by Azure Storage Service Encryption (SSE) at the host level.

Mistake

Azure Bastion requires a public IP on the VM.

Correct

Bastion connects to VMs via private IPs. The public IP is assigned to the Bastion service, not the VM.

Mistake

NSGs can block application-layer attacks like SQL injection.

Correct

NSGs operate at Layer 4 (TCP/UDP) and cannot inspect application payloads. Use Azure WAF for Layer 7 filtering.

Mistake

Just-in-Time VM access is enabled automatically for all VMs.

Correct

JIT must be explicitly enabled via Defender for Cloud or Azure Policy. It is not default.

Mistake

Azure Backup can back up VMs to any Azure region.

Correct

The Recovery Services vault must be in the same region as the VM. Cross-region backup is not supported (except for geo-redundant storage).

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

Can I use Azure Bastion to connect to VMs in a peered VNet?

Yes, but only if the Bastion is deployed in the same region as the VMs and the VNet is directly peered (not via a hub-and-spoke with a firewall). Bastion does not support transitive peering; you must deploy Bastion in each spoke VNet that contains VMs you need to connect to.

What happens if I enable JIT on a VM that has no NSG?

JIT will fail because it relies on modifying NSG rules. You must associate an NSG to the VM's subnet or NIC before enabling JIT. Azure Security Center will alert you if no NSG is present.

Does Azure Disk Encryption support Linux VMs?

Yes, ADE uses DM-Crypt for Linux VMs. It supports most major distributions like Ubuntu, CentOS, RHEL, and SUSE. The VM must have a compatible kernel and the dm-crypt module loaded.

Can I encrypt an already running Windows VM with ADE?

Yes, but for Windows, the VM may need to be deallocated (stopped) for the initial encryption. After encryption is complete, the VM can run normally. Linux VMs can be encrypted while running.

What is the difference between Azure Backup and Azure Site Recovery for VMs?

Azure Backup provides periodic backups for data protection and restoration. Azure Site Recovery (ASR) provides disaster recovery by replicating VMs to a secondary region. Backup is for data loss, ASR is for downtime. Both can be used together.

How do I enforce that all VMs have disk encryption enabled?

Use Azure Policy with the built-in policy 'Audit VMs that do not use disk encryption' or create a custom policy with deny effect. Assign the policy at the subscription or management group level and use remediation tasks to fix non-compliant resources.

Can I use a single Key Vault to encrypt VMs in multiple subscriptions?

Yes, but the Key Vault must be in the same region as the VMs. You can grant the Azure Disk Encryption service principal access to the vault from other subscriptions. However, it's best practice to use a Key Vault per subscription for isolation.

Terms Worth Knowing

Ready to put this to the test?

You've just covered Azure VM Security — now see how well it sticks with free AZ-500 practice questions. Full explanations included, no account needed.

Done with this chapter?