Validate dynamic scope membership before execution

Completed

A dynamic scope selects VMs by a query rather than a fixed list. Contoso might approve one orders canary and still target the wrong machine: a tag change could substitute payments-01 for orders-01 without changing the count. To catch that substitution before installation, compare three sets of full VM resource IDs: those approved in the change record, those previewed before the window, and those resolved for the actual run. Never build the approval list from the result you're trying to validate.

Diagram that shows a tag change replacing approved orders-01 with payments-01. The target count stays at one, but the VM ID changes.

Establish the assignment boundary

To keep the canary assignment limited to orders-01, check its scope and freeze its membership before the patch window:

  1. For a resource-group boundary, place the assignment at /subscriptions/{subscriptionId}/resourceGroups/{group}/providers/Microsoft.Maintenance/configurationAssignments/{name}. A resource-group filter limits which VMs match. It doesn't change where the assignment is defined: an assignment created at subscription scope remains at subscription scope.
  2. Read the assignment directly. Verify its ID, properties.resourceId (the approved group), and properties.maintenanceConfigurationId. Check the full filter: resource group, VM resource type, OS, location, and tags. For example, require All of Workload=Orders and PatchWave=Canary; Any would also match an unrelated canary or every Orders VM. Retain the assignment request and response.
  3. Inspect Dynamic scopes on the configuration and Updates > Scheduling on the VMs. Review all static and dynamic assignments referencing the configuration across the approved subscriptions, not just the intended group. Even if no VM appears in both waves, another schedule might still target one of those VMs during the same window. Also check other campaigns targeting different VMs in a shared availability set, and coordinate those schedules across workload owners.
  4. Compare the preview with the signed-off manifest. If the schedule uses pre-events, finish schedule setup and target-assignment changes more than 40 minutes before the patch window opens. For an existing maintenance configuration whose schedule is being changed, also follow Microsoft's recommendation to update it at least one hour before the scheduled run because cached old policies can retain an earlier trigger time. That recommendation doesn't impose one hour on every tag change, VM start, or health check. Until the run ends, don't change maintenance assignments, tags used to select VMs, or permissions that determine which VMs and assignments the handler can see. Restrict assignment writes to the designated deployment identity and withdraw its active write grant during the freeze. If an emergency changes which VMs are targeted or which VMs the handler can see, review the run again. Don't rewrite the approved list to make the new targets look authorized.

If campaign VMs belong to availability sets, check for other campaigns targeting any VM in the same set, including different workloads. An update domain is a platform-defined maintenance grouping within an availability set. Azure Update Manager processes VMs within update-domain boundaries and doesn't update different update domains in that set concurrently. This isn't a one-VM-at-a-time or application-health guarantee.

Coordinate the shared set's campaign timing across workload owners. Microsoft warns that overlapping schedules for machines in the same availability set can lead to updates not being applied or to failures when the maintenance window is exceeded. A longer maintenance window can help, within the Guest maximum of 3 hours 55 minutes. If you choose nonoverlapping campaigns, confirm the earlier installations and required reboots have actually finished before releasing the next campaign: the scheduled window end doesn't forcibly terminate an installation already in progress. Keep patchMode=AutomaticByPlatform and bypassPlatformSafetyChecksOnUserSchedule=true for Customer Managed Schedules. The bypass flag doesn't remove the availability-set restriction.

Diagram that shows how the operator checks assignment scope and overlapping schedules before freezing orders-01 as the approved target.

Visibility matters as much as the comparison. Azure Resource Graph returns what the caller can see; it can omit inaccessible resources without an error, and new changes can take time to appear. Seeing one expected VM with Reader on one group doesn't rule out an assignment in another group. For a single-subscription campaign, one option is to assign the built-in Reader role directly to the handler identity at subscription scope. Leave the assignment unconditional and confirm that no deny assignment blocks the reads the handler needs. Use Get-AzRoleAssignment to confirm that the handler identity has Reader at subscription scope. Use Get-AzDenyAssignment to check for restrictions. Separately, compare the maintenance assignments the administrator read directly with the approved list. If complete visibility can't be established or isn't authorized, don't schedule the change on the strength of a partial query.

Diagram that shows how group-only access can hide another maintenance assignment even when Resource Graph returns the expected canary.

Compare the actual run with the approved wave

The pre-event lists the Azure subscriptions targeted by this run in data.ResourceSubscriptionIds. Proceed only if that complete set matches the approved subscriptions. In Azure Resource Graph Explorer, select those subscriptions and use Kusto Query Language (KQL) to retrieve machine-level applyupdates records. Replace <full-run-correlation-id> with the event's full data.CorrelationId after matching it to the approved maintenance configuration and start time. Don't filter by the expected group, name, or tags: those filters can hide an unapproved target.

maintenanceresources
| where type =~ 'microsoft.maintenance/applyupdates'
| where properties.correlationId =~ '<full-run-correlation-id>'
| project id, resourceId = tostring(properties.resourceId)
| order by id asc

Diagram that shows how to match the subscriptions and run ID before querying Resource Graph for every VM targeted by the run.

In an automated query, follow every continuation token (for example, Search-AzGraph -SkipToken) within the time budget. Preserve the query scope, run ID and capture time with the results. If the query returns no VMs, omits a page, or might not reflect recent changes, you can't confirm which VMs the run will patch. Treat membership as unknown. No set comparison can detect an inaccessible row.

Diagram that shows when to compare queried VMs with the approved list and when missing pages, stale data, or limited access leave targets unknown.

To compare approved and actual targets in PowerShell, place two CSV files in the current directory:

  • approved-membership.csv: Export the signed-off change record with columns wave (canary, later, or excluded) and resourceId (full Azure VM ID). Don't derive approval from live tags.
  • resolved-run.csv: Export every microsoft.maintenance/applyupdates row from Resource Graph's maintenanceresources for the verified properties.correlationId, across all approved execution subscriptions. Include id and resourceId, taking resourceId from properties.resourceId. Don't filter out other groups or unapproved VMs.

The comparison reads both files without changing Azure. It rejects duplicate VM IDs in the manifest, even across different waves, and reports any missing or unexpected target.

$wave = 'canary'
$manifest = @(Import-Csv -LiteralPath 'approved-membership.csv' -ErrorAction Stop)
$rows = @(Import-Csv -LiteralPath 'resolved-run.csv' -ErrorAction Stop)
$vmIdPattern = '^/subscriptions/[^/]+/resourceGroups/[^/]+/providers/Microsoft\.Compute/virtualMachines/[^/]+$'
foreach ($row in ($manifest + $rows)) {
    if ($row.resourceId -notmatch $vmIdPattern) { throw "Invalid VM ID: '$($row.resourceId)'" }
}
if (@($manifest | Where-Object { $_.wave -notin 'canary','later','excluded' }).Count) {
    throw 'Manifest contains an unrecognized wave'
}
if (@($manifest | Group-Object resourceId | Where-Object Count -gt 1).Count) {
    throw 'Duplicate or overlapping VM IDs in approved membership'
}
$approved = @($manifest | Where-Object wave -eq $wave | ForEach-Object { $_.resourceId.ToLowerInvariant() })
$resolved = @($rows | ForEach-Object { $_.resourceId.ToLowerInvariant() } | Sort-Object -Unique)
if ($approved.Count -eq 0 -or $resolved.Count -eq 0) { throw 'Empty approval or run membership' }

$drift = @(Compare-Object -ReferenceObject $approved -DifferenceObject $resolved)
if ($drift.Count) {
    $drift | Format-Table InputObject, SideIndicator | Out-String | Write-Warning
    throw 'Run membership differs from approval'
}

<= means an approved VM is missing; => means an unapproved VM is present. If the run targets payments-01 instead of orders-01, the target count is still one. But the approved orders VM is missing, and the payments VM is targeted without its owner's approval. A comparison error stops the PowerShell script, not Azure patching. For a known run with mismatched or unconfirmed membership, request cancellation before the earlier of the event's CancellationCutOffDateTime and the scheduled start minus ten minutes. Read the run status and confirm Cancelled.

Diagram that shows how to compare actual VM IDs with the signed manifest and cancel if targets differ or membership can't be confirmed.