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 / arm-resource-governance

ARM resource governance

ARM resource governance gives management-plane requests a shared meaning before a service handles them. It parses each path into scope and resource identity, applies subscription, resource-group, location, name, and provider rules, and keeps the resource views that clients use to discover and remove resources. The ARM service then exposes common management behavior while provider services supply their own resource actions.

Request governance

The request gate is the common boundary for ARM management requests. It gives every request one parsed call context, applies ordered rules, and invokes the selected handler only after the request passes those rules.

ARM request gate

src/…/ArmRequestGate.java builds an ArmCall from the request scope, path, method, declared resource type, and body when a rule needs it. A rule can allow the call, amend its context or body, or return an ARM response before the handler runs. Nested dispatch keeps the existing call context, so internal cleanup does not run the same gate twice.

The gate runs the same checks whether the router sends the request to a direct service handler or ArmHandler delegates it to a provider service. Rule positions must be unique. Rules that read a PUT or PATCH body cause the gate to buffer it once, so later rules and the handler see the same body, including any approved amendment.

The gate also supports an exit step. Rules that entered the request can observe the final response, including a response produced by an earlier rule or by the handler.

The request path then follows this broad sequence:

flowchart LR
    A[ARM request] --> B[Parse path and type]
    B --> C[Build ArmCall]
    C --> D[Apply ordered rules]
    D -->|reject or answer| E[ARM error response]
    D -->|allow or amend| F[Route to ARM surface]
    F --> G[Run handler]
    G --> H[Run entered rule exit steps]
    H --> I[Client response]

References: src/…/ArmRequestGate.java• L18-27 src/…/ArmRequestGate.java• L56-107 src/…/ArmRequestRule.java• L5-39 src/…/ArmVerdict.java• L5-37

Subscription scope

Subscription governance decides whether the subscription in a path can receive the request. A known writable subscription proceeds. An unknown subscription can be registered on first use under the caller's tenant when first-use behavior is enabled; strict subscription mode returns 404 SubscriptionNotFound instead. Read-only subscriptions allow reads and deletes but reject writes with 409 ReadOnlyDisabledSubscription.

Paths without a subscription, such as tenant discovery and subscription discovery, pass through this check. The directory and scope resolver provide the tenant, subscription, and cloud context used by the decision. See Cloud and directory configuration for that broader context.

References: src/…/SubscriptionRule.java• L13-30 src/…/SubscriptionRule.java• L67-92 src/…/ArmHandler.java• L209-227

Resource-group scope

Resource-group governance protects provider resources below a group boundary. In strict resource-group mode, any request for a provider resource or collection below a missing group stops before the provider runs and returns 404 ResourceGroupNotFound. The group's own operations and paths above the group do not use this child-resource check.

Resource-group semantics mode creates a missing group only after a child PUT succeeds. A failed request therefore leaves no group behind. The new group's location comes first from the created resource response, then from the normalized request location, and finally from the request cloud's default.

When resource-group deletion is enabled, the rule coordinates child writes with deletion. A write admitted before deletion can finish. A new PUT or PATCH is rejected while deletion is in progress. The group's own create, read, update, list, and delete paths manage the boundary itself and are not treated as child resources.

References: src/…/ResourceGroupRule.java• L18-39 src/…/ResourceGroupRule.java• L84-126 src/…/ResourceGroupRule.java• L129-155 src/…/ArmErrors.java• L82-89

Location policy

Location governance gives each declared resource type one location policy. The policy tells the gate whether a PUT needs a location, uses global, inherits the resource group's location, accepts an optional value, or has no location field.

When location normalization is enabled, the rule stores the cloud's canonical location in the body and in the request context. Strict location mode rejects a regional top-level PUT when its location is not offered by the subscription's cloud. A policy step that appends or replaces location is checked again, so a value added after the first location check cannot bypass the same rule.

Provider metadata reports the same location model to clients. Regional types list the subscription cloud's regions, global types list global, and child or location-free types list no locations.

References: src/…/LocationPolicy.java• L3-17 src/…/LocationRule.java• L14-32 src/…/LocationRule.java• L72-101 src/…/AppendedLocationRule.java• L9-15 src/…/ProviderService.java• L94-114

Resource name syntax

Resource type metadata can define the allowed syntax for a resource name. When strict name behavior is enabled, a PUT that does not match that rule stops at the request gate with the type's ARM error; the default behavior keeps the earlier permissive contract.

The name rule belongs to the resource type rather than to one handler. This lets the same declaration drive path matching and request validation without making each provider repeat the rule.

References: src/…/NameRule.java• L6-18 src/…/ResourceNameRule.java• L7-16 src/…/ResourceNameRule.java• L37-47 src/…/ArmResourceType.java• L18-30

Global DNS names

Some resource types use names that must be unique beyond one resource group. A global name rule reserves such a name before the provider runs, returns the type's conflict response when another resource owns it, and commits or releases the reservation from the final response. This closes the race in which two creates could otherwise pass separate ownership checks.

The global name registry rebuilds its view from the services that store these resources. It therefore does not become the source of resource state. Most names are shared across clouds because the related data plane is keyed by name; a declared per-cloud type uses the cloud as an additional boundary. A failed create releases only its own pending reservation, while a successful delete releases the committed name after any in-flight PUT to the same resource has ended.

References: src/…/GlobalName.java• L5-26 src/…/GlobalNameRegistry.java• L21-43 src/…/GlobalNameRegistry.java• L99-187 src/…/GlobalNameRule.java• L14-25 src/…/GlobalNameRule.java• L53-87 src/…/GlobalNameSource.java• L7-29

ARM response contract

ARM management errors use a JSON CloudError envelope with error.code and error.message. The shared error factory supplies common outcomes such as missing subscriptions, missing groups, invalid provider namespaces, missing provider registration, unsupported locations, and groups being deleted.

Body handling depends on the caller. The gate buffers bodies for rules that inspect them. Strict ARM-plane handlers treat malformed JSON and the JSON value null as 400 InvalidRequestContent, while an absent body remains an empty object. Compatibility paths retain tolerant parsing for absent or malformed bodies, and mutable parsing supports handlers that amend the body in place. The lenient parser also treats the JSON literal null as invalid and raises the same body exception instead of returning a null map. This separation lets strict provider management calls enforce the ARM contract without changing older resource shells.

References: src/…/ArmErrors.java• L10-24 src/…/ArmErrors.java• L31-89 src/…/ArmRequestBody.java• L11-15 src/…/ArmJson.java• L11-107 src/…/ArmHandler.java• L145-153

Resource identity

ARM identity comes from the resource path, not only from a provider's resource name. The parser keeps the spelling that clients sent for responses and provides a lower-case key for comparisons, ownership checks, and stored indexes.

Resource ID parsing

src/…/ArmResourceId.java recognizes subscription and resource-group roots, provider namespaces, nested type and name pairs, collections, actions, and extension resources. A path that ends on a type can be a collection or an action on the resource before it. Built-in ARM paths such as resource-group collections are also represented so the type registry can give them shared meaning.

The parsed identity supplies the subscription, resource group, provider namespace, type path, resource name, parent, scope, and canonical key. ArmPaths remains the small helper for handlers that need one segment or a path remainder. It also recognizes provider registration paths and matches provider markers without regard to case. Its caller-selected fallback values remain part of the malformed-path behavior.

References: src/…/ArmResourceId.java• L8-39 src/…/ArmResourceId.java• L55-132 src/…/ArmPaths.java• L9-18 src/…/ArmPaths.java• L24-38 src/…/ArmPaths.java• L86-129

Resource type registry

The type registry is the shared description of the ARM surface. Each service declares its namespace and resource types through an ArmSurfaceProvider; the registry matches parsed paths to those declarations and supplies the scope, location, name, and global-name rules that the request gate uses.

The registry pairs served types with Azure API versions from azure/providers.json. It fails at startup when two surfaces claim one namespace, a type is declared twice, or a declaration is not present in the Azure catalog. This keeps provider discovery and request governance based on the same type set.

Resource types describe broad scope kinds: resource-group, subscription, tenant, or extension. They can also declare name syntax and global-name behavior, so request validation and name ownership use the same type metadata as routing. Nested types inherit the resource-group model and do not claim a separate location unless their declaration says otherwise. An action path can therefore use the parent resource type even when it does not name a new resource.

References: src/…/ArmResourceType.java• L6-77 src/…/ArmScopeKind.java• L3-12 src/…/ArmSurface.java• L5-23 src/…/ArmSurfaceProvider.java• L5-15 src/…/ArmTypeRegistry.java• L18-29 src/…/ArmTypeRegistry.java• L116-149 src/…/ProviderCatalog.java• L15-26

Scope ownership

An ArmScope is the subscription and optional resource group addressed by a request. A stored resource belongs to a resource-group scope only when both parts match without regard to case. A subscription-only path owns no resource because resources in this model belong to a group.

This ownership check protects names that are global in Azure, such as storage accounts, vaults, managed HSMs, and web apps. A read or child request through another scope becomes 404; a create through another scope becomes a name conflict. The ownership check and create are kept together so concurrent creates cannot assign one global name to two scopes.

References: src/…/ArmScope.java• L5-29 src/…/ArmHandler.java• L929-942

Resource state keys

ARM resource maps carry internal subscription and resource-group keys for local ownership and index work. These keys are removed before a response reaches a client. The base public index entry contains resource identity, location, and non-empty tags, but not local routing state.

Provider contributors can add a fuller stored body when management clients need provider properties. This separation lets one stored resource support scope checks, generic listing, and deletion without leaking emulator-only fields into the ARM contract.

References: src/…/ArmResources.java• L6-16 src/…/ArmResources.java• L18-50 src/…/ArmResources.java• L71-77 src/…/ArmHandler.java• L322-331

ARM resource stores

The ARM resource store gives a service one consistent view of persisted resources while ARM treats IDs as case-insensitive. It writes each resource under a lower-case canonical ID, keeps the request's spelling inside the value for responses, and scopes reads and lists by subscription and resource group.

The store also provides a migration path for older key layouts. It can read legacy entries, chooses the newest entry when old keys differ only by case, and moves the resource to its canonical key on the next write or delete. A typed store can share one backend with other resource types without reading or deleting their entries.

For child cleanup, the store can return resources below a parsed parent ID. This gives resource-group deletion and extension-resource handling a direct index view without scanning unrelated resource bodies.

References: src/…/ArmResourceStore.java• L26-49 src/…/ArmResourceStore.java• L125-189 src/…/ArmResourceStore.java• L196-251 src/…/ArmResourceStore.java• L264-341

Resource indexes

The generic ARM resource index gives clients one view of resources across provider types. It combines resources from built-in handlers with entries supplied by enabled providers, then applies the supported client filter before returning a subscription or resource-group listing.

Index contributors

ResourceIndexContributor is the shared contract for a service that wants its resources to appear in generic listings. Each contributor supplies entries for both subscription and resource-group scopes and declares whether its service is enabled.

StoreIndexSource is the store-backed form of this contract. It takes one scope-based index method and uses it for both resource-group and subscription listings, so the two views cannot drift apart when they come from the same resource store.

A contributor can stay out of the default listing while remaining visible to resource-group deletion when the matching parity behavior is enabled. This keeps generic listing compatibility separate from deletion safety. A service that omits the contributor contract can leave a group appearing empty even when provider resources remain.

References: src/…/ResourceIndexContributor.java• L6-18 src/…/ResourceIndexContributor.java• L23-48 src/…/StoreIndexSource.java• L6-23

Generic resource listings

The ARM service builds subscription and resource-group listings through one assembly path. Built-in handler state and enabled contributor state enter the same view, and internal scope keys are removed before the response is returned. Resource-group deletion can request the wider contributor view so that resources hidden from the default listing are still removed.

The $filter query narrows this shared view by supported identity, location, group, and tag fields. An unsupported expression returns 400 InvalidFilter instead of being ignored. This prevents a client from treating an unfiltered resource as the wrong provider type.

References: src/…/ArmHandler.java• L301-319 src/…/ArmHandler.java• L322-358 src/…/ArmResourceFilter.java• L12-30

ARM service surface

The ARM service is the shared management surface for tenant and subscription discovery, cloud location discovery, provider registration, resource listings, resource-group control, and provider resource delegation. The router sends specific provider paths to their owners, while ArmHandler answers common management paths and delegates provider actions when needed.

ARM surface declarations

An ARM surface declares one provider namespace, its routing lane, and the resource types that the service answers. A resource type declaration also carries its scope, location policy, name syntax, and global-name policy. The shared Microsoft.Resources surface declares resource groups and resource-group deployments. Deployment behavior is described in ARM deployments.

These declarations are metadata used across routing, type matching, location checks, name checks, global-name checks, and the Providers API. They keep the public provider inventory aligned with the resource types that management handlers can serve.

References: src/…/ResourcesArmSurface.java• L13-30 src/…/ArmResourceType.java• L18-45

Provider discovery

The Providers API reports the namespaces that floci-az serves, the resource types under each namespace, supported API versions, locations, and registration state. Registration and unregistration are idempotent and return the final provider state at once. A namespace that the emulator does not serve is not presented as an available provider and returns 404 InvalidResourceNamespace when requested directly.

The location list for a subscription comes from its cloud profile. GET /subscriptions/{sub}/locations exposes the same cloud region names and display names that provider metadata uses, with the location metadata and availability-zone mappings expected by ARM clients. This keeps location discovery and resource validation based on one cloud catalog.

References: src/…/ProviderService.java• L19-34 src/…/ProviderService.java• L51-114 src/…/AzureLocations.java• L15-26 src/…/AzureLocations.java• L38-69 src/…/AzureLocations.java• L72-91 src/…/ArmHandler.java• L170-220 src/…/ArmHandler.java• L478-502

ARM routing lanes

Provider services can enter through a direct filter lane or through the ArmHandler provider lane. The provider-lane contract maps one or more namespaces to a service and can also allow that service to answer subscription-level paths. A namespace belongs to one lane so one request has one owner.

Provider claims are assembled at startup and duplicate namespace claims fail fast. A disabled provider is treated as unavailable, so a generic route returns the normal ARM not-found response instead of exposing a disabled resource. All lanes still use the request gate. See Core routing and authentication for the wider routing context.

References: src/…/ArmLane.java• L3-10 src/…/ArmProviderService.java• L8-50 src/…/ArmHandler.java• L109-143 src/…/ArmHandler.java• L363-398

Shared management operations

The ARM handler provides the common operations that tools need before they manage provider resources. These include tenant and subscription discovery, location discovery, provider registration checks, resource listings, name-availability checks, and resource-group operations.

Provider-lane services answer the resource actions that belong to their namespaces. This split keeps common directory and index behavior in one ARM surface while allowing each provider to preserve its own management and data-plane contract. Broader management scopes are covered in Management groups.

References: src/…/ArmHandler.java• L156-263 src/…/ArmHandler.java• L420-502

Internal resource dispatch

Resource-group deletion sends each indexed resource through the same routing and handler path used by a client. It parses resources that belong to the target subscription and group, orders nested resources before their parents, treats an already missing resource as complete, and continues after other resource failures. The group is removed only after the cascade finishes.

Services that keep group-scoped state outside the generic resource index can implement ResourceGroupCleanup. The resource-group service calls these cleanup hooks after the group is removed, so state such as deployment history does not outlive the group.

This shared dispatch preserves provider side effects during cleanup. The delete returns 202 with a poll URL after the cascade, while the first valid poll returns success because the cascade is complete before the operation is reported.

References: src/…/ResourceGroupCleanup.java• L3-12 src/…/ResourceGroupService.java• L162-221

Resource-group lifecycle

Resource groups form the main container boundary for ARM resources. Their names are case-insensitive within a subscription, while the latest PUT spelling is used in responses. Tags and managedBy remain part of group state and can be updated without replacing fields that a PATCH omits.

Group persistence

Groups are kept in memory by default. When resource-group semantics are enabled, they use the directory storage mode and can survive a restart with tenant and subscription directory state. The resource stores managed by the ARM handler remain separate, so persistence settings must be understood together with the selected parity behavior.

References: src/…/ResourceGroups.java• L26-34 src/…/ResourceGroups.java• L55-63 src/…/ResourceGroups.java• L202-235

Group deletion

With resource-group deletion behavior enabled, deletion marks the group before it lists resources, waits for admitted writes, cascades through the resource index in deepest-first order, and then removes the group. A missing resource does not stop the cascade. Other resource failures are logged and do not prevent group removal. The service then notifies components that keep state outside that index.

The delete returns 202 with a Location and Retry-After. The cascade is complete before that response, so a valid operation-result poll returns success. Without this behavior, deletion removes only the group and invokes cleanup hooks. Resources left in service indexes can still be discovered by generic listing. This difference is controlled by the parity settings described in Core routing and authentication, which provides the broader request, scope, and configuration context.

References: src/…/ResourceGroups.java• L136-185 src/…/ResourceGroupService.java• L162-195 src/…/ResourceGroupService.java• L197-233

Change checklist

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

  • Keep gate rule order unique and preserve the scope checks that must happen before provider work.
  • Keep body buffering, body amendments, and strict or tolerant parsing aligned across rules and handlers.
  • Keep resource type declarations, provider catalog entries, API versions, location policy, and Providers API output aligned.
  • Keep resource type name rules and global-name declarations aligned with the service's stored IDs, conflict responses, and cloud data-plane scope.
  • Keep ARM path parsing, case-insensitive ownership, and canonical index keys aligned when adding a resource type or extension path.
  • Strip internal resource keys from every client response and preserve the body shape required by contributors that clients use for provider lookups.
  • Keep ARM resource stores' canonical and legacy-key behavior aligned when changing a persisted resource ID or sharing a backend between types.
  • Keep provider namespace ownership in one routing lane and preserve startup failure for duplicate claims.
  • When changing resource-group deletion, keep the index, internal dispatch, cleanup hooks, write admission, and operation-result contract aligned.
  • When changing parity behavior, check both default listings and the contributor view used by group deletion.
  • When changing subscription first-use registration, preserve the caller tenant context so the new subscription enters the correct directory scope.
  • When changing resource-group auto-creation, preserve the location precedence used for the new group: response location, normalized request location, then cloud default.
  • When changing a store-backed index contributor, keep resource-group and subscription listings derived from the same scope view.
  • When changing cloud location catalogs, keep /subscriptions/{sub}/locations, provider metadata, location validation, and availability-zone data aligned.

Important failure modes

TriggerConsequenceGuard
A gate rule claims an existing orderStartup fails instead of applying an ambiguous check orderArmRequestGate rejects duplicate rule positions
A location is appended after the first location checkA resource can be stored with a value that strict location mode should rejectAppendedLocationRule checks a changed body location again
A strict name rule is added without matching type metadataInvalid resource names reach the provider or a valid name is refused under the wrong ruleResourceNameRule reads the rule from the matched ArmResourceType
A global name is reserved but the create failsA name remains blocked for later createsGlobalNameRule releases the reservation on a non-2xx response
Two resources create one global name at the same timeBoth creates can appear successful while sharing one DNS nameGlobalNameRegistry treats pending reservations as taken
A global-name source omits stored claims during registry rebuildA restart or reset can make an existing name appear availableGlobalNameRegistry rebuilds from every GlobalNameSource
A delete releases a global name while a same-resource PUT is still storing itAnother resource can take a name still used by the recreated resourceGlobalNameRegistry defers release until in-flight puts end and checks stored state
A resource store reads only canonical keysResources written by an older service version disappear from reads or cleanupArmResourceStore indexes legacy entries and moves them on write
A typed store ignores resource type ownership on a shared backendOne provider can read or delete another provider's resourceArmResourceStore limits canonical and legacy access to its declared type
A served type is missing from the provider catalogStartup fails instead of advertising incomplete provider metadataArmTypeRegistry validates each declared type against providers.json
An unknown subscription reaches strict subscription modeThe request returns 404 SubscriptionNotFoundSubscription scope checks run before the handler
A write reaches a read-only subscriptionThe request returns 409 ReadOnlyDisabledSubscriptionSubscription state and method are checked at gate entry
A child request reaches a missing group in strict modeThe provider does not run and the request returns 404 ResourceGroupNotFoundResource-group scope rules reject the call before dispatch
A successful child PUT creates a group with the wrong location sourceThe group location differs from the resource or request cloudAuto-creation uses response location, normalized request location, then cloud default
A resource-group delete races with a child writeA resource can outlive its group or be missed by the cascadeGroup deletion marks the group and waits for admitted writes
A cascade sees a provider failure other than 404The group can still be removed while the failed resource remains in provider stateThe cascade logs the failure and continues; provider cleanup must match the shared delete contract
A service keeps group state outside the resource index and has no cleanup hookThe deleted group leaves service-specific state behindResourceGroupCleanup is called after group removal
A provider skips resource-index contributionGeneric tools can see an empty group and delete it incorrectlyResourceIndexContributor requires both scope listings
An unsupported $filter is ignoredA client can parse a resource as the wrong provider typeThe resource filter returns 400 InvalidFilter
Two services claim one provider namespaceStartup fails instead of choosing an arbitrary ownerARM routing tables reject duplicate claims
Internal subscription or group keys reach the responseLocal storage details leak into the ARM resource contractArmResources.stripInternal runs before serialization
A store-backed contributor builds its two listings from different pathsSubscription and resource-group views can disagree about the same resourceStoreIndexSource derives both methods from one indexEntries(ArmScope) method
A cloud location catalog changes without matching ARM location outputProvider metadata and /locations can report different regions or zone dataAzureLocations builds location responses from the cloud profile and shared catalog data
A lenient ARM operation receives the JSON literal nullThe request returns 400 InvalidRequestContent instead of reaching a handler with a null mapArmJson.parseBodyLenient raises InvalidBodyException for the null value

Key files

FileWhy to read it
src/…/ArmRouter.javaShows ARM base-path routing, provider lanes, and internal dispatch
src/…/ArmRequestGate.javaDefines the shared entry and exit boundary for ARM governance
src/…/ArmProviderService.javaDefines the provider-lane contract and namespace ownership
src/…/ArmCall.javaDefines the request context shared by rules and handlers
src/…/ArmTypeRegistry.javaConnects declared resource types with path matching and provider metadata
src/…/ArmResourceType.javaDefines the shared scope, location, name, and global-name metadata for a type
src/…/ArmJson.javaDefines strict, tolerant, and mutable request-body parsing for ARM handlers
src/…/ResourceGroupRule.javaGates child requests, admits writes during deletion, and creates implicit groups after successful child PUTs
src/…/LocationRule.javaDefines location normalization, inheritance, and strict validation
src/…/NameRule.javaDefines reusable resource-name syntax and error metadata
src/…/GlobalNameRegistry.javaCoordinates global-name ownership, reservations, concurrency, and rebuilds
src/…/GlobalNameRule.javaConnects global-name ownership to the ARM request gate
src/…/ArmResourceId.javaDefines ARM path identity, nesting, extensions, and canonical keys
src/…/ArmPaths.javaProvides shared path extraction and provider-path matching behavior
src/…/ArmResourceStore.javaDefines canonical resource persistence, legacy-key recovery, and scope lists
src/…/ArmResources.javaDefines public index entries and internal-key removal
src/…/ResourceIndexContributor.javaDefines how provider services join generic ARM listings
src/…/StoreIndexSource.javaConnects one store-backed scope view to both generic ARM listings
src/…/ResourceGroupCleanup.javaDefines cleanup for group-scoped state outside the generic resource index
src/…/ArmHandler.javaProvides the shared ARM management surface, indexes, and provider delegation
src/…/ProviderService.javaDefines provider discovery, registration, API versions, and locations
src/…/AzureLocations.javaBuilds subscription location responses from cloud region data and ARM location metadata
src/…/ResourcesArmSurface.javaDeclares the shared Microsoft.Resources resource types and routing lane
src/…/ResourceGroupService.javaShows group operations, deepest-first cascade deletion, cleanup hooks, and poll results
src/…/ResourceGroups.javaShows group scope keys, persistence choice, and deletion/write coordination