Introducing a new way to review your PRs.

Read the announcement

floci-io / floci-az

Light, fluffy, and always free - Local Azure Emulator

View on GitHub

27 documents · Updated Nov 23, 2026

docs / azure-policy-insights

Azure Policy Insights

Azure Policy Insights provides the Microsoft.PolicyInsights control plane for local policy compliance state. It records the result of policy evaluation on successful resource writes and on-demand scans, then makes that state available through scoped queries and summaries.

Service boundary

Policy state control plane

The Policy Insights service is the reporting side of Azure Policy. Policy definitions and assignments come from the Policy service, while Policy Insights stores the resulting verdict for each locally evaluated resource.

The control plane exposes these main operations:

  • policyStates/latest/queryResults and policyStates/default/queryResults return policy-state records.
  • policyStates/latest/summarize and its default form return compliance counts.
  • policyStates/latest/triggerEvaluation starts a scan at subscription or resource-group scope.
  • asyncOperationResults reports the scan operation as complete.
  • Tenant-level policyMetadata is available as an empty built-in metadata list because no built-in definitions are seeded.

The service is enabled only when both the Policy service and its insights setting are enabled. Its provider route also handles extension paths where Microsoft.PolicyInsights is the final provider segment.

References: src/…/PolicyInsightsHandler.java• L31-131 src/…/PolicyInsightsArmSurface.java• L13-29 src/…/application.yml• L350-353

Policy state records

A policy state is one verdict for one resource against one policy definition in one assignment. An initiative can add a definition reference to that identity, so the same resource can have several records for one assignment.

Each record carries the resource identity and basic resource facts with the assignment and definition identity. Its compliance state is one of Compliant, NonCompliant, or Exempt. The query response also exposes isCompliant and serializes object-valued fields such as tags and effective parameters as JSON text.

The local store keeps only the latest record for each resource, assignment, definition, and initiative reference. It is process-local state rather than a separate durable store for each tenant. Tenant isolation applies when tenant-scoped management-group queries select records. A reset clears the store, and deleting a resource or assignment removes its related records.

References: src/…/PolicyState.java• L12-39 src/…/PolicyState.java• L41-85 src/…/ComplianceStore.java• L16-24 src/…/ComplianceStore.java• L52-81 src/…/PolicyHandler.java• L339-349

Compliance evaluation

Write-time recording

Policy evaluation runs before an eligible PUT or PATCH reaches its resource handler. When the write succeeds, Policy Insights replaces the resource's previous states with the evaluations produced by that request.

The write path keeps policy enforcement and compliance reporting related but separate:

  • deny prevents the write and does not create a new compliance record.
  • append changes the request before the resource handler sees it. A successful result is recorded as compliant for that definition.
  • audit permits the write and records its policy result after the handler succeeds.
  • An exemption produces an Exempt state.

Successful deletes remove the deleted resource's states. A tags-only patch updates the states for definitions that inspect tags and keeps the other definitions' latest states.

References: src/…/PolicyEvaluationRule.java• L31-37 src/…/PolicyEvaluationRule.java• L93-179 src/…/PolicyEngine.java• L170-253

On-demand scanning

An on-demand scan evaluates the current resource body without applying policy changes. It covers every resource group and every indexed resource in the selected subscription or resource group. The scanner reads each resource through its normal ARM route so the scan sees the same resource shape that a client receives.

The scan flow is:

flowchart LR
    A[Trigger at subscription or resource-group scope] --> B[Find resource groups and indexed resources]
    B --> C[Read each resource through ARM]
    C --> D[Evaluate applicable assignments in read-only mode]
    D --> E[Replace that resource's stored policy states]
    E --> F[Return completed operation status]

An unreadable resource is skipped and keeps its prior verdicts. The trigger returns an accepted operation response with a status URL, but the local scan is synchronous, so polling that URL reports success immediately.

References: src/…/ComplianceScanner.java• L30-37 src/…/ComplianceScanner.java• L65-105 src/…/ComplianceScanner.java• L107-148 src/…/PolicyInsightsHandler.java• L134-149

Locally evaluated resources

The local policy engine evaluates provider resources and resource groups. It does not evaluate Policy resource writes themselves. The scan and write paths use the same assignment matching and rule evaluation, but a scan uses read-only mode so append does not change the stored resource.

This means query results describe local evaluation history, not a separate Azure resource inventory. A resource must be readable through the local ARM router for a scan to refresh its state. A policy assignment that refers to an unavailable built-in definition produces no local definition evaluation because built-ins are not seeded.

References: src/…/PolicyEngine.java• L20-35 src/…/PolicyEngine.java• L106-127 src/…/PolicyEngine.java• L229-246 src/…/ComplianceScanner.java• L80-90

State query model

Scope and tenant boundary

Policy-state queries use the scope before the Microsoft.PolicyInsights provider segment. A subscription scope includes its resources. A resource-group scope includes that group and its children. A resource scope includes the resource and child resources. Assignment and definition scopes select the states created by that policy object.

Management-group queries are tenant-scoped. The handler resolves the tenant from the request token when the directory knows it, then includes subscriptions placed under the named management group or its descendants in that tenant's hierarchy. A management group with the same name in another tenant does not select those states.

The compliance store itself is local process state rather than a separate durable store for each tenant. Tenant isolation is applied when management-group scope is resolved, while subscription and resource scopes select states by their resource IDs.

References: src/…/PolicyInsightsHandler.java• L297-331 src/…/ComplianceStore.java• L22-24

Query results

queryResults filters the selected states, orders them by timestamp, and returns the Azure-style value collection. Results are newest first unless $orderby=timestamp asc is requested. The service limits $top to 1,000 and uses $skiptoken for later pages.

The supported $filter form joins equality clauses with and. It can filter by compliance state, compliance flag, policy assignment or definition identity, policy action, resource identity, resource type, location, resource group, or subscription. $select reduces the fields in each returned record without changing the stored state.

References: src/…/PolicyInsightsHandler.java• L151-199 src/…/PolicyInsightsHandler.java• L333-364 src/…/PolicyState.java• L38-73

Compliance summaries

summarize applies the same scope and filter rules as queryResults, then groups states by assignment. It counts non-compliant resources and policy definitions and returns resource details for non-compliant, compliant, and exempt results.

A resource counts once in the summary. If any selected state marks it non-compliant, that state wins over compliant or exempt states. Otherwise the summary uses compliant when a compliant state exists and exempt when only exempt states exist.

References: src/…/PolicyInsightsHandler.java• L202-294

Service relationships

Policy service relationship

The Azure Policy Service owns definitions, initiatives, assignments, and exemptions. Policy Insights does not author or enforce those resources. It consumes the policy engine's evaluations and exposes their latest compliance results.

References: src/…/PolicyEngine.java• L97-103 docs/azure-policy-service.md

Resource Graph relationship

The Azure Resource Graph is a separate inventory query surface. Its policy resource table describes stored policy control-plane resources, while Policy Insights queries describe resource compliance states. A client can use both views to connect policy configuration with local compliance results.

References: docs/azure-resource-graph.md src/…/PolicyInsightsHandler.java• L153-260

ARM governance relationship

The ARM resource governance page describes the resource operations that provide the input to local policy evaluation. Policy Insights reports the resulting state after those operations or after a scan reads the current resource through ARM.

References: src/…/PolicyInsightsHandler.java• L136-149 docs/arm-resource-governance.md

Platform service relationship

The Azure platform services page places Policy Insights beside the Policy control plane and other platform services. Policy Insights is the reporting and scan path that completes the Policy flow. It does not replace the Policy resource lifecycle or the Resource Graph inventory view.

References: docs/azure-platform-services.md src/…/PolicyInsightsHandler.java• L107-131

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the Policy engine's evaluation records aligned with PolicyState identity fields. A change to assignment, definition, or initiative reference identity can create duplicate states or leave stale states behind.
  • Keep write-time recording and scan-time recording aligned. Both paths must use the same policy verdict rules, while scans must remain read-only.
  • Keep resource deletion and assignment deletion connected to compliance cleanup. Removing control-plane objects must not leave queryable states for them.
  • Keep management-group scope checks tied to the caller tenant and its hierarchy. A scope change can expose another tenant's policy states.
  • Keep query paging and $select behavior aligned with the count, next-link, and response field rules.
  • Keep the scanner's resource discovery and ARM read path aligned. A resource that appears in the index but cannot be read must retain the documented stale-state behavior.

Important failure modes

TriggerConsequenceGuard
Policy Insights or Policy is disabledPolicy Insights routes are unavailable and no new states are recordedEnable both the Policy service and its insights setting
A scanned resource cannot be read through ARMIts old policy states remain unchangedMake the resource readable at a supported API version before scanning
A write is denied or fails in its resource handlerNo new compliance state replaces the prior stateTreat a successful resource response as the recording point
A query uses unsupported filter syntaxThe request returns 400 InvalidQueryFilterUse equality clauses joined by and
$skiptoken is invalidThe query returns 400 InvalidQueryOptionReuse the token from the prior response
A management-group query uses a token from another tenantThe query can resolve a different tenant context or return no matching statesUse a token whose tenant matches the intended management-group hierarchy
The emulator resetsAll locally stored policy states are lostTreat compliance state as process-local data

Key files

FileWhy to read it
src/…/PolicyInsightsHandler.javaDefines the Policy Insights routes, tenant-aware scope rules, query behavior, summaries, and scan trigger.
src/…/ComplianceScanner.javaShows how subscription and resource-group scans discover, read, and evaluate local resources.
src/…/ComplianceStore.javaShows the lifecycle and replacement rules for local policy states.
src/…/PolicyState.javaDefines the compliance record identity and query response fields.
src/…/PolicyEvaluationRule.javaShows when successful writes and deletes update compliance state.
src/…/PolicyEngine.javaShows the shared evaluation model used by writes and read-only scans.
src/…/PolicyInsightsArmSurface.javaShows the tenant-level policyMetadata resource boundary.
docs/azure-policy-service.mdExplains the policy resources and assignments that produce compliance evaluations.
docs/azure-platform-services.mdPlaces Policy Insights in the wider Azure service flow.
docs/arm-resource-governance.mdExplains the ARM resource lifecycle that supplies resources for evaluation.
docs/azure-resource-graph.mdExplains the separate inventory query view for policy control-plane resources.