ION DocsV2
  • Architecture
    • ION Architecture V2
      • ION V2 — Architecture Overview
      • V2 context
        • V2 capacity model
        • V2 constraints
        • V2 integration boundaries
        • V2 requirements
        • V2 solution strategy
      • V2 Structural Design
        • ION V2 Landscape
        • ION V2 Platform Views
          • ION V2 Delivery and Runway
          • ION V2 Incident-Processing Pipelines
          • ION V2 Platform Networking
          • ION V2 Platform Observability
          • ION V2 Platform Security
        • ION V2 System Context
        • ION V2 Systems
          • Alya System Topology
          • Cogs System Topology
          • Ion IQ System Topology
          • Kingsman System Topology
          • Pigeon System Topology
          • Veritas System Topology
          • Watchtower System Topology
      • V2 evolution and platform lineage
        • Tiberium Origins
          • Tiberium Architecture Overview
          • Tiberium Components Architecture Overview
        • Voyager and the V2 Merge
          • Voyager Architecture Overview
          • Voyager Identity Architecture Overview
          • Voyager Services Architecture Overview
      • V2 Platform Architecture
        • Alya Workbench
          • Mission Brief: Alya (Workbench for Cyber Defenders)
        • Asset Discovery
        • Automation
        • Customer Communications
          • Notification and Escalation Design
        • Reporting and Dashboards
        • Vulnerability Mitigations
      • V2 Well-Architected
        • V2 Reliability
          • Availability Architecture
        • V2 Security
          • API Management
            • API Management Architecture
            • API Management Guidelines
            • API Management Implementation
              • APIM Deployment and Debugging
              • APIM Global Policy Implementation
              • APIM Platform Provisioning
              • APIM Policy Authoring
              • APIM Service Onboarding
              • APIM Webhook Flow Implementation
            • API Management Policy Model
          • V2 Security Architecture
          • Teams Notification Security
          • Customer Data and PII
          • V2 Identity
            • Applications and Authorization
            • V2 Identity Architecture
            • Microsoft Entra ID
            • V2 Identity Standard
            • V2 Identity Implementation
              • Application Registration
              • Application Roles
              • Customer Identity Onboarding
              • Identity Lifecycle and Operations
              • Managed Identity
            • V2 Identity Workflows
              • Alya Workbench Identity Workflow
              • Customer Portal Identity Workflow
              • Microservices Identity Workflow
              • ServiceNow Inbound Identity Workflow
              • Microsoft Teams Identity Workflow
          • Customer Environment Access
            • Customer Environment Access Architecture
            • Customer Environment Access Guidelines
            • Customer Environment Access How-to
    • ION Architecture V3
      • ION V3 Architecture Overview
      • V3 context
        • V3 capacity model
        • V3 constraints
        • V3 integration boundaries
        • V3 requirements
        • V3 solution strategy
      • V3 Structural Design
        • Data and events
          • Archival and retention
          • Event model
          • Event sourcing
          • Event store
          • Micro-frontend interaction
          • Recovery and disaster recovery
          • Replay and reconstruction
          • Reporting and customer analytics
          • Event-sourcing requirements
          • Snapshots
          • UI interaction
        • ION v3 domains
          • Assets domain
            • Assets domain flows
            • Assets domain implementation
            • Assets domain model
          • Customer Collaboration domain
            • Customer Collaboration domain flows
            • Customer Collaboration domain implementation
            • Customer Collaboration domain model
          • Incident domain
            • Incident domain flows
            • Incident domain implementation
            • Incident domain model
          • Investigation domain
            • Investigation domain flows
            • Investigation domain implementation
            • Investigation domain model
          • Remediation domain
            • Remediation domain implementation
            • Remediation domain model
          • Ticket domain
            • Ticket domain flows
            • Ticket domain implementation
            • Ticket domain model
        • ION V3 Landscape
        • ION V3 Platform Views
          • Internal API
            • Internal API architecture
            • Internal API consumer guide
            • Internal API identity and access
            • Internal API implementation
          • Micro-Frontends
            • Micro-Frontends architecture
            • Micro-Frontends capability service (Signet)
            • Micro-Frontends composition
            • Micro-Frontends identity and access
            • Micro-Frontends implementation
            • Micro-Frontends real-time (SignalR)
            • Micro-Frontends routing and ingress
            • Shells and MFEs
          • SOAR Integration
            • SOAR Integration architecture
            • SOAR Integration customer onboarding
            • SOAR Integration Identity and Access Design
            • SOAR Integration implementation
            • SOAR Integration operations
        • ION V3 System Context
        • ION V3 systems
          • Alya
          • Cogs
          • ION IQ
          • Kingsman
          • Pigeon
          • Veritas
          • Watchtower
      • V2 to V3 evolution
        • V2 to V3 architecture delta
        • V2 to V3 decision changes
        • V2 to V3 migration guidance
        • V2 to V3 service impact
      • Well-Architected
        • Cost Optimization
          • Cost Governance
            • Cost Governance Architecture
            • Cost Governance Guidelines
            • Cost Governance Implementation
          • SKU Strategy
            • SKU Strategy Architecture
            • SKU Strategy Guidelines
            • SKU Strategy Implementation
        • Operational excellence
          • Audit Logs
            • Audit Logs Architecture
            • Audit Logs Guidelines
            • Audit Logs Implementation
          • CI/CD Runway
            • CI/CD Runway Architecture
            • CI/CD Runway Guidelines
            • CI/CD Runway Implementation
          • Feature Flags
            • Feature Flags Architecture
            • Feature Flags Guidelines
            • Feature Flags Implementation
          • Incident management
            • Incident management architecture
            • Incident management guidelines
            • Incident management implementation
          • Azure Landing Zone
            • Azure Landing Zone Architecture
            • Azure Landing Zone Guidelines
            • Azure Landing Zone Implementation
          • Notifications
            • Notifications Architecture
            • Notifications Guidelines
            • Notifications Implementation
          • Observability
            • Observability Architecture
            • Observability Guidelines
            • Observability Implementation
        • Performance efficiency
          • Capacity, sizing, and scaling
            • Capacity, sizing, and scaling architecture
            • Capacity, sizing, and scaling guidelines
            • Implement capacity, sizing, and scaling
          • UI responsiveness
            • UI responsiveness architecture
            • UI responsiveness guidelines
            • Implement UI responsiveness
        • V3 reliability
          • Application resilience patterns
          • Critical flows
          • Customer reliability assurance
            • ION Platform reliability and service continuity
            • Customer reliability slides
          • Disaster recovery
            • Disaster recovery architecture
            • Disaster recovery guidelines
            • Disaster recovery implementation
              • DR implementation: API Management
              • DR implementation: App Configuration
              • DR implementation: Application Gateway
              • DR implementation: Azure SQL Database
              • DR implementation: Container Apps
              • DR implementation: Container Registry
              • DR implementation: Cosmos DB
              • DR implementation: Event Hubs
              • DR implementation: Azure Front Door
              • DR implementation: Function Apps
              • DR implementation: Key Vault
              • DR implementation: Log Analytics and Application Insights
              • DR implementation: MySQL Flexible Server (Temporal)
              • DR implementation: PostgreSQL Flexible Server
              • DR implementation: Azure Managed Redis
              • DR implementation: Service Bus
              • DR implementation: SignalR
              • DR implementation: Storage accounts
            • Operational-data replication
            • Disaster recovery operations
          • Edge and routing
            • Azure Application Gateway
              • Azure Application Gateway architecture
              • Azure Application Gateway guidelines
              • Azure Application Gateway implementation
              • Azure Application Gateway resiliency
              • Azure Application Gateway security
            • Azure Front Door
              • Azure Front Door architecture
              • Azure Front Door guidelines
              • Azure Front Door implementation
              • Azure Front Door resiliency
              • Azure Front Door security
          • Event-store disaster recovery (moved)
          • Failure mode analysis
          • Graceful degradation
            • Graceful degradation architecture
            • Graceful degradation guidelines
            • Graceful degradation implementation
          • V3 reliability maturity model
            • V3 reliability maturity assessment
            • Maturity level 2: self-preservation
            • Maturity level 3: recovery readiness
            • Maturity level 4: maintain stability
            • Maturity level 5: stay resilient
          • Multi-region replication
            • Multi-region replication architecture
            • Multi-region replication guidelines
            • Multi-region replication implementation assessment
          • Reliability testing
          • Scaling and headroom
          • Targets and health model
          • Trade-offs and accepted risks
        • V3 Security
          • API Management
            • API Management Architecture
            • API Management Guidelines
            • API Management Implementation
              • API Contracts and Asynchronous Operations
              • APIM Deployment and Debugging
              • APIM Global Policy Implementation
              • APIM Platform Provisioning
              • APIM Policy Authoring
              • APIM Service Onboarding
              • APIM Webhook Flow Implementation
            • API Management Policy Model
          • V3 Security Architecture
          • Data protection
            • Data protection architecture
            • Data protection guidelines
            • Data protection implementation guidelines
              • API Management
              • Application Gateway
              • Azure SQL Database
              • Azure Container Apps
              • Azure Cosmos DB
              • Azure Front Door
              • Azure Function Apps
              • Azure Database for MySQL
              • Azure Database for PostgreSQL
              • Data protection procedures
          • V3 Security Guidelines
          • V3 Identity
            • Applications and Authorization in ION V3
            • V3 Identity Architecture
            • Capabilities
            • Microsoft Entra ID for ION V3
            • V3 Identity Standard
            • V3 Identity Implementation
              • App Service Authentication
              • Application Registration
              • Application Roles
              • Customer Azure RBAC
              • Customer Identity Onboarding
              • Identity Lifecycle and Operations
              • Mailbox-Scoped Access
              • Managed Identity
              • Workload Identity Federation
            • V3 Identity Workflows
              • Alya Workbench Identity Workflow
              • Customer Azure RBAC Identity Workflow
              • Customer Portal Identity Workflow
              • Mailbox Access Identity Workflow
              • Microservices Identity Workflow
              • ServiceNow Inbound Identity Workflow
              • Shell and MFE Identity Workflow
              • Microsoft Teams Identity Workflow
          • Customer Environment Access
            • Azure Lighthouse
              • Azure Lighthouse implementation
            • GDAP and Tenant Governance
              • Access Packages (legacy)
              • GDAP human access implementation
            • Customer environment access guidelines
            • Multi-tenant Entra apps
              • Multi-tenant Entra apps implementation
            • Teams B2B Direct Connect
              • Teams B2B Direct Connect implementation
          • Network Security
            • Network Security Architecture
            • Network Security Guidelines
            • Network Security Implementation
              • Egress and Static IPs
              • Resource Access Restrictions
          • V3 Security Patterns
    • ION Architecture V4
      • How V4 evolves from V3
  • Principles
  • Patterns
    • Application Permissions Only
    • Async REST
    • Audit Logs (Pattern)
    • Auth / AuthZ
    • Dead Letter Queue (DLQ)
    • Dual Writes (and how to avoid them)
    • ECST — Event-Carried State Transfer
    • Event Hubs Throttling
    • Feature Flags (Pattern)
    • Idempotent Write
    • MFE UI Interaction
    • Notifications (Pattern)
    • Private Data Store Access
    • Schema Evolution
    • Service Bus Topic Throttling
    • UI Interaction with an Event-Sourced Backend
  • Standards
    • API Standard
    • API Standards
    • Coding Standard
    • Coding Standards
    • Documentation Standard
    • Documentation Standards
    • Microservice Standard
    • Microservice Checklist
    • Operational Readiness Standard
    • ORR — Operational Readiness Review Checklist
  • Decisions
    • ADR-0001
    • ADR-0002
    • ADR-0003
    • ADR-0004
    • ADR-0005
    • ADR-0006
    • ADR-0007
    • ADR-0008
    • ADR-0009
    • ADR-0010
    • ADR-0011
    • ADR-0012
    • ADR-0013
    • ADR-0014
    • ADR-0015
    • ADR-0016
    • ADR-0017
    • ADR-0018
    • ADR-0019
    • ADR-0020
    • ADR-0021
    • ADR-0022
    • ADR-0023
    • ADR-0024
    • ADR-0025
    • ADR-0026
    • ADR-0027
    • ADR-0028
    • ADR-0029
    • ADR-0030
    • ADR-0031
    • ADR-0032
    • ADR-0033
    • ADR-0034
  • Services
  • Governance
    • Assumptions
    • Discrepancies
    • V3 reference coverage and conflict matrix
OntinueION Docs
  1. Architecture
  2. ION Architecture V2
  3. V2 Well-Architected
  4. V2 Security
  5. API Management
  6. API Management Implementation
  7. APIM Policy Authoring

APIM Policy Authoring

security
VersionV2V3
architecturev2

APIM Policy Authoring

These samples show the deployed ION policy structure without publishing tenant, application, identity, or endpoint identifiers. Replace placeholders through Terraform variables or APIM named values. Do not paste environment values into policy XML.

Policy-order baseline

Every service policy inherits its parent scope:

<policies>
  <inbound>
    <base />
    <!-- Local inbound policy executes after inherited inbound policy. -->
  </inbound>
  <backend>
    <base />
  </backend>
  <outbound>
    <base />
  </outbound>
  <on-error>
    <base />
  </on-error>
</policies>

The placement of <base /> controls order. Removing it can remove global caller validation or the parent API’s managed-identity backend authentication.

Global policy pattern

The platform owns the complete environment global policy. The following reduced sample demonstrates its control flow; service teams must not copy it into API scope.

<policies>
  <inbound>
    <check-header
      name="Authorization"
      failed-check-httpcode="401"
      failed-check-error-message="Not authorized"
      ignore-case="false" />

    <set-header name="X-Transaction-Id" exists-action="skip">
      <value>@(Guid.NewGuid().ToString())</value>
    </set-header>

    <validate-jwt
      header-name="Authorization"
      require-scheme="Bearer"
      require-signed-tokens="true"
      output-token-variable-name="jwt">
      <openid-config url="{{APIM-OPENID-CONFIGURATION-URL}}" />
      <audiences>
        <audience>{{APIM-ALLOWED-AUDIENCE}}</audience>
      </audiences>
      <required-claims>
        <claim name="tid" match="all" />
        <claim name="roles" match="all" />
      </required-claims>
    </validate-jwt>

    <set-header name="X-Tenant-Id" exists-action="override">
      <value>@(((Jwt)context.Variables["jwt"]).Claims.GetValueOrDefault("tid", ""))</value>
    </set-header>

    <include-fragment fragment-id="fragment-request-trace" />
  </inbound>

  <backend>
    <limit-concurrency key="@(context.Api.Id)" max-count="200">
      <forward-request timeout="120" fail-on-error-status-code="true" />
    </limit-concurrency>
  </backend>

  <outbound>
    <include-fragment fragment-id="fragment-response-trace" />
  </outbound>

  <on-error>
    <include-fragment fragment-id="fragment-error-trace" />
  </on-error>
</policies>

Customer tenant activation is an additional global step in the deployed policy. It uses a cached managed-identity-authenticated HEAD request and denies inactive or unresolved customer tenants. See Global policy implementation for the full deployed sequence; this reduced sample is guidance, not a replacement for the platform-owned policy.

Service API policy

This is the standard API-level pattern. Global caller validation executes first; APIM then selects the service backend, applies rate limiting, acquires an APIM identity token for the backend audience, and replaces Authorization.

<policies>
  <inbound>
    <base />

    <set-backend-service base-url="${globals.backend_base_url}" />

    <set-variable
      name="rateLimitKey"
      value="@(context.Api.Id + &quot;-&quot; + ((Jwt)context.Variables[&quot;jwt&quot;]).Claims.GetValueOrDefault(&quot;oid&quot;, &quot;none&quot;))" />

    <rate-limit-by-key
      calls="${globals.rate_limit_calls}"
      renewal-period="60"
      counter-key="@(context.Variables.GetValueOrDefault&lt;string&gt;(&quot;rateLimitKey&quot;, &quot;none&quot;))" />

    <authentication-managed-identity
      resource="{{APIM-BACKEND-AUDIENCE}}"
      client-id="{{APIM-MSI-CLIENT-ID}}"
      output-token-variable-name="backend-access-token"
      ignore-error="false" />

    <set-header name="Authorization" exists-action="override">
      <value>@("Bearer " + (string)context.Variables["backend-access-token"])</value>
    </set-header>
  </inbound>

  <backend>
    <base />
  </backend>

  <outbound>
    <base />
    <set-header name="x-aspnet-version" exists-action="delete" />
    <set-header name="x-powered-by" exists-action="delete" />
  </outbound>

  <on-error>
    <base />
  </on-error>
</policies>

ignore-error="false" is mandatory: failure to acquire the APIM backend token must stop the request.

Operation role and rewrite policy

The operation map supplies the rewrite and role list. This example authorizes the request when the caller has any configured required role.

<policies>
  <inbound>
    <base />

    <rewrite-uri
      template="${globals.rewrite_template_path}"
      copy-unmatched-params="true" />

    <choose>
      <when condition="@{
        var jwt = (Jwt)context.Variables[&quot;jwt&quot;];
        if (!jwt.Claims.ContainsKey(&quot;roles&quot;)) {
          return true;
        }

        string[] callerRoles = jwt.Claims[&quot;roles&quot;];
        string[] requiredRoles = { ${globals.roles_csv} };
        return !requiredRoles.Any(requiredRole =&gt;
          Array.Exists(callerRoles, callerRole =&gt; callerRole == requiredRole));
      }">
        <set-variable name="X-Status-Code" value="403" />
        <set-variable name="X-Status-Reason" value="Forbidden" />
        <set-variable
          name="X-Last-Error"
          value="Required role is not present in the caller token." />
        <include-fragment fragment-id="fragment-error-trace" />
        <return-response>
          <set-status code="403" reason="Forbidden" />
        </return-response>
      </when>
    </choose>
  </inbound>

  <backend>
    <base />
  </backend>

  <outbound>
    <base />
  </outbound>

  <on-error>
    <base />
  </on-error>
</policies>

Do not put the caller’s full role list or token into the denial message or trace.

Optional response cache

Cache policy belongs at operation scope. Include tenant/customer variation for customer-dependent responses.

<cache-lookup
  allow-private-response-caching="true"
  caching-type="internal"
  vary-by-developer="false"
  vary-by-developer-groups="false">
  <vary-by-header>X-Tenant-Id</vary-by-header>
  <vary-by-header>Accept</vary-by-header>
  <vary-by-query-parameter>page[offset]</vary-by-query-parameter>
  <vary-by-query-parameter>page[limit]</vary-by-query-parameter>
</cache-lookup>

Store only successful, explicitly cacheable responses:

<choose>
  <when condition="@(
    context.Response.StatusCode == 200 &amp;&amp;
    string.Equals(&quot;${globals.cache_response}&quot;, &quot;true&quot;, StringComparison.OrdinalIgnoreCase)
  )">
    <cache-store duration="${globals.cache_duration}" />
  </when>
</choose>

A cache key that omits customer context can become a cross-customer disclosure.

Operation-specific backend override

An operation may route to another protected backend. It must still inherit the API and global policy chain. If the alternate backend has a different audience or approved APIM identity, explicitly acquire the correct token after selecting it.

<set-backend-service base-url="${globals.messaging_backend_base_url}" />

<authentication-managed-identity
  resource="{{APIM-MESSAGING-BACKEND-AUDIENCE}}"
  client-id="{{APIM-MSI-CLIENT-ID}}"
  output-token-variable-name="messaging-backend-token"
  ignore-error="false" />

<set-header name="Authorization" exists-action="override">
  <value>@("Bearer " + (string)context.Variables["messaging-backend-token"])</value>
</set-header>

Synthetic public health operation

Only a deliberately public synthetic health operation may omit <base /> in inbound policy to bypass global authentication. It must return no dependency or customer information.

<policies>
  <inbound>
    <return-response>
      <set-status code="200" reason="OK" />
      <set-header name="Content-Type" exists-action="override">
        <value>application/json</value>
      </set-header>
      <set-body>{ "status": "available" }</set-body>
    </return-response>
  </inbound>
  <backend />
  <outbound />
  <on-error />
</policies>

This reports gateway policy availability, not backend readiness. An authenticated health operation should use the normal <base /> chain and a health-read role.

External-provider webhook exception

A reviewed webhook API may omit inbound <base /> when its provider cannot present an ION bearer token. It must implement provider-specific sender validation, acquire an APIM UAMI token for backend OAuth, and continue to inherit global backend, outbound, and error policy. Do not adapt the synthetic-health pattern, because webhook requests reach application code.

The complete deployed Phoenix example and sanitized XML are in Webhook flow implementation.

Safe trace fragment

Trace bounded metadata rather than headers, token claims, or bodies.

<fragment>
  <trace source="ION API Gateway" severity="information">
    <message>APIM request</message>
    <metadata
      name="TransactionId"
      value="@(context.Request.Headers.GetValueOrDefault(&quot;X-Transaction-Id&quot;, &quot;none&quot;))" />
    <metadata name="ApiId" value="@(context.Api.Id)" />
    <metadata name="OperationId" value="@(context.Operation.Id)" />
    <metadata name="RequestId" value="@(context.RequestId.ToString())" />
  </trace>
</fragment>

Never add Authorization, X-Authorization, raw JWT data, secrets, or unredacted request/response bodies to a fragment.

Terraform operation-policy renderer

The service-local module renders one policy for each OpenAPI operationId:

resource "azurerm_api_management_api_operation_policy" "operation" {
  for_each = var.apim_api_operations_policy

  api_name            = var.api_name
  api_management_name = var.api_management_name
  resource_group_name = var.resource_group_name
  operation_id        = each.key

  xml_content = templatefile(each.value.file, {
    globals = merge(local.default_template_vars, each.value.vars)
  })
}

Defaults are convenience values, not permission decisions. A default role must not accidentally authorize an operation; reviewers must verify the explicit role for every mapped operation.

Authoring checklist

  • XML is valid and special characters in expressions are escaped.
  • <base /> appears in every inherited section at the intended order.
  • Named values replace environment-specific identifiers and URLs.
  • Managed-identity acquisition fails closed.
  • Caller and backend tokens are not confused.
  • Operation role behavior is explicit: any required role versus all required roles.
  • Cache variation preserves tenant and customer isolation.
  • Errors reveal no roles, token data, backend secrets, or internal exception text.
  • Trace metadata is bounded and contains no credentials or sensitive payloads.

On this page

  • Policy-order baseline
  • Global policy pattern
  • Service API policy
  • Operation role and rewrite policy
  • Optional response cache
  • Operation-specific backend override
  • Synthetic public health operation
  • External-provider webhook exception
  • Safe trace fragment
  • Terraform operation-policy renderer
  • Authoring checklist
PreviousAPIM Platform Provisioning
NextAPIM Service Onboarding
Edit on GitHubSecurity