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 / core-routing-auth

Core routing and authentication

floci-az presents one HTTP front door for Azure data-plane, management-plane, identity, and emulator-local requests. It identifies the target service and cloud, builds one request context, applies the right authentication and ARM checks, and returns a client-shaped response.

Request front door

The request front door separates local emulator endpoints from Azure-compatible routes. It captures transport data before work moves to a blocking worker, then lets an ordered set of route stages claim the request.

Request capture and dispatch

src/…/AzureRoutingFilter.java is the first Azure-facing request boundary. It keeps both the decoded path used for routing and the original path and query used by clients that need exact URL data. RouteDispatcher turns a route decision into a handler call and builds the shared AzureRequest that carries request, scope, and authentication state.

The main flow is:

flowchart TD
    A[HTTP request] --> B{Local health or admin path?}
    B -- yes --> C[JAX-RS local controller]
    B -- no --> D[Capture path host authority and peer]
    D --> E[Resolve cloud and ARM scope]
    E --> F[Run ordered route stages]
    F --> G{Route claims request?}
    G -- no --> H[Account or storage fallback]
    G -- yes --> I[Build AzureRequest]
    H --> I
    I --> J[Resolve development auth]
    J --> K[Invoke service handler]

The request context keeps the authority and peer address separate from the routing host. This lets handlers build correct URLs while avoiding trust in forwarded client identity data for the peer address. Repeated query values remain available for services whose requests use the same key more than once.

References: src/…/AzureRoutingFilter.java• L234-303 src/…/RouteDispatcher.java• L44-118 src/…/AzureRequest.java• L12-29

Route ownership

Route stages run in a fixed order because the same path can match more than one Azure convention. Specific host and identity routes run before broad ARM and account routes. Within ARM provider routing, guarded claims run before broad provider claims so nested resource paths remain deterministic. A route can answer the request, pass it to JAX-RS, or leave it for the next stage.

Route areaMain purpose
Host suffix and host service markerMap production-style and emulator-style service hosts to an account and service.
Managed identity and EntraServe token and identity discovery paths that do not use normal request authentication.
GraphServe the supported /v1.0/ directory API slice.
ARM-base data planeSupport Monitor, Key Vault, and ACS Email clients that send data-plane calls to the resource-manager host.
ARM provider and generic pathsSend management requests through provider ownership or the general ARM handler.
Service Bus and Cosmos compatibilityRecognize protocol and root paths used by their SDKs.
Account suffix fallbackResolve path-style accounts and distinguish blob from queue when no suffix names the service.

An unambiguous disabled service returns 503 ServiceDisabled instead of falling through and being interpreted as another service. Unknown or disabled provider routes can fall through to the generic ARM lane when that is the intended ownership model. Route declarations that collide fail at startup so ownership does not depend on discovery order.

References: src/…/AzureRoutingFilter.java• L46-79 src/…/AzureRoutingFilter.java• L130-195 src/…/AzureRoutingFilter.java• L348-505 src/…/ArmRouter.java• L103-132

Request context

AzureRequest is the handoff contract between the front door and a service. It contains the selected account and service, paths, headers, body, query values, transport details, resolved scope, and the authentication result. The filter resolves scope once, while the dispatcher resolves authentication once, so handlers use one consistent view of the request.

The request also records whether it is inside the ARM gate. This marker prevents an internal ARM delegation from applying ARM governance twice. Internal dispatch keeps the caller's authorization and scheme so a handler sees the same caller context as an external request.

References: src/…/AzureRequest.java• L32-127 src/…/RouteDispatcher.java• L85-118 src/…/ArmRouter.java• L146-191

ARM request governance

ARM management requests share a governance boundary even when different providers serve them. The ARM router selects the management lane, and the request gate applies common checks around the selected provider or generic ARM handler.

ARM route lanes

src/…/ArmRouter.java handles the paths that arrive at the ARM base URL. It keeps ARM-base data-plane paths separate from management paths, then gives registered provider namespaces a chance before the generic ARM handler. The provider table rejects duplicate namespace claims at startup and uses guarded routes before broad routes.

The management flow is:

flowchart LR
    A[ARM base request] --> B{ARM-base data plane?}
    B -- yes --> C[Monitor Key Vault or Email handler]
    B -- no --> D{Known provider namespace?}
    D -- yes --> E[Provider handler through gate]
    D -- no --> F{Subscription or tenant ARM path?}
    F -- yes --> G[Generic ARM handler through gate]
    F -- no --> H[ARM ResourceNotFound]

Diagnostic settings are treated as ARM extension resources even though they can sit below another resource provider. They therefore use the ARM gate. Monitor ingestion and query, Key Vault data paths, and Email data paths do not use that gate because they are data-plane operations rather than management operations.

See ARM resource governance for the provider, resource identity, and management policy contract. See ARM deployment orchestration for the deployment flow that uses this management boundary.

References: src/…/ArmRouter.java• L32-41 src/…/ArmRouter.java• L103-132 src/…/ArmRouter.java• L194-293

ARM request gate

ArmRequestGate is the common boundary around every ARM management handler. It creates an ArmCall with the resolved scope, resource identity, and normalized method. Ordered rules inspect that call before the handler runs and observe the response after it returns.

When a rule rejects a request, its response replaces the handler response and later rules are not entered. Exit hooks still run for every rule that entered, including when a handler or rule throws. A nested call passes through without entering the gate again.

References: src/…/ArmRequestGate.java• L18-28 src/…/ArmRequestGate.java• L47-103 src/…/ArmRequestGateTest.java• L59-118

Cloud and directory resolution

The front door resolves where a request belongs before it dispatches the request. Cloud profiles provide Azure endpoint and location facts, while the directory maps tenants and subscriptions to those clouds.

Cloud catalog

src/…/CloudCatalog.java loads the supported Azure cloud profiles once from the bundled catalog. The catalog covers Azure public, US Government, and China clouds. It supplies endpoint hosts, service DNS suffixes, audiences, locations, and metadata shapes used by request routing and configuration.

Cloud host matching uses the longest known suffix. Host names are compared without ports and without case differences. Location input is normalized to the cloud's canonical name when the catalog knows it; validation of whether a location is allowed belongs to the caller.

See cloud and directory configuration for the configuration contract and cloud-specific behavior.

References: src/…/CloudCatalog.java• L22-84 src/…/CloudCatalog.java• L237-305 src/…/CloudCatalogTest.java• L42-160

Scope resolution

ScopeResolver produces a ScopeContext for each request. It records the cloud and any tenant, subscription, or resource group named by the request. Resolution records the best available scope signal; it does not reject a mismatch.

Signals are considered in this order:

  1. An ARM subscription path resolves the subscription, its tenant, and that tenant's cloud.
  2. A tenant-rooted Entra path resolves the tenant's cloud. Shared aliases such as common do not name a tenant.
  3. A known Azure service host suffix resolves its cloud.
  4. A data-plane name or emulator host can resolve its owning cloud when a name registry supplies one.
  5. A catalog resource-manager or login host resolves its cloud.
  6. The configured default cloud is used when no stronger signal exists.

When tenant scoping is enabled, a JWT-shaped Bearer value can add the token's textual tid claim as an unverified tenant hint. TokenTenantHint only decodes that payload; it does not prove the token or its claims. Opaque tokens, malformed tokens, and tokens without a usable tid provide no hint. Tenant scoping is disabled by default, so the hint remains absent and callers use the prior default-tenant behavior.

The ARM gate, not the resolver, decides what an unknown subscription or a token from another tenant means. This keeps location discovery separate from access policy.

References: src/…/ScopeResolver.java• L21-46 src/…/ScopeResolver.java• L123-171 src/…/ScopeContext.java• L3-16 src/…/TokenTenantHint.java• L10-41

Directory state

AzureDirectory is the local source of tenant and subscription state. It starts with a default tenant and subscription, adds configured entries, and can register an unseen subscription on first use. IDs are case-insensitive, and a first-use subscription is placed under the requested tenant only when that tenant exists.

Configured entries are rewritten from current configuration at startup. First-use entries can survive a restart when the directory uses persistent storage. If a saved first-use subscription refers to a tenant that no longer exists, the directory moves it to the current default tenant so every listed subscription has a valid owner.

Listing order matters to clients that select the first enabled subscription. The default entry stays first, followed by configured entries and then first-use entries.

References: src/…/AzureDirectory.java• L27-42 src/…/AzureDirectory.java• L77-149 src/…/AzureDirectory.java• L152-239 src/…/DirectorySeed.java• L17-29

Authentication decisions

Authentication is a development compatibility layer, not a production identity system. Normal service routes pass the request through the authentication pipeline, while token endpoints that Azure clients call without an authorization header bypass it.

Authentication pipeline

AuthPipeline applies the AuthVerifier contract to the request in its configured verifier sequence. The first verifier that recognizes a credential supplies the AuthContext; when no verifier recognizes the request, the pipeline returns an anonymous context. This separates credential recognition from the service-specific checks that decide whether the request may perform an operation.

The current development decisions are:

Request credentialDevelopment behavior
Bearer tokenA header with the Bearer scheme is accepted as a valid bearer context. A JWT-shaped value may also provide an unverified tenant hint when tenant scoping is enabled.
SAS queryA request with SAS fields is recognized. Parseable start and expiry times can mark it invalid when outside its active window.
Shared keyA SharedKey account:signature header is recognized by its shape and supplies the account name. The signature is not verified here.
No recognized credentialThe request is anonymous.

Storage services can apply a stronger SAS authorization step after recognition. That step is where account keys, resource scope, permissions, and request constraints are enforced. IMDS and Entra routes skip the normal pipeline because their clients obtain credentials from those endpoints rather than send an authorization header.

The tenant hint does not authenticate the caller. It only selects the tenant view used during scope resolution, and strict authentication remains a separate responsibility.

These rules make local SDK use easy, but they do not provide cryptographic protection for an exposed deployment.

References: src/…/AuthPipeline.java• L12-30 src/…/AuthVerifier.java• L8-10 src/…/BearerTokenVerifier.java• L10-19 src/…/SharedKeyAuthVerifier.java• L11-27 src/…/TokenTenantHint.java• L10-41 src/…/SasTokenVerifier.java• L12-32

Bearer identity claims

BearerClaims reads usable identity fields from a bearer-token payload without validating its signature. The claim view gives ARM and log-producing features a caller identity when development authentication is enabled, but it does not change whether the request is authenticated.

The claim view can identify a user, application, or managed identity. It keeps the full claim set in both a string form for Activity Log output and a typed form for policy expressions that read request identity. It also maps the caller to the principal name, principal type, and object ID that ARM metadata uses. A missing or malformed bearer payload produces an empty claim view rather than a partial identity.

References: src/…/BearerClaims.java• L12-45 src/…/BearerClaims.java• L47-100 src/…/BearerClaims.java• L107-165

Readiness and error shaping

The local health surface is separate from Azure routing. It reports process health, startup readiness, service health, and local TLS diagnostics without allowing those paths to be reinterpreted as service requests.

Readiness state

EmulatorReadiness starts down, becomes ready only after startup observers finish, and returns to down as shutdown begins. GET /ready returns 503 until that point and during shutdown. The health endpoints can still report process and service problems, so an orchestrator can distinguish an alive process from one that is safe to receive work.

References: src/…/EmulatorReadiness.java• L13-48 src/…/HealthController.java• L44-79 src/…/EmulatorReadinessTest.java• L15-48

Azure error contracts

AzureErrorResponse keeps the common Azure error code and message while shaping the body for the client family that receives it. XML and normal JSON support common Azure clients. Data Lake uses a nested error object, and Table uses an OData envelope. All forms also expose x-ms-error-code so clients can identify the failure from the header.

Error responses to HEAD requests must not advertise a body. Successful HEAD responses keep their normal content type. This distinction prevents SDKs from trying to parse an empty error response as a document.

References: src/…/AzureErrorResponse.java• L10-58 src/…/BodylessErrorContentTypeFilter.java• L1-80

Change checklist

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

  • Keep route stage order aligned with route specificity. Provider and diagnostic-setting routes must not be swallowed by generic ARM routing.
  • Keep host suffix, account suffix, service marker, and ARM provider ownership unique. A collision must fail at startup rather than select a handler by discovery order.
  • Keep disabled-service behavior aligned with route certainty. An unambiguous route must return ServiceDisabled; an intentionally optional provider route may fall through.
  • Keep AzureRequest path, authority, repeated-query, scope, and ARM-gate fields aligned with handlers that sign requests or build downstream URLs.
  • Add every ARM management path to the gate, including extension resources that appear below another provider's resource ID.
  • Preserve cloud catalog suffix uniqueness and explicit unsettled values when cloud data changes.
  • Preserve directory ownership and ordering when changing default, configured, or first-use tenant and subscription state.
  • Keep token tenant hints clearly separate from authentication. A decoded tid must never become proof of identity or bypass ARM policy.
  • Keep bearer claim-to-principal mapping aligned with the ARM metadata and Activity Log fields that report the caller.
  • Keep the string and typed bearer claim views aligned with policy expressions and log formats that inspect request identity.
  • Keep AuthVerifier recognition rules aligned with the AuthContext that downstream services use for authorization.
  • Keep Bearer claim parsing separate from token acceptance. Reading a payload must never validate its signature or make a malformed token authenticated.
  • Keep SharedKey recognition limited to the SharedKey account:signature shape. It identifies the account but does not prove the signature.
  • Keep development authentication distinct from storage authorization. Recognizing a SAS is not the same as proving its signature or permissions.
  • Keep local health and readiness paths outside Azure route fallback so startup and shutdown status cannot become service requests.
  • Preserve the client-specific error envelopes for Data Lake, Table, XML, and JSON callers.

Important failure modes

TriggerConsequenceGuard
A new route is placed before a more specific routeA provider, identity, or data-plane request reaches the wrong handlerOrdered stages in AzureRoutingFilter and ArmRouter
Two handlers claim one suffix, marker, or provider namespaceStartup fails instead of routing by arbitrary discovery orderRouting-table and provider duplicate checks
A known service is disabled on an unambiguous URLThe request must return 503 ServiceDisabled, not become a storage requestRouteDispatcher.dispatchOrServiceDisabled
An ARM management route bypasses the gateProvider policy does not see the requestArmRouter uses the gated invocation for provider and generic ARM paths
A guarded provider route is treated as a broad routeA nested resource path can reach the wrong provider handlerGuarded provider claims are sorted before broad claims
A saved first-use subscription names a removed tenantDirectory listings contain a subscription with no listed ownerAzureDirectory moves it to the default tenant on load
A cloud suffix is missing or claimed by two cloudsCloud routing can use the wrong endpoint or fail at startupCloudCatalog validates suffix coverage and uniqueness
A forged or malformed JWT tid is treated as proof of caller identityA request can be viewed in a tenant scope without authentication having been establishedTokenTenantHint only supplies an unverified hint; ARM rules still enforce policy
A bearer claim is mapped to the wrong principal type or nameARM metadata and Activity Log entries report the wrong callerBearerClaims derives user, application, and managed identity fields without authenticating the token
A bearer claim with an array or object is flattened before policy reads itAn identity policy sees the wrong value type or contentBearerClaims keeps typed claim values alongside string forms
A malformed bearer payload is treated as a valid identity recordARM metadata can contain a partial or invented caller identityBearerClaims returns NONE when the payload cannot be read
A Bearer header uses a form the verifier does not recognizeThe request becomes anonymous even though a separate claim reader could parse the valueBearerTokenVerifier owns the acceptance rule; BearerClaims only reads claims
A SharedKey header is accepted as proof of account authorizationA caller can reach storage logic without signature validationSharedKeyAuthVerifier only recognizes the header shape; service authorization remains separate
A client sends an invalid or expired SAS that a handler trusts only from the auth contextThe handler can accept a request that the development recognizer marked invalidDownstream storage authorization checks AuthContext.isValid()
Readiness is reported before startup work completesAn orchestrator sends traffic to an emulator that is not readyEmulatorReadiness and HealthController.ready()
A service error uses the wrong body envelopeThe SDK loses the Azure error code or treats the response as malformedAzureErrorResponse client-specific response methods

Key files

FileWhy to read it
src/…/AzureRoutingFilter.javaDefines the HTTP front door, route order, local endpoint bypass, and final account fallback.
src/…/RouteDispatcher.javaShows how a route becomes an authenticated AzureRequest and how disabled services are handled.
src/…/AzureRequest.javaDefines the request context shared by handlers.
src/…/ArmRouter.javaSeparates ARM-base data-plane paths from provider and generic management paths, and defines deterministic provider ownership.
src/…/ArmRequestGate.javaDefines the common entry and exit boundary for ARM management requests.
src/…/ScopeResolver.javaExplains how request signals and optional token tenant hints select a cloud and ARM scope.
src/…/TokenTenantHint.javaDefines the unverified JWT tenant hint used only when tenant scoping is enabled.
src/…/AuthVerifier.javaDefines the credential-recognition contract used by the authentication pipeline.
src/…/AuthPipeline.javaDefines the development authentication decision chain and anonymous fallback.
src/…/BearerTokenVerifier.javaDefines development acceptance of Bearer credentials without signature validation.
src/…/BearerClaims.javaDefines the caller identity view used for ARM metadata, Activity Log claims, and typed policy identity values.
src/…/SharedKeyAuthVerifier.javaDefines SharedKey account recognition before service-specific authorization.
src/…/CloudCatalog.javaDefines the supported cloud profiles and endpoint facts.
src/…/AzureDirectory.javaDefines tenant and subscription state, first-use registration, and persistence behavior.
src/…/HealthController.javaDefines health, readiness, and TLS diagnostic responses.
src/…/AzureErrorResponse.javaDefines the error body variants used by Azure client families.