Azure Policy service
The Azure Policy service provides a local Microsoft.Authorization control plane for authoring and managing policy definitions, initiatives, assignments, and exemptions. It routes these ARM requests by policy path and stores the resources through the local policy store. It does not evaluate policy rules against resource requests.
Control-plane boundary
Policy authoring boundary
The service models the part of Azure Policy that clients use to create and manage policy resources. A policy definition stores a rule, an initiative groups definitions, an assignment binds a definition to a scope, and an exemption records an exception for an assignment. These resources support the ARM lifecycle that SDKs, the Azure CLI, Terraform, and OpenTofu use.
The service validates rule shape and checks links between local resources. It accepts policy resources without applying their rules to other ARM requests, so this page covers policy administration rather than enforcement or compliance.
References: src/…/PolicyHandler.java• L37-47 src/…/PolicyHandler.java• L165-196
Resource relationships
Policy resources form a dependency chain. Set definitions and assignments can point to definitions. Exemptions point to assignments. The service checks these links when it creates a resource and protects a referenced definition or set definition from deletion.
The relationship also controls removal. Deleting an assignment removes its exemptions with it, while deleting a definition requires callers to remove dependent set definitions and assignments first.
flowchart LR
D[Policy definition] --> S[Policy set definition / initiative]
D --> A[Policy assignment]
S --> A
A --> E[Policy exemption]
References: src/…/PolicyHandler.java• L196-215 src/…/PolicyHandler.java• L303-315 src/…/PolicyHandler.java• L339-350
ARM request handling
Provider routing
The ARM routing layer uses a shared Microsoft.Authorization surface to distinguish policy resource paths from other authorization resources. It sends policy resource paths to the Policy service, while role assignments and other authorization resources remain available to their own handling paths.
The control plane is enabled by the policy service setting. When it is disabled, the Policy service declines the request and unrelated ARM requests can still use their normal routes.
flowchart TD
R[ARM request] --> G{Policy resource path?}
G -- No --> A[Generic ARM handling]
G -- Yes --> E{Policy service enabled?}
E -- No --> A
E -- Yes --> P[Policy request handling]
P --> S[Policy store]
P --> O[ARM response]
References: src/…/AuthorizationArmSurface.java• L15-19 src/…/AuthorizationArmSurface.java• L47-59 src/…/PolicyHandler.java• L80-109
Path and scope model
The request path parser treats policy resources as ARM extension resources. It takes the path before the last providers/Microsoft.Authorization segment as the scope. This supports tenant-rooted built-in paths, management groups, subscriptions, resource groups, and full resource scopes.
The final provider segment selects one of four resource kinds:
policyDefinitionsandpolicySetDefinitionsare available at management-group and subscription scope.policyAssignmentsandpolicyExemptionsare available at management-group, subscription, resource-group, and resource scope.- Tenant-rooted definition and set-definition reads represent built-in listings. They are empty because built-in definitions are not seeded.
The parser preserves request casing for returned resource IDs while the service uses normalized scope and resource IDs for comparison. A path with an unsupported type, unsupported scope, or extra sub-resource segment does not become a local policy resource. The handler removes query text before parsing and returns ResourceNotFound for unsupported sub-resource paths.
References: src/…/PolicyPath.java• L6-20 src/…/PolicyPath.java• L56-116 src/…/PolicyHandler.java• L103-114
Request lifecycle
The handler turns a matched path into a resource operation. It removes the query part for path parsing, identifies the resource kind and scope, applies the operation and list-filter rules, then returns an ARM-shaped response or an ARM error.
The main flow is:
- The router identifies a policy resource path.
- The handler parses the scope, type, name, and any unsupported remainder.
- A collection request lists matching resources. A named request reads, creates, updates, or removes one resource.
- The handler validates required fields and references.
- The policy store receives the normalized resource or returns the current state.
References: src/…/PolicyHandler.java• L103-126 src/…/PolicyHandler.java• L135-163 src/…/PolicyHandler.java• L504-528
Policy resource lifecycle
Definitions and initiatives
Policy definitions are the base authoring unit. The service requires a rule with an if condition and a then block that names an effect, then stores the definition with server-managed ARM fields. A policy set definition, also called an initiative, groups references to existing definitions and supplies defaults for reference IDs and definition versions when they are absent.
Both resource kinds support create or update, get, list, and delete at their allowed scopes. Their lists are limited to the requested scope rather than inherited scopes.
References: src/…/PolicyHandler.java• L135-196 src/…/PolicyHandler.java• L223-303
Assignments and exemptions
An assignment connects a definition or initiative to a management group, subscription, resource group, or resource. The service returns the assignment scope and instance data as part of the ARM resource. It also supplies managed identity data when the request asks for a system-assigned or user-assigned identity. A limited patch operation can update assignment identity, location, resource selectors, and overrides.
An exemption connects to an existing assignment. It supports updates to its resource selectors and scope-validation mode. Assignment and exemption lists can select exact scope, parent scope, descendant scope, and selected property values through policy list filters.
References: src/…/PolicyHandler.java• L320-489 src/…/PolicyHandler.java• L502-581 src/…/PolicyHandler.java• L642-731
Server-managed resource data
The service adds data that callers do not need to provide to make a resource usable. This includes ARM identity fields, assignment scope, an assignment instance ID, and creation or update audit fields. On later updates, the original creation data remains while last-modified data changes.
These values describe local emulator state. They identify the local request and resource history, but they do not replace policy evaluation or compliance records.
References: src/…/PolicyHandler.java• L371-408 src/…/PolicyHandler.java• L736-812 src/…/PolicyResource.java• L10-28
Local policy state
Policy store
The policy store is the local source of truth for four resource groups: definitions, set definitions, assignments, and exemptions. Each group has its own typed ARM resource store over the policy storage backend. Resource IDs are canonicalized for lookup, so reads, updates, deletes, and reference checks do not depend on request casing.
The store also performs the cross-resource lookups needed for safe deletion and removes exemptions that belong to a deleted assignment. Assignment removal also clears the related local compliance records. A stored resource keeps its ARM body together with internal scope data used for listing. Clearing the service clears all four groups; persistence then follows the emulator's configured storage mode rather than an in-memory-only contract.
References: src/…/PolicyStore.java• L19-35 src/…/PolicyStore.java• L37-89 src/…/PolicyStore.java• L119-155 src/…/PolicyHandler.java• L128-131 src/…/PolicyHandler.java• L341-350 src/…/PolicyResource.java• L10-28
Resource reference rules
References between policy resources must use absolute ARM IDs for the matching policy resource type. A relative path, another provider's ID, a collection path, or an ID for a different policy type does not resolve in the store. Tenant-rooted built-in IDs are the exception for control-plane validation, but they do not identify local stored resources.
References: src/…/PolicyStore.java• L30-34 src/…/PolicyStore.java• L158-170 src/…/PolicyHandler.java• L611-640
Related pages
The Azure platform services page places this control plane beside the other Azure service emulations. The Azure Policy Insights page covers policy activity and compliance records as a separate concern. The Azure Resource Graph page covers resource queries that can consume platform state. The Azure authorization and RBAC page covers the other authorization resources in the shared provider namespace. The Azure SignalR Service page provides a neighboring Azure service example. The ARM resource governance page describes the wider ARM governance model that routes requests to services such as Azure Policy.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the provider route guard aligned with
AuthorizationArmSurfaceand the resource types thatPolicyPathcan parse. A broad guard can take ownership of unrelatedMicrosoft.Authorizationresources. - Keep the service-enabled route behavior separate from policy state. Disabling the control plane must not accidentally change generic ARM routing or make unsupported policy resources available.
- Keep scope rules aligned between
PolicyPath, handler validation, and list matching. A change in one can silently allow writes that cannot be read or listed. - Preserve dependency checks when changing resource fields or IDs. Set definitions, assignments, and exemptions use those IDs to decide what is valid and removable.
- Keep assignment deletion and exemption cleanup aligned. Exemptions are bound to their assignment and are removed with it.
- Keep assignment deletion aligned with compliance cleanup. Removing an assignment must not leave local compliance records for an assignment that no longer exists.
- Keep server-managed audit fields separate from caller-supplied metadata. Updates must preserve creation data while changing last-modified data.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Policy service disabled | Policy paths fall through and policy create requests return 404 | Check the service-enabled route contract before changing provider dispatch |
| Policy resource type is placed at an unsupported scope | The request returns ResourceNotFound | Check the scope matrix before adding or moving an endpoint |
| Policy path contains an unsupported sub-resource | The request returns ResourceNotFound | Use only the supported policy resource path forms |
Definition rule lacks an if condition or then.effect | Create or update returns a policy validation error | Validate the policy rule shape before storing it |
| Assignment or initiative points to a missing local definition | The control-plane request returns a policy-specific not-found error | Create the referenced local resource first, or use an accepted tenant-rooted built-in ID |
| Definition or initiative is still referenced | Delete returns an invalid-delete error and keeps the resource | Remove dependent assignments and set definitions before deletion |
| Assignment is deleted | Its exemptions and local compliance records are removed as well | Read or remove dependent state before deleting the assignment when the client needs it |
| Tenant-rooted built-in list is queried | The response is an empty collection | Treat built-in definitions as unseeded local state |
| Emulator storage is cleared or reset | All local policy resources and related local state are removed | Treat the configured policy store as local emulator state rather than an external Azure tenant |
Key files
| File | Why to read it |
|---|---|
| src/…/AuthorizationArmSurface.java | Shows the policy resource types alongside the other Microsoft.Authorization types and defines the shared ARM routing surface. |
| src/…/PolicyPath.java | Defines the scope and resource-type model used for request matching. |
| src/…/PolicyHandler.java | Describes the control-plane lifecycle, validation, response shape, list filters, and resource relationships. |
| src/…/PolicyStore.java | Shows how policy resources use the local storage backend and how dependency lookups work. |
| src/…/PolicyResource.java | Defines the stored resource boundary between the ARM body and internal listing state. |
| docs/azure-policy-insights.md | Explains the policy activity and compliance records maintained as a separate service concern. |
| docs/azure-platform-services.md | Places Azure Policy in the wider platform-service model. |
| docs/arm-resource-governance.md | Places Azure Policy request handling in the wider ARM governance flow. |