APIM Deployment and Debugging
APIM failures should be isolated by policy scope and authentication leg. Preserve the correlation identifier, status, API, operation, and deployment revision; do not capture bearer tokens as troubleshooting evidence.
Deployment order
- Deploy or verify backend OAuth and the expected audience.
- Provision the selected APIM UAMI and backend permission.
- Deploy required named values and fragments.
- Import the OpenAPI contract.
- Apply API policy.
- Apply every operation policy.
- Apply API diagnostics.
- Run positive and negative tests.
- Reconcile OpenAPI operations with deployed operation policies.
A service deployment must not depend on manual policy edits in the Azure portal.
Failure isolation
| Symptom | Likely boundary | Checks |
|---|---|---|
401 before API policy | Global caller authentication | Header, scheme, signature, expiry, issuer, audience, required claims |
| Customer tenant rejected | Global tenant policy | Tenant claim, active onboarding state, validation dependency, cache state |
403 for one operation | Operation policy | Terraform map key, OpenAPI operationId, required Ion.* role, role assignment |
| All operations hit wrong host | API policy | Backend base URL and environment variables |
| One operation hits wrong path | Operation policy | Rewrite template and unmatched parameters |
Backend 401 | APIM → backend authentication | APIM token audience, selected UAMI, backend OAuth configuration |
Backend 403 | Backend authorization | APIM principal/application role and backend authorization policy |
| Direct backend call succeeds anonymously | Backend platform authentication | Authentication enabled, unauthenticated action, excluded paths |
| Stale or cross-context response | Cache policy | Tenant/customer variation, query/header variation, duration, invalidation |
| Missing trace | Diagnostic or fragment | Logger, API diagnostic, fragment inheritance, sampling, destination access |
| Policy deployment rejected | XML/template | XML escaping, valid section/scope, named values, template variables, <base /> |
| Gateway overload or timeout | Traffic/backend | Rate key, concurrency, backend latency, APIM capacity, 120-second forwarding limit |
Distinguish the two token legs
Caller to APIM
Inspect only safe metadata: expected issuer category, expected audience category, tenant classification, whether the required claim exists, and authorization result. Do not paste or decode a production token into change records or logs.
APIM to backend
Verify the selected APIM identity, requested backend audience, backend OAuth allowed principals, and backend application role. A valid caller token does not prove that APIM can authenticate to the backend.
Safe tracing procedure
- Generate or capture
X-Transaction-Idfrom a controlled test request. - Identify the environment, API, operation, time window, and expected outcome.
- Find the APIM request/error trace by correlation ID.
- Find backend telemetry using the same correlation ID.
- Compare policy stage, response code, backend URL category, and authorization outcome without exposing headers or token payloads.
- Record the root cause, policy/deployment revision, and retest result.
APIM tracing can expose request and response content if policies are overly broad. Do not enable body or header capture as an ad hoc production debugging shortcut.
Required validation matrix
| Test | Expected result |
|---|---|
No Authorization header | 401 at APIM |
| Invalid signature or expired token | 401 at APIM |
| Wrong audience or issuer | 401 at APIM |
| Unknown or inactive customer tenant | Denied before backend |
| Valid token without operation role | 403 at operation policy |
| Valid caller and role | Request reaches intended protected backend |
| APIM UAMI lacks backend grant | Backend authentication/authorization failure |
| Anonymous direct backend request | Rejected by platform OAuth |
| Caller-supplied trusted context header | Overwritten or ignored by APIM |
| Same cache inputs in different tenants | No cross-tenant cache reuse |
| Public synthetic health | Successful without exposing backend state |
| Authenticated health without role | Denied |
Rollback
Rollback the version-controlled API or operation policy and redeploy it. If the change introduced a new route or role, remove the route or assignment and verify denial. Do not fix production by retaining an untracked portal edit.
Policy rollback and OpenAPI rollback may need to be coordinated when operation IDs or paths changed. Preserve backward compatibility until callers have moved or remove the route deliberately.
Emergency containment
Depending on the incident, the owner can:
- block or remove one operation;
- remove an application-role assignment;
- disable an API or product association;
- remove the APIM identity’s backend permission;
- change backend OAuth allowed principals;
- stop the backend workload;
- restrict edge or network access; or
- disable customer tenant activation.
Account for APIM, Entra token, and application caches. When revocation cannot wait for expiry, combine identity revocation with route, workload, or network containment.
Retirement
- Notify and migrate callers.
- Remove edge routes and APIM operations.
- Remove operation and API policies.
- Remove API/product association and imported contract.
- Remove API diagnostics and logger resources used only by the API.
- Remove APIM backend role grants and unused named values.
- Disable and retire the backend according to its service lifecycle.
- Verify the gateway path and direct backend path are denied.
- Retain safe audit and change evidence according to policy.