Automation

Azure Machine Configuration: diagnose a non-compliant assignment before creating a policy exemption

A production runbook for separating Azure Policy scope, guest assignment, agent health, package execution and real OS drift before exempting a machine or triggering remediation.

09 Nov 2026 azuremachine-configurationazure-policyguest-configurationcompliancevirtual-machinesazure-arcautomationsecurityobservabilityresource-graphrunbookrollbackproduction

A production VM becomes non-compliant with an Azure Policy baseline after a routine image update. The policy summary names a machine configuration rule, but the application is healthy and the operating system team cannot reproduce the alleged drift. Creating an exemption would clear the governance signal quickly. It could also hide a missing extension, an unreachable package, a stale guest assignment or a configuration item that is genuinely unsafe.

The running case is a Windows or Linux Azure VM, with the same diagnostic path applicable to an Azure Arc-enabled server. The objective is to identify the first broken stage between policy intent and guest evidence, then choose one bounded action: repair prerequisites, remediate one canary, create a justified temporary exemption, or roll back the policy or package release.

Freeze the compliance contract

Preserve the policy and machine state before launching a remediation task. A compliance percentage is not enough to reproduce the decision.

yaml 01-machine-configuration-incident.yml
incident: INC-MC-417
machine: /subscriptions/.../resourceGroups/rg-app-prod/providers/Microsoft.Compute/virtualMachines/api-03
policy_assignment: pa-prod-os-baseline
policy_definition_version: <version-or-definition-id>
guest_assignment: AzureLinuxBaseline
expected_assignment_type: Audit
first_noncompliant_utc: 2026-11-09T05:20:00Z
last_known_compliant_utc: 2026-11-08T05:18:00Z
recent_changes:
- image-or-package-release
- policy-or-initiative-version
- extension-or-agent-version
- network-or-proxy-policy
preserve:
- policy assignment and parameters
- exemption inventory
- guest assignment JSON and compliance details
- VM identity and extension state
- redacted agent logs
- application health and change timeline
decision_deadline_utc: 2026-11-09T09:00:00Z

Record whether the assignment is expected to audit, apply once and monitor, or continuously correct. A non-compliant result under Audit is evidence, not a failed remediation. Under ApplyAndMonitor, drift can remain until an explicit remediation. Only ApplyAndAutoCorrect is expected to correct detected drift during a later evaluation.

Locate the first missing stage

Treat the path as four separate stages:

  1. Azure Policy selects the machine and evaluates the definition.
  2. The Machine Configuration service creates a Microsoft.GuestConfiguration/guestConfigurationAssignments resource.
  3. The in-guest agent retrieves the assignment and its content package, then evaluates the configuration.
  4. The guest assignment reports rule-level evidence that Azure Policy consumes.

A machine marked non-compliant at stage one does not prove that stage four produced a valid audit. Build the following matrix for one affected machine and one healthy control.

text 02-compliance-path-matrix.txt
STAGE                    AFFECTED VM       HEALTHY CONTROL
Policy assignment in scope   yes/no            yes
Guest assignment exists      yes/no            yes
Guest assignment status      pending/error/... compliant
Expected package/version     value             value
Extension or Arc agent       version/status    version/status
Managed identity             present/missing   present
Package downloaded           yes/no            yes
Rule-level result            item + reason     passing item
Last report time             UTC               UTC

If no guest assignment exists, stay on the Azure Policy and resource-provider side. If it exists but remains Pending, inspect identity, extension, connectivity and package retrieval. If a fresh rule-level report says NonCompliant, investigate the operating-system state instead of reinstalling the agent.

Query assignments at fleet scale

Use Azure Resource Graph to separate missing reports, pending evaluations and explicit drift. Keep resource IDs in the output so every result can be tied back to the policy assignment and machine.

kusto 03-machine-configuration-status.kql
guestconfigurationresources
| where type =~ "microsoft.guestconfiguration/guestconfigurationassignments"
| extend p = parse_json(properties)
| extend TargetResourceId = tostring(p.targetResourceId),
       ComplianceStatus = tostring(p.complianceStatus),
       AssignmentType = tostring(p.assignmentType),
       PolicyAssignmentId = tostring(p.policyAssignmentId),
       LastComplianceStatusChecked = todatetime(p.lastComplianceStatusChecked)
| where PolicyAssignmentId has "/providers/Microsoft.Authorization/policyAssignments/pa-prod-os-baseline"
| project TargetResourceId, name, ComplianceStatus, AssignmentType,
        LastComplianceStatusChecked, PolicyAssignmentId, id
| order by ComplianceStatus asc, TargetResourceId asc

Do not interpret an absent row as compliant. It can mean that the policy did not select the machine, the guest assignment was never created, permissions hide the resource, or the data has not converged yet. Compare this result with the policy scope, exclusions, resource selectors and the actual inventory.

For a specific assignment, retain the extension resource directly.

bash 04-export-guest-assignment.sh
VM_ID="/subscriptions/<sub>/resourceGroups/rg-app-prod/providers/Microsoft.Compute/virtualMachines/api-03"
ASSIGNMENT="AzureLinuxBaseline"
ASSIGNMENT_ID="$VM_ID/providers/Microsoft.GuestConfiguration/guestConfigurationAssignments/$ASSIGNMENT"

az resource show --ids "$ASSIGNMENT_ID" --api-version 2022-01-25 \
--output json > guest-assignment.json

az vm extension list \
--ids "$VM_ID" \
--query "[?publisher=='Microsoft.GuestConfiguration'].{name:name,version:typeHandlerVersion,provisioningState:provisioningState,autoUpgrade:enableAutomaticUpgrade}" \
--output json > machine-configuration-extension.json

For an Azure VM, confirm the system-assigned managed identity required by Machine Configuration and the AzurePolicyforWindows or AzurePolicyforLinux extension. For Arc-enabled servers, inspect the connected-machine agent path instead of assuming the Azure VM extension model.

Separate transport failure from real drift

A guest assignment can fail before its configuration test runs. Check these boundaries in order:

  • the Microsoft.GuestConfiguration resource provider is registered;
  • the machine has the required identity and a healthy extension or Arc agent;
  • outbound HTTPS or the approved private path reaches the Machine Configuration service;
  • the content URI is reachable from the machine;
  • the expected package and version are downloaded;
  • the package can load its resources and evaluate the target setting;
  • the rule-level report is recent enough to support the decision.

Do not add a broad outbound rule merely because the package is absent. Correlate DNS, proxy and firewall evidence with the exact destination and time window. Likewise, do not recreate the guest assignment while its current JSON and report are the only evidence of the failure.

The agent logs are the next boundary. For Azure VMs, review:

  • Windows: C:\ProgramData\GuestConfig\gc_agent_logs\gc_agent.log;
  • Linux: /var/lib/GuestConfig/gc_agent_logs/gc_agent.log.

For Arc-enabled servers, use the corresponding arc_policy_logs directory. Package content is stored under C:\ProgramData\GuestConfig\configuration on Windows and /var/lib/GuestConfig/Configuration on Linux.

Collect only the incident window and redact secrets, internal addresses and package parameters that should not leave the host.

Prove the configuration item

Once the agent has produced a fresh report, move from the assignment summary to the individual configuration item. Record the expected value, observed value, test method, evidence timestamp and whether the setting is owned by another automation system.

yaml 05-rule-evidence.yml
assignment: AzureLinuxBaseline
configuration_item: <rule-or-resource-name>
expected: <policy-parameter-and-normalized-value>
observed: <redacted-current-value>
test_result: false
evidence_utc: 2026-11-09T06:12:00Z
other_owners:
- image_build
- cloud_init
- configuration_management
- application_bootstrap
risk_if_changed: <service-or-security-impact>
rollback:
source: <previous-value-or-image>
verification: <command-and-application-check>

This step catches policy conflicts. A package can correctly report drift while cloud-init, Ansible, a security agent or an application bootstrap immediately restores another value. Continuous remediation would then create a correction loop rather than compliance.

Compare one healthy machine with the same image, policy parameters and assignment version. Differences in operating system family, package version or parameter expansion often explain why a broad baseline fails on only one ring.

Canary the remediation

Do not launch a subscription-wide remediation task to test one hypothesis. Select one disposable or redundant machine from the affected cohort and define stop conditions before applying anything.

text 06-remediation-gate.txt
PROMOTE ONLY IF
- guest assignment and package version match the approved release
- the canary reports the expected rule-level change
- application probes and dependency checks remain healthy
- the next evaluation stays compliant
- no competing automation restores the old value

STOP AND ROLLBACK IF
- an unrelated setting changes
- agent or package errors increase
- the service fails its health or capacity budget
- the assignment cannot be tied to the policy version
- the canary oscillates between compliant and non-compliant

For ApplyAndMonitor, trigger the approved remediation path on the canary and observe a complete evaluation cycle. For ApplyAndAutoCorrect, first prove that the intended setting is safe and that no other controller owns it. Changing assignment type is a policy decision, not an incident workaround.

Exempt only the understood condition

A policy exemption is appropriate when the machine has a documented, time-bounded reason not to meet the rule. It is not a repair for missing evidence.

Before creating one, require:

  • the exact policy assignment and definition reference;
  • the smallest resource scope;
  • an owner and expiry;
  • the accepted risk and compensating control;
  • the rule-level evidence that justifies the exception;
  • a removal condition and review date.

Machine Configuration needs an additional operational check: exempting a resource from policy does not necessarily stop an already associated guest assignment from scanning it. If execution must stop, verify the exemption first, then remove the associated guest assignment through the approved process and prove that the policy no longer recreates it. Preserve its last report before deletion.

Decide and roll back

End the incident with one of four explicit outcomes.

  • Repair prerequisites when the assignment is missing, pending or unable to report.
  • Remediate a canary, then a bounded ring, when fresh evidence proves safe OS drift.
  • Create a temporary exemption when the deviation is intentional, owned and expiring.
  • Roll back the policy parameters, package version or enforcement release when the rule is wrong, unsafe or conflicting.

Rollback restores the previous policy or package contract, not merely a green compliance count. Re-evaluate the canary, confirm the guest assignment version and verify application health. If a configuration was applied, restore the prior OS value only through a tested service recovery path.

Conclusion

A non-compliant Machine Configuration assignment is the start of a diagnosis, not proof that the host should be remediated or exempted. Separate policy selection, assignment creation, agent transport, package execution and rule-level drift, then validate one canary.

The final decision should be auditable: repair the evidence path, correct a proven drift, grant a bounded exemption, or roll back the configuration release. If the failing stage is still unknown, keep enforcement contained and do not turn missing evidence into permanent policy debt.