Cloud

Azure Application Gateway: validate JWT before trusting injected identity

A pre-production runbook for qualifying Application Gateway JWT validation with Entra token canaries, 401/403 evidence, backend trust boundaries and rollback.

04 Nov 2026 azureapplication-gatewayjwtentra-ididentitysecurityobservabilitykqlcanaryrunbookrollbackproduction

An internal API already sits behind Azure Application Gateway. Its backend validates Microsoft Entra access tokens, while the gateway handles TLS, routing and WAF inspection. The platform team now wants to enable JWT validation at the gateway so invalid requests are rejected before they consume backend capacity.

The change looks local, but it moves part of the authentication boundary. A wrong audience can deny every client, an Allow action can forward an invalid token without identity context, and a backend that accepts the injected identity header through another route can turn a useful edge control into a bypass.

JWT validation for Application Gateway is currently a preview without an SLA and Microsoft does not recommend it for production workloads. This runbook therefore treats the feature as a pre-production qualification: preserve backend validation, canary the policy on a bounded route, prove the trust boundary, then decide whether to keep the experiment, extend it later under an approved preview policy, or roll it back.

Freeze the authentication contract

Start from the API contract, not the portal form. Record which clients request tokens, the expected tenant and audiences, the listener and routing rule that expose the API, and the authentication control that remains in the backend.

yaml 01-jwt-validation-contract.yml
change: CHG-2026-1104-22
gateway: agw-shared-preprod
listener: api-preprod-https
route: orders-api-canary
backend: orders-api-preprod

token_contract:
issuer_tenant: <tenant-guid>
accepted_audiences:
  - api://<orders-api-client-id>
required_client_types:
  - service-principal-canary
  - developer-cli-test

controls:
gateway_invalid_token_action: Deny
backend_token_validation: enabled
backend_direct_access: denied
preview_exception: <approved-reference>

rollback:
owner: platform-on-call
action: detach-jwt-validation-from-canary-route
deadline_minutes: 10

Do not use common, organizations or a broad audience because it makes the first test pass more easily. Use the tenant and audience that the API actually owns. If a multi-tenant design is intentional, list its accepted issuers and negative tenants explicitly.

Prove the gateway can validate before testing clients

The current preview requires a Standard_v2 or WAF_v2 gateway, an HTTPS listener and Azure Resource Manager API version 2025-03-01 or later. The Application Gateway subnet also needs outbound TCP 443 connectivity to login.microsoftonline.com.

That egress dependency belongs in the validation plan. A correct client token can still fail if DNS, UDR, NSG, firewall or TLS inspection prevents the gateway from reaching Microsoft Entra endpoints. Do not widen all outbound traffic when the first request returns 401.

text 02-prerequisite-gate.txt
CONTROL PLANE
Gateway SKU is Standard_v2 or WAF_v2
Listener is HTTPS and certificate is valid
JWT configuration is attached to the intended routing rule
Deployment uses an API version that supports JWT validation

NETWORK PATH
Application Gateway subnet resolves login.microsoftonline.com
UDR sends TCP 443 through the approved egress path
NSG and firewall allow only the required documented dependency
Firewall logs show the canary window and expected source subnet

TRUST BOUNDARY
Backend is reachable only through approved gateway paths
Backend token validation stays enabled during preview qualification
Client-supplied identity header behavior is tested explicitly
Logs distinguish gateway rejection from backend rejection

Private Endpoint is not the subject of this change. If the backend uses one, it can help close the direct path, but it does not validate the caller’s token or prove that the JWT configuration is attached to the correct gateway rule.

Build a token canary matrix

A single successful token proves almost nothing. Acquire tokens through the same flows used by real clients, decode only non-secret claims for the test record, and vary one property at a time. Never place complete bearer tokens in tickets, shell history or logs.

text 03-jwt-canary-matrix.txt
CASE                         EXPECTED GATEWAY RESULT   BACKEND RESULT
Valid tenant and audience    forwarded, identity header  backend validation succeeds
Missing Authorization header 401, no identity header     not reached
Malformed bearer token       401, no identity header     not reached
Expired token                401, no identity header     not reached
nbf in the future            401, no identity header     not reached
Wrong audience               401, no identity header     not reached
Wrong tenant or issuer       401, no identity header     not reached
Token without oid            403, no identity header     not reached
Forged identity header only  rejected or sanitized       never trusted by backend
Valid token on other route   existing behavior unchanged no regression

For a valid request, the gateway injects x-msft-entra-identity with a tenantId:oid value. Treat that header as authentication context, not as application authorization. The API still needs to decide whether the identity may read an order, start a job or change production state.

The negative header test is essential. Send x-msft-entra-identity without a valid token and through every reachable backend path. Promotion is blocked until the team proves that an external caller cannot choose the trusted identity value and that no DNS name, public endpoint or alternate load balancer bypasses the gateway.

Separate gateway 401/403 from backend denials

Run each case with a correlation identifier and a narrow UTC window. Capture the client status, gateway access event and backend request count. A gateway rejection should not appear as an authenticated backend call.

kusto 04-correlate-jwt-401-403.kql
let Start = datetime(2026-11-04T15:00:00Z);
let End = datetime(2026-11-04T15:20:00Z);
AzureDiagnostics
| where TimeGenerated between (Start .. End)
| where ResourceType == "APPLICATIONGATEWAYS"
| where Category == "ApplicationGatewayAccessLog"
| extend Status = toint(column_ifexists("httpStatus_d", 0)),
       Host = tostring(column_ifexists("host_s", "")),
       Uri = tostring(column_ifexists("requestUri_s", "")),
       ClientIp = tostring(column_ifexists("clientIP_s", "")),
       TransactionId = tostring(column_ifexists("transactionId_g", ""))
| where Host == "api-preprod.example.net"
| where Uri startswith "/jwt-canary/"
| summarize Requests=count(),
          Statuses=make_set(Status, 10),
          FirstSeen=min(TimeGenerated),
          LastSeen=max(TimeGenerated)
  by ClientIp, Uri, TransactionId
| order by LastSeen desc

Adapt the field names to the diagnostic table and ingestion mode. The query locates the request; it does not prove why a token failed. Keep the expected claim set beside the canary result, then use the gateway diagnostic detail to distinguish issuer, audience, lifetime, missing bearer header and missing oid.

If all cases return 401, verify policy placement and gateway egress before changing client code. If only one client fails, compare its iss, aud, exp and nbf claims with the frozen contract. If the gateway forwards the request but the backend returns 403, investigate application authorization rather than weakening JWT validation.

Keep preview failure modes bounded

Attach the configuration to one pre-production routing rule or hostname. Do not replace backend authentication, remove an APIM policy or expose the backend directly during the same change. Those edits destroy the comparison path and make rollback ambiguous.

Use a short observation window that includes normal token renewal. Watch four signals: gateway 401/403 rate, backend request volume, successful canary latency and Entra/gateway egress failures. A fall in backend traffic is healthy only when it corresponds to expected negative cases.

The Allow action for invalid tokens is useful only for a deliberate observation scenario. It forwards the request without the injected identity header. It must not be interpreted as successful authentication, and a backend using the header must fail closed when it is absent.

Decide hold, extend or roll back

Keep the canary only when every positive case reaches the backend, every negative case is rejected as designed, the injected identity cannot be forged through another path, and backend validation remains authoritative. Document the preview acceptance, supported regions and operational owner before any broader exposure.

Roll back by detaching the JWT validation configuration from the canary routing rule and restoring the recorded rule association. Re-run the valid and invalid cases to confirm that the previous backend behavior is back. Do not delete the Entra application registration or change its audience during rollback; those are separate controls and would hide the original fault.

The closing decision has three outcomes:

  1. Keep the bounded pre-production canary when the contract and trust boundary are proven.
  2. Hold the rollout when gateway egress, token claims, logs or bypass prevention remain ambiguous.
  3. Roll back the route association when valid clients regress or invalid identity context reaches the backend.

Conclusion

Gateway JWT validation is valuable when it rejects bad traffic early without becoming an undocumented source of identity. The feature changes where authentication evidence is produced, so the test must cover more than one valid token.

Freeze the tenant and audience contract, exercise negative tokens, correlate gateway and backend evidence, and prove that the injected header is trustworthy only on a non-bypassable path. Until the preview posture changes, preserve backend validation and keep the experiment reversible.