APIM Global Policy Implementation
This page documents the global Rome APIM policy as deployed. It is based on
the Terraform and environment policy files under
rome-ion/infrastructure/spoke/apim, rather than on a generic APIM design. The V3
global policy is the V2 global policy; nothing in its control flow has changed.
What has changed is the V3 standard for X-Authorization and the edge, which the
policy does not yet meet.
The global policy authenticates the caller, validates customer-tenant status,
creates trusted request context, applies backend concurrency, forwards the
request, and invokes shared trace fragments. Product, API, and operation policies
extend this baseline through <base />.
Source and environment selection
Terraform selects one policy file using the environment short code:
module "rome-apim-global-policy" {
depends_on = [module.rome-apim, module.rome-apim-policy-fragments]
source = "<approved-api-management-policy-module>"
api_management_id = module.rome-apim.apim_id
apim_policy_globals = {
customer_concurrency = 20
}
apim_policy = {
apim = "${path.cwd}/apim_policies/apim_global_policy_${var.environment_short}.xml"
}
}
The deployed files are apim_global_policy_apa.xml,
apim_global_policy_bta.xml, apim_global_policy_gma.xml, and
apim_global_policy_prd.xml. Their control flow is equivalent, but their
allowed audiences and backend concurrency are environment-specific.
| Environment | Policy suffix | Per-API concurrency | MFE UI audience in list |
|---|---|---|---|
| Alpha | apa | 30 | ✓ |
| Beta | bta | 30 | ✓ |
| Gamma | gma | 200 | ✓ |
| Production | prd | 200 | ✗ |
The Terraform input customer_concurrency = 20 does not determine the hard-coded
XML values. This drift, carried over from V2, must be resolved before treating
that input as authoritative.
Deployed execution flow
The initial tid parse is only routing input for tenant lookup. It is not an
authentication decision. Trust is established only after validate-jwt
succeeds. The tenant-validation URL is built from the fixed
{{APIM-TENANT-VALIDATION-URL}} base with only the parsed tid appended
(Verified), so the unvalidated claim cannot select an arbitrary host. The tid
format is not validated before use.
Note that there is no X-Azure-FDID step in this flow (gap APIM-02).
Inbound execution order
| Order | Policy implementation | Effective behavior | Failure behavior |
|---|---|---|---|
| 1 | check-header | Requires a case-sensitive Authorization header. | APIM returns 401 Not authorized. |
| 2 | set-header | Preserves a caller-supplied X-Transaction-Id; otherwise generates a time/GUID-based value. | Policy evaluation fails if the expression cannot execute. |
| 3 | TryParseJwt in set-variable | Parses the bearer value without validating it and reads tid into jwt-tid. | Missing or unparseable tid is traced and returns 401. |
| 4 | set-variable | Builds the tenant-validation URL, cache key, and Ontinue-tenant flag. | Subsequent tenant processing fails closed. |
| 5 | cache-lookup-value | For a non-Ontinue tenant, checks cached active status. | A miss invokes tenant validation. |
| 6 | send-request with HEAD | On a cache miss, calls the tenant-validation API using the primary APIM UAMI and the {{APIM-AZURE-AD-APPLICATION-ID}} audience. | Request failure enters on-error; non-200 status becomes inactive. |
| 7 | cache-store-value | Caches the Boolean result for {{APIM-TENANT-CACHE-DURATION}} (1,800 seconds). | Missing/false status returns a traced 401. |
| 8 | validate-jwt | Validates the bearer token against the organizations and Ontinue OpenID metadata, environment audiences, tenant-bound v1 and v2 issuers, signature, and lifetime. Stores the validated token as jwt. | APIM rejects the token and enters error processing. |
| 9 | choose claim checks | Requires roles and tid claims. | Each missing claim is traced and returns 401. |
| 10 | choose token-type check | Rejects idtyp=app for non-Ontinue tenants; customer traffic must be user traffic. | Traced 401. |
| 11 | set-header override | Overwrites X-Tenant-Id with tid from the validated JWT. | Request does not proceed with an untrusted tenant header. |
| 12 | set-header skip | Sets Authorization to itself with exists-action="skip". Because the header always exists here, this is a no-op. | None. API policy later overrides Authorization for the backend. |
| 13 | set-header skip | Copies Authorization to X-Authorization only if X-Authorization is absent. | Gap APIM-01: a client-supplied X-Authorization survives unchanged. |
| 14 | set-header override | Overwrites Forwarded with original scheme, host, and path. | No local rejection. |
| 15 | include-fragment | Invokes the request trace fragment. | Fragment failure enters on-error. |
Tenant activation sub-flow
The deployed tenant lookup is skipped for the Ontinue tenant. Every other tenant uses a cache-first validation call:
<cache-lookup-value
key="@(context.Variables.GetValueOrDefault<string>("jwt-tid-cache-key", "NIL"))"
variable-name="jwt-tid-cache-value" />
<choose>
<when condition="@(!context.Variables.ContainsKey("jwt-tid-cache-value"))">
<send-request
mode="new"
response-variable-name="tenant-state"
timeout="20"
ignore-error="false">
<set-url>@(context.Variables.GetValueOrDefault<string>("tenant-validation-url", "NIL"))</set-url>
<set-method>HEAD</set-method>
<authentication-managed-identity
resource="{{APIM-AZURE-AD-APPLICATION-ID}}"
client-id="{{APIM-MSI-CLIENT-ID}}"
ignore-error="false" />
</send-request>
<set-variable
name="jwt-tid-cache-value"
value="@(((IResponse)context.Variables["tenant-state"]).StatusCode == 200)" />
<cache-store-value
key="@(context.Variables.GetValueOrDefault<string>("jwt-tid-cache-key", "NIL"))"
value="@((bool)context.Variables["jwt-tid-cache-value"])"
duration="{{APIM-TENANT-CACHE-DURATION}}" />
</when>
</choose>
Only HTTP 200 means active. Unknown, inactive, or unavailable tenant state must
not silently become authorized. The 30-minute cache duration bounds how quickly
customer offboarding takes effect at this layer.
JWT validation
The real policy contains an environment-specific audience list. The sanitized shape is:
<validate-jwt
header-name="Authorization"
require-scheme="Bearer"
require-signed-tokens="true"
output-token-variable-name="jwt">
<openid-config url="https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration" />
<openid-config url="{{APIM-ONTINUE-OPENID-CONFIGURATION-URL}}" />
<audiences>
<audience>{{APIM-PORTAL-API-AUDIENCE}}</audience>
<audience>{{APIM-PLATFORM-API-AUDIENCE}}</audience>
<audience>{{APIM-INTERNAL-API-AUDIENCE}}</audience>
<audience>{{APIM-MFE-UI-AUDIENCE}}</audience> <!-- apa, bta, gma only -->
</audiences>
<issuers>
<issuer>{{APIM-ONTINUE-V1-ISSUER}}</issuer>
<issuer>{{APIM-CALLER-TENANT-V1-ISSUER}}</issuer>
<issuer>{{APIM-ONTINUE-V2-ISSUER}}</issuer>
<issuer>{{APIM-CALLER-TENANT-V2-ISSUER}}</issuer>
</issuers>
</validate-jwt>
The placeholders above are illustrative. The deployed files hard-code the audience GUIDs and Ontinue issuer, which is why the policy is per environment. The production file also has development comments listing application names and IDs; they should be removed.
Global policy checks that a roles claim exists; operation policy decides which
Ion.* role authorizes a route. Possessing any role is therefore not sufficient
to invoke any operation, provided the operation template enforces its role
(see APIM-05).
Headers after global inbound policy
| Header | Deployed source | Trust and use |
|---|---|---|
Authorization | Original caller bearer token | Validated at global scope. API or operation policy later overrides it with an APIM UAMI token for backend OAuth. |
X-Authorization | Copy of the original caller bearer token, unless the client already sent one | Caller context for the receiving service. Not trustworthy until APIM-01 is fixed; backends must validate it. Must not be logged, stored, or propagated. |
X-Tenant-Id | tid from the validated JWT | Trusted gateway-derived tenant context. The backend must still enforce its customer and operation rules. |
X-Transaction-Id | Caller value or generated value | End-to-end correlation. Services propagate it to dependent calls. |
Forwarded | Original scheme, host, and path | Routing context; not an authorization grant. |
Relationship to product, API, and operation policy
After global inbound completes, inherited policy executes:
- For MFE APIs, the product policy rate-limits, applies the tenant quota, and
validates the capability token with Signet, failing closed with
403. - API policy selects the backend and applies API-level rate limits.
- API or operation policy obtains a token using an approved APIM UAMI and
overrides backend
Authorization. - Operation policy rewrites the URI and requires the operation’s
Ion.*role. - The inherited global backend section forwards the request.
The original caller token and backend token have different purposes. The first authorizes caller-to-APIM access. The second authenticates APIM to the OAuth-protected compute resource.
Backend, outbound, and error sections
The deployed backend section isolates concurrency by context.Api.Id, emits a
trace containing backend URL, API ID, and operation ID, and forwards with a
120-second timeout:
<backend>
<limit-concurrency key="@(context.Api.Id)" max-count="${environment_concurrency}">
<trace source="ION Platform API Request" severity="information">
<message>ION Platform APIM Concurrency Request</message>
<metadata name="BackendEndpointUri" value="@(context.Request.Url.ToString())" />
<metadata name="ApiId" value="@(context.Api.Id)" />
<metadata name="OperationId" value="@(context.Operation.Id)" />
</trace>
<forward-request timeout="120" fail-on-error-status-code="true" />
</limit-concurrency>
</backend>
fail-on-error-status-code="true" routes backend 4xx and 5xx responses
through APIM error processing. The outbound section invokes
fragment-response-trace; the on-error section invokes
fragment-error-trace.
Trace fragments: deployed behavior and required target
The fragments are installed before global policy because the global policy references them by ID.
| Fragment | Deployed behavior | Required safe target behavior |
|---|---|---|
| Request | Uses existing jwt, or parses X-Authorization before Authorization. Logs correlation/request IDs, preferred_username, oid, aud, azp, all non-auth request headers, original URI, and the full request body. | Log bounded route, correlation, outcome, and timing metadata. Do not log raw claims, broad headers, or request bodies by default. |
| Response | If jwt is absent, attempts token parsing. Logs non-auth response headers, rate-limit counters, status/reason, and the full response body. | Log bounded status, timing, cache, and rate-limit metadata. Do not log response bodies or broad headers by default. |
| Error | Logs identity claims and roles when available, request and response headers, rate-limit values, URLs, full response body, and serialized APIM error details. | Log a stable error category, policy location, status, route, and correlation ID. Minimize identity and exception detail and never emit customer payloads. |
The response fragment’s fallback reads X-Authorization and then, when that value
is not NIL, replaces it with Authorization (Verified, unchanged from V2).
This inverted condition can select the backend APIM token instead of the caller
token. It is a defect, not a pattern to reproduce.
The fragments exclude Authorization and X-Authorization from their header
dumps, but their identity and body capture is unsafe for a shared customer
platform. Because webhook APIs include fragment-request-trace without a
validated jwt, the fragment also logs provider payloads. For Twilio, that
includes caller phone numbers (gap APIM-03). New policies MUST follow the
minimized trace example in Policy authoring.
Public health bypass
Policy inheritance depends on <base />. The public GET and HEAD health
operation policies deliberately omit it from inbound, apply an IP rate limit,
and return a synthetic response without calling a backend.
<inbound>
<rate-limit-by-key
calls="200"
renewal-period="60"
counter-key="@(context.Request.IpAddress)" />
<return-response>
<set-status code="200" reason="OK" />
<set-body>{ "status": "Healthy" }</set-body>
</return-response>
</inbound>
Authenticated health includes <base />, requires the health-read role, and
returns a synthetic result. Neither operation proves backend readiness. The other
reviewed exceptions are the provider webhook APIs, which
bypass global inbound authentication but retain global backend, outbound, and
error inheritance. No ordinary protected operation may omit global inbound
inheritance.
Known implementation risks
These findings describe deployed behavior. They do not relax the API Management Guidelines. Rows without a new ID are V2 risks carried forward; their status is as of 2026-10-15.
| ID | Severity | Risk | Current implementation | Required disposition | Status |
|---|---|---|---|---|---|
| APIM-01 | High | Caller-controlled X-Authorization (V2 carry-over) | Global policy uses exists-action="skip" (apim_global_policy_prd.xml, lines 240–242). Identity docs previously claimed APIM always overwrites it. | Change to exists-action="override" in all four environment files. Add a negative test that an injected header is replaced. | Open |
| APIM-02 | High | Direct gateway access bypasses the Front Door WAF | No global X-Azure-FDID check or ip-filter; classic Standard tier without VNet. Conflicts with SEC-4 and ADR-0015, including its priority-2 failover-origin exception. | Add a global check-header on X-Azure-FDID = {{APIM-FRONT-DOOR-ID}} before check-header Authorization, returning 403. Exempt only the public health operations. | Open |
| APIM-03 | Medium | Excessive trace data (V2 carry-over), now including webhook payloads | Fragments capture bodies, claims, and broad headers. The Twilio and Graph webhook APIs include fragment-request-trace. | Replace with bounded, redacted telemetry and controlled sampling. Remove body-logging fragments from webhook and unauthenticated APIs now. | Open |
| APIM-04 | Low | Notifications to a personal mailbox | Autoscale notification targets an individual’s email. | Route to an owned team channel or action group. | Open |
| APIM-05 | Medium | Operation roles not enforced in Signet | Signet’s apim-api-operation.xml rewrites the path and acquires the MI token but has no role check, so roles_csv is ignored. The signet-int /v1/validations route therefore accepts any globally-valid token and can act as a capability-validation oracle. | Add the standard role choose block to the template, and restrict signet-int to the APIM identity or an explicit role. | Open |
| — | Low | Concurrency configuration drift | Terraform supplies 20; XML hard-codes 30 or 200. | Make one configuration source authoritative and test rendered policy. | Open |
| — | Low | Unvalidated tenant pre-routing | tid is parsed before JWT validation to select tenant status. The base URL is a fixed named value. | Validate tid format before use and keep authorization dependent on validated JWT. | Partially mitigated |
| — | Medium | Original token copied broadly | Global policy creates X-Authorization for every inherited route. | Keep, per the amended ADR-0014, but only after APIM-01 is fixed so the value is APIM-owned. Routes that need no caller context should override it with APIM’s token. | Accepted with condition |
| — | Low | Response trace fallback | Inverted condition can choose the wrong token for parsing. | Correct the condition or remove token parsing from response tracing. | Open |
| — | Medium | Large global audience catalogue | One global list accepts several application audiences; production lacks the MFE UI audience. | Keep lists environment-controlled, pair every route with explicit operation or capability authorization, and add the MFE UI audience to production at go-live. | Open |
Validation checklist
For each environment, verify:
- missing
Authorizationreturns401; - malformed tokens and tokens without
tidfail closed; - inactive, unknown, and unavailable customer tenants are denied;
- valid Ontinue tokens skip customer-tenant lookup;
- signature, lifetime, issuer, and environment audience are validated;
- missing
rolesandtidclaims are denied; - external-tenant application tokens are denied;
X-Tenant-Idcomes only from the validated token;- a client-supplied
X-Authorizationis replaced (APIM-01); - a request without the expected
X-Azure-FDIDis denied (APIM-02); - every protected API and operation inherits global policy;
- operation policy requires the intended
Ion.*role (APIM-05); - API or operation policy replaces backend
Authorizationwith the expected APIM UAMI token; - concurrency and timeout match the approved environment configuration;
- only public health and reviewed webhook APIs bypass global inbound authentication; and
- traces contain no bearer tokens, customer payloads, unnecessary identity data, or unrestricted exception details (APIM-03).