Lesson 5 of 5 Securing Application Platform Services

Protecting Back-End APIs with API Management

This lesson explains how policies validate callers, limit use and authenticate to back ends.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose a token validation policy.
  • Distinguish rate limits from quotas.
  • Describe content validation.
  • Explain how a gateway authenticates to a back end.

API Management as a security layer

An API exposed directly must handle authentication, rate limits and validation by itself. Azure API Management moves those concerns to a gateway, so that a back end receives only requests that have passed its checks. Requests pass through policies, which are XML statements run in sections: inbound, backend, outbound and on-error.

The OWASP API Security Top 10 lists common API risks, such as broken object-level authorization and unrestricted resource consumption. API Management helps with many of them, although it cannot fix a flaw in a back end's own authorization logic. The Defender for APIs plan adds discovery and threat detection, and Microsoft also suggests a WAF in front and DDoS Protection.

The following diagram shows the policy sections a request passes through.

API Management as a security layer. Requests from clients pass through policies before a back end sees them. Inbound policies validate the caller, for example a JWT, limit use with rate limits and quotas, and validate content; the back-end section can authenticate to the API with a managed identity; outbound policies can remove headers that leak details. API Management cannot fix a flaw in the back end's own authorization logic.
The back end receives only requests that passed the checks.

Validating callers

Policies check who is calling. The following table describes the main ones.

PolicyPurposeKey point
validate-azure-ad-tokenValidates a token issued by Microsoft Entra IDThe preferred policy for Entra tokens
validate-jwtValidates any JSON web tokenUse for other identity providers; a failure returns 401 by default
validate-client-certificateChecks a client's certificateFor mutual TLS with callers
ip-filterAllows or denies caller addressesA coarse filter, to be used with identity
check-headerRequires a header with a given valueA simple check, not real authentication

A subscription key identifies a client application, for tracking and throttling. It is not a strong proof of identity, since it is a shared secret, so a sensitive API should also demand a token. The following policy validates a Microsoft Entra token, and requires a specific audience and role claim.

<inbound>
    <base />
    <validate-azure-ad-token tenant-id="TENANT_ID">
        <audiences><audience>api://orders</audience></audiences>
        <required-claims>
            <claim name="roles" match="any"><value>Orders.Read</value></claim>
        </required-claims>
    </validate-azure-ad-token>
</inbound>

The validate-jwt defaults are strict: an expiration time and a signed token are required, and clock skew is zero.

Match the pairs

Caller validation policies

Exam skills 3.3.9

Match each API Management policy with its purpose.

Log in to try this activity Interactive activities are free with an account.

Limiting use

Limits protect a back end against overload, and they make abuse more expensive. Candidates should know the differences among the following policies.

PolicyLimitsKey byExceeded response
rate-limitCalls in a short windowSubscription429
rate-limit-by-keyCalls in a short windowAny expression, such as an IP address or claim429
quotaCalls or bandwidth over a long periodSubscription403
quota-by-keyCalls or bandwidth over a long periodAny expression403
limit-concurrencySimultaneous callsA key429

A rate-limit policy applies only when an API is called with a subscription key, with a renewal period of up to 300 seconds. To limit callers by something else, such as a client address on a public API with no subscription, use rate-limit-by-key. Counts are tracked per gateway.

Sort into groups

Which limit policy?

Exam skills 3.3.9

Choose the limiting policy for each requirement.

Log in to try this activity Interactive activities are free with an account.

Validating content

Attackers send unexpected content to back ends. validate-content checks a request body against an API schema and size limit, validate-parameters checks query and path values, validate-headers checks response headers, validate-status-code checks response codes, and validate-graphql-request checks GraphQL. Each can run in a detection or prevention style, so that a team can observe first.

Outbound policies also matter. set-header can strip headers that reveal back-end technology, such as X-Powered-By, and cors controls which browser origins can call the API.

Authenticating to the back end

A gateway also needs to prove itself to the back end, and the back end should trust only the gateway. The options are as follows.

  • authentication-managed-identity obtains a token with the gateway's managed identity, for a resource named in the resource attribute, and sets it as a Bearer token. Without client-id, it uses the system-assigned identity.
  • Mutual TLS presents a client certificate to the back end, kept in Key Vault, from where it rotates automatically within four hours, or uploaded as a PFX file. With a Key Vault firewall, a system-assigned identity and the trusted services bypass are needed.
  • Network isolation places the gateway in a virtual network, so that the back end allows only that subnet, or uses a private endpoint.
<backend>
    <authentication-managed-identity resource="api://orders-backend" />
    <base />
</backend>

Anyone who can edit a policy can use the gateway's managed identity, so restrict who can edit policies, just as with Logic Apps.

True or false

Gateway to back end

Exam skills 3.3.9

Check how API Management authenticates to the back end.

Log in to try this activity Interactive activities are free with an account.
Worked example

Protecting an orders API

A public API issues Microsoft Entra tokens to customers' applications. The company must reject calls without a valid token and the Orders.Read role, limit each client to 60 calls a minute based on the client ID in the token, and stop the back end from being reached directly. No secret may be stored for the back-end connection. What policies and settings do you need?

Use validate-azure-ad-token with audience and role claims. Use rate-limit-by-key with a counter key based on the token's client ID, since plain rate-limit keys on subscriptions. Use authentication-managed-identity for the back end, and configure the back end, through Easy Auth or network rules, to accept only the gateway.

validate-jwt would work, but Microsoft recommends the Entra-specific policy for such tokens. A subscription key would not satisfy the requirement for role-based access. A mutual TLS certificate would store a credential, which the scenario wishes to avoid.

Check yourself

Which policy limits a public API's callers by client IP address with no subscription key?

Show answer

rate-limit-by-key, with a counter key based on the address.

Exam Tips

Remember for the exam

  • Use validate-azure-ad-token for Entra tokens, and validate-jwt for others.
  • rate-limit needs a subscription key; rate-limit-by-key does not.
  • Rate limits return 429; quotas return 403.
  • authentication-managed-identity avoids a stored back-end credential.