APIM Service Onboarding
A service team owns the contract and APIM overlays for its service. The deployed pattern is used by Playfair, Bastion, and Bounded Context Config: OpenAPI import, API policy, operation-policy map, and API diagnostics are deployed from the service repository to the shared Rome APIM instance.
Required artifacts
<service>/
├── api/<service>.yaml
└── infrastructure-shared/
├── main-apim.tf
├── policies/apim-api-policy.xml
├── policies/apim-api-operation.xml
└── modules/apim/
Paths may vary, but ownership and deployed resources must remain explicit.
Step-by-step implementation
Define the API and security contract
Owner: Service team
Define each method, path, request, response, error, and stable operationId in
OpenAPI. Document the intended security requirement, but remember that OpenAPI
does not deploy APIM role enforcement by itself.
paths:
/v1/workspaces/{workspace-id}/summary:
get:
operationId: get-workspace-summary-v1
summary: Get a workspace summary
responses:
'200':
description: Successful response
'401':
description: Authentication failed
'403':
description: Authorization failedImport the OpenAPI contract
Owner: Service team
Use the approved API module to import the specification, define the gateway path, and associate the API with its product.
module "apim_api" {
source = "<approved-api-management-api-module>"
apim_product_id = local.apim_product_id
api_resource_name = local.apim_api_name
api_display_name = local.apim_api_display_name
service_name = local.service_name
resource_group_name = local.apim_resource_group_name
api_specification = "../api/service.yaml"
api_path = "service-int"
apim_name = local.apim_name
}The product groups the API; it is not a substitute for Entra tokens and roles.
Protect the backend with OAuth
Owner: Service team
Enable platform authentication on the Function App, App Service, Container App, Logic App, or other HTTP compute endpoint. Configure the expected audience and allow the selected APIM managed identity or backend application role.
Before continuing, prove that:
- an anonymous direct request is rejected;
- a token for another audience is rejected; and
- the approved APIM principal can authenticate.
Apply the API policy
Owner: Service team
Set the backend, rate limit, APIM managed identity, and outbound sanitization at
API scope. Keep <base /> so the service inherits global caller validation and
backend forwarding.
module "apim_api_policy" {
depends_on = [module.apim_api]
source = "<approved-api-management-api-policy-module>"
api_resource_name = local.apim_api_name
service_name = local.service_name
resource_group_name = local.apim_resource_group_name
apim_name = local.apim_name
apim_policy_globals = {
backend_base_url = "https://${azurerm_windows_function_app.api.name}.azurewebsites.net/api"
}
apim_api_policy = {
apim_api = "policies/apim-api-policy.xml"
}
}Use the complete XML baseline in Policy authoring.
Map every operation to authorization policy
Owner: Service team
The Terraform map key must exactly match the OpenAPI operationId. Declare the
backend rewrite, required roles, and cache behavior.
apim_api_operations_policy = {
get-workspace-summary-v1 = {
file = "./policies/apim-api-operation.xml"
vars = {
rewrite_template_path = "v1/workspaces/{workspace-id}/summary"
roles_csv = "\"Ion.Reporting.Read\""
cache_response = "true"
cache_duration = 60
}
}
}Reconcile the complete OpenAPI operation list against this map. An operation left unmapped still inherits global and API policy but may lack its role check, rewrite, or cache rule.
Configure safe diagnostics
Owner: Service team
Create the APIM Application Insights logger and API diagnostic using W3C
correlation. Always log errors, but minimize headers and body bytes. Do not log
Authorization, X-Authorization, raw claims, or sensitive bodies.
Use X-Transaction-Id to correlate the gateway request with backend telemetry.
Diagnostics and inherited policy traces together form the effective telemetry
surface, so review both.
Validate authorization and routing
Owner: Service and Security teams
Test at least:
- valid token, active tenant, and required role;
- missing and malformed token;
- wrong issuer and audience;
- inactive or unknown customer tenant;
- missing operation role;
- an OpenAPI operation with no policy mapping;
- incorrect backend rewrite;
- APIM managed-identity token acquisition failure;
- anonymous and unapproved direct backend access; and
- cache isolation across tenants and request variants where caching is enabled.
Keep correlation IDs and status outcomes as evidence; do not retain tokens.
Deploy and record ownership
Owner: Service team
Deploy through the approved environment pipeline. Record the service owner, contract revision, APIM API name, product, gateway path, backend category, selected APIM identity, required roles, diagnostic destination, test evidence, and rollback procedure.
Review checklist
- Every OpenAPI
operationIdhas intentional policy coverage. - API and operation policy sections retain
<base />. - Backend authentication uses APIM managed identity.
- Backend OAuth rejects anonymous direct access.
- Role names use the controlled
Ion.*catalogue. - Cache keys preserve customer isolation.
- Logging excludes credentials and sensitive payloads.
- API and backend can be revoked independently.