Skip to main content

Policy Model and Attachment

A policy changes how the gateway treats traffic without touching the service behind it: who may call, how much, how long the gateway waits, what happens when the backend fails.

Why policies sit at the gateway​

  • One enforcement point. A rule holds for every instance of the service, whatever its language or version.
  • Rejected early. An unauthenticated or throttled request never reaches the integration and costs it nothing.
  • Changed without a build. A policy is applied in seconds; the integration is neither rebuilt nor restarted.

Policy families​

Policies are grouped by the side of the gateway they act on. Knowing the family tells you where a rule is configured and what it can affect.

FamilyControlsRulesReference
Security policyWho may callJWT, OIDC, API key, Basic, CORS, IP rules, external authorizationSecurity Policy
Backend traffic policyHow the gateway talks to the backendRate limit, timeouts, retries, circuit breaker, load balancingBackend Traffic Policy
Client traffic policyHow clients connect to the gatewayConnection limit, timeouts, TLS versions and ciphersClient Traffic Policy
Custom policyAnything else, in LuaScript on request and responseLua Policy
Route filtersThe request and response of one APIHeaders, URL rewriteRoute Filters

Attaching a policy to a gateway or an API instance​

A policy has a target: a whole gateway (it then covers every API on it) or one API instance.

TargetUse it for
GatewayA baseline every API must meet: TLS versions, a global connection limit, an IP allowlist
API instanceWhat is specific to one API: its authentication, its rate limit, its timeouts

Where a policy lives​

A policy is not a separate object to manage: it is deployed with the gateway or the API instance it protects.

  • It is added to the same application as its target, as one more component. In an API group, each API instance carries its own policies beside it.
  • It is named after its target and its family, for example orders-api-security-policy.
  • It depends on its target: the target is deployed first, and the policy is applied once the target is ready.
  • Applying the gateway or the API group applies its policies; deleting it removes them.

A gateway and an API instance are created with their policies already beside them, empty:

CreatedPolicies it starts with
GatewaySecurity, backend traffic, client traffic
API instance, on its own or in an API groupSecurity, backend traffic

An empty policy enforces nothing; it is there so that a rule can be added to it without creating anything first.

PolicyNumber per gateway or APICan be removed
SecurityOne, created with its targetNo: remove its rules instead
Backend trafficOne, created with its targetNo: remove its rules instead
Client traffic (gateways only)One, created with the gatewayYes
CustomOne, none by defaultYes

A gateway or an API carries at most one custom policy, named after its target, for example orders-api-custom-policy. Once it is activated, its tab shows where the script comes from and how long it is, not the script itself: Open the script shows it in an editor. Once it is changed there, a banner on the page says so and offers Save changes, which updates the policy itself, for every environment, and takes effect at the next Apply.

Adding a rule to a policy, activating one or deactivating one changes the application of its target, and takes effect at the next Apply.

A policy on an API replaces the gateway's, it does not add to it

When a policy of the same family targets both a gateway and one of its API instances, the API instance uses its own policy only. A JWT rule set on the gateway is no longer enforced on an API that has its own security policy without that rule: repeat in the API's policy what must still hold.

How rules combine inside a policy​

One policy holds several rules. How they combine differs per family.

FamilyCombination
Security policyEvery rule present must pass. CORS answers preflights before authentication
Backend traffic policyEach rule covers its own aspect; they do not conflict
Client traffic policyOne set of connection and TLS settings per target
Start with three rules

For an API open to applications: JWT authentication with the audience check, a rate limit, and a request timeout below the timeout of your callers. Add retries only for idempotent operations.

Consequences to anticipate​

Every rule changes what some callers receive. Decide on these effects before turning a rule on in production, and tell the teams that call the API.

RuleEffect on callersWatch
Authentication401 without valid credentialsPreflight OPTIONS requests carry none: add CORS
Rate limit429 beyond the limitThe limit is counted per gateway instance
Timeout504 when the backend is slowerLong-running calls, streaming, uploads
RetriesThe backend may receive the same request several timesNon-idempotent operations
Circuit breaker503 beyond the capsCaps too low for peak traffic

Configurations referenced by policies​

Several rules read a list or a credential stored once in Secret Manager:

RuleTemplate
API key authenticationAPI Keys
HTTP Basic authenticationBasic Auth Users
OIDC authenticationClient Credentials
Lua policy, stored scriptLua Script
Backend TLS, client certificateTLS Certificate
Make the configuration available first

A configuration can only be chosen in an environment it was made available to. The selectors of the policy forms offer to do it in place.

One page per rule, with its procedure and verification: Policy tasks.