Plans
The policy lives in the plan; the route is a projection detail. One API carries one set of resources and as many plans as it needs, each with its own auth mechanism — adding a tier never touches the infrastructure.
Status
| Status | On the gateway | On the portal |
|---|---|---|
staging | projected; its extractor is not installed | hidden |
published | projected and enforced | shown, subscribable |
deprecated | projected and enforced: its consumers keep calling | shown, closed to new subscriptions |
closed | Otoroshi deletes the keys of its subscriptions | hidden |
An API without a published or deprecated plan is closed: the gateway refuses every call. An
open API publishes a keyless plan. The draft says so (no_served_plan).
Auth mechanism
| Kind | The consumer calls with | Configuration |
|---|---|---|
apikey | a client id / secret minted by the subscription | read only, automatic secret rotation (every N hours, with a grace period) |
oauth2-local | a token obtained from the gateway with the subscription's client id / secret | signing key pair, token lifetime |
jwt | its own JWT | a reference to an Otoroshi JWT verifier, or a description the product derives the verifier from (see below); client id claim (client_id) |
mtls | a client certificate | the trusted CAs (derived as certificates of the gateway, see below), subject and issuer DN regexes, client id field |
oauth2-remote | a token of a remote IdP, validated by an Otoroshi auth module | a reference to an auth module, or a description of the authorization server the product derives the module from (see below); client id claim; user profile |
keyless | nothing | the expression the caller identity is derived from (${req.ip}) — an ephemeral identity, so quotas still apply per caller |
Derived JWT verifiers
Instead of referencing a verifier that already exists on the gateway, a jwt plan can describe how
its tokens are validated — keys from a JWKS url, or an HMAC secret (a vault reference works), the
expected issuer and audience, the header and its prefix. The product then derives the Otoroshi
JWT verifier from the plan: written before the Api that references it, marked as the
product's own, part of the deployment diff and of drift detection, and removed when the plan stops
deriving it, or when the API is deleted.
auth:
kind: jwt
config:
clientIdPath: client_id
derive: { enabled: true, kind: jwks, jwksUrl: https://idp.example.com/.well-known/jwks.json, issuer: https://idp.example.com }
Trusted CAs of an mtls plan
An mtls plan lists the CA certificates (PEM, no private key) that sign its consumers'
certificates. The product derives each of them as a certificate of the gateway, marked as its
own, and removes it when the plan stops listing it or when the API goes. The console reads each
certificate — subject, CA or not, validity — and shows the DN Otoroshi will compare.
The gateway's TLS trust is global: it holds every certificate of the gateway plus the JDK CAs, so a
certificate from any public authority completes the handshake. The plan is tied to its own CAs: they
are projected as its trusted_ca_refs, and the chain of a client certificate has to lead to one of
them, whatever the handshake trusts. The subject and issuer DN patterns, when given, must all
match (dn_match: all).
Without trusted CAs, the plan accepts a certificate from any authority the gateway trusts — among
them the client certificates of the applications
that have an active subscription to an mtls plan, derived for that time — and an issuer pattern
only compares text anyone can write in a certificate of their own: the draft warns
(no_trusted_ca). The plan reads the CN of
the certificate as the client id by default; without a client id field, the gateway names a
consumer after its whole certificate and no application can be reconciled with it.
Two gateway settings decide whether the plan can work at all, and the deployment dry run says so:
the gateway must ask callers for a client certificate (TLS client auth Want or Need), and if
it trusts a fixed list of CAs (trustedCAsServer), the derived ones must be on it. Both belong to
the gateway's operator.
auth:
kind: mtls
config:
clientIdField: CN
trustedCAs:
- |
-----BEGIN CERTIFICATE-----
MIID…
-----END CERTIFICATE-----
The authorization server of an oauth2-remote plan
An oauth2-remote plan validates tokens issued by a remote authorization server, through an
Otoroshi auth module (Otoroshi names the field verifier; it holds an auth module id). Instead of
referencing a module that exists, the plan can describe the server — Discover reads its
.well-known/openid-configuration — and the product derives the module: keys from the JWKS url,
the userinfo url when the plan fetches the user profile, client id and secret when the server needs
them. Same life as every derived object: marked, diffed, watched for drift, removed with the API.
The plan names the issuer its tokens carry (filled by Discover) and the audiences one of
which they must carry: a token the same server issued for another client, or for another API, is
refused. Without either, the plan accepts any token signed with the keys of the server, and the
draft warns (token_claims_not_checked).
auth:
kind: oauth2-remote
config:
clientIdPath: sub
issuer: https://idp.example.com
audiences: [books]
derive: { enabled: true, discoveryUrl: https://idp.example.com/.well-known/openid-configuration, jwksUrl: https://idp.example.com/jwks }
On jwt, mtls and oauth2-remote plans the application must declare its expected client_id,
and the gateway serves only the client ids of enabled subscriptions: a valid token or
certificate alone is not a subscription. A caller the plan does not serve falls to the next plan
of the API — a keyless plan serves it as any anonymous caller — or is refused (401).
The gateway names the consumers of these plans after the API and the plan
(jwt_<api>_<plan>_<client id>): two APIs may have plans of the same id, their consumers are
distinct, and they leave with their API.
Resolution order
When several plans are published, the gateway tries them in the order of its extractors — it is not freely chosen, so the console shows it rather than hiding it:
| Kind | Extractor index |
|---|---|
apikey, oauth2-local | 2.00 |
jwt | 2.01 |
mtls | 2.02 |
oauth2-remote | 2.03 |
keyless | 900 — always last |
"If you present a valid key you are on your tier, otherwise you fall back on the open access."
Two apikey plans are told apart by the key itself. Two jwt, mtls, oauth2-remote or keyless
plans that can both match need a selection on all but one of them, or the draft does not
publish. Between plans of the same kind, the order of the plans decides: the first one that
identifies the caller wins, so the plan without a selection comes last (selection_shadowed
otherwise).
A selection is a list of JSON path conditions, all of which must hold, on the request, the claims of the token, the client certificate or the client id the plan read:
- id: plan_gold
auth: { kind: jwt, config: { verifier: idp } }
selection:
- { path: $.token.tier, value: gold }
- id: plan_free
auth: { kind: jwt, config: { verifier: idp } }
A value can be Regex(…), Contains(…), Not(…)… A plan whose selection fails identifies no
one, and the next plan gets the call. Deprecated plans are served, and count.
Availability and isolation
- Counter failure strategy: what happens when the distributed quota counter cannot be reached —
let the call pass, uncounted, or refuse it (
503). Not the same answer for an open free tier and for a contractual one. Projected as the plan'scounter_failure. - Circuit breaker granularity: one circuit breaker for the API (each route, shared by every
caller), or one per subscription, so that one consumer making the backend fail does not open it
for everyone. Projected as the plan's
circuit_breaker_scope.
Limits
- Rate limit: N calls per second, minute, hour or day.
- Quotas: daily and monthly, empty meaning unlimited.
- Unit of measure: calls. Tokens and AI budgets are in the model, and refused at validation until LLM backends are supported.
Limits are per subscription, counted on its key: nothing is pooled between the subscriptions of an application or between plans — not even when the application calls every API with one key, each of its subscriptions being counted on an alias of its own. On an Otoroshi leader/worker cluster the quota is global, within a few seconds of synchronisation.
They are projected as the throttling strategy of the keys:
{ "strategy": { "id": "FixedWindowStrategyConfig", "windowDurationMs": 60000,
"quota": { "window": 500, "daily": 10000000, "monthly": 10000000 } } }
(10000000 is Otoroshi's "unlimited").
On apikey plans, a key validity in days makes each key expire that long after it is first
enabled — the subscription, or its acceptance — whatever the date of the subscription request.
Projected as the validity of the plan's key template.
Resource filtering
A plan can give access to all resources or only some. It is projected as the restrictions of its consumers — the allowed resources first, everything else forbidden. The paths are regexes Otoroshi matches against the whole request path: a resource and what is under it, or the resource alone when it is exact:
{ "enabled": true, "allowLast": false,
"allowed": [{ "method": "GET", "path": "/v1/pets(/.*)?" }],
"forbidden": [{ "method": "*", "path": "/.*" }] }
A call outside the plan's resources gets 403, whatever the kind of the plan — but oauth2-local:
the gateway gives the keys of these plans no restrictions, and the draft says the filter is not
enforced there (filter_not_enforced).
Plan plugins
A plan can add one of the API's policy flows on top of the flow of the route, for its consumers
only — projected as the plan's flow_ref.
Threat protection
A plan can put the Threat Protection Suite of the gateway (otoroshi-waf-extension) on the calls of its consumers, from the plan's tab Threat protection: the firewall (SecLang, the OWASP core rule set by default), the bot guard, the IP reputation, fail2ban, the sensitive data and error leakage guards, the upload guard, the login guard, the API contract. The product configures it, the extension enforces it: the plan carries the preset of the extension in its plugins, after the flow it references, and the drift detection watches it like the rest of the plan.
The policies are the extension's — threat policies, bot policies, firewall configurations, API
contracts, made in Threat Studio — and a plan references them, it never writes them. Without a
threat policy, the extension applies its built-in one, which records what it sees and never
refuses a call: the draft says it (threat_protection_dry_run), as it says a login guard without
a login path (login_guard_idle) or an API contract that names no contract (api_contract_idle).
A gateway without the extension ignores a plugin it does not know, and the calls go through
unprotected: the draft and the deployment say it (threat_protection_unavailable), and the tab
says it before you start. The events of the suite are in Observability → Security, attributed to
the API, and to the plan and the subscription of the key that called; a caller not identified — a
keyless plan, a refusal before identification — is the API's only (waf#61).
The extension works best as a fabric: the firewall reports (a configuration that does not block)
and the threat response decides, from the score of the call — a policy that refuses at 90, the
weight of a block of the firewall, with waf_block_decisive. Its refusals are then security events.
A threat policy can also challenge a caller: a challenge is a page, for a person in a browser.
- The global table of Threat Studio does not see the preset of a plan: a second firewall runs on the calls of that plan, the scores add up and the policy of the table decides (waf#60). Keep the global table off the APIs the product protects per plan.
- With the core rule set, every call scores a firewall match (45): its initialization rules count as matches (waf#62). A policy that refuses below 90 refuses legitimate calls.
- A firewall that blocks on its own sends no security event, only its trail (waf#63): its blocks do not reach Observability → Security.
- A security event names the API, not the plan (waf#61): the product finds the plan from the key that called, when there is one.
Catalogue and approval — never projected
These belong to the portal:
| Attribute | |
|---|---|
| visibility | public, authenticated or restricted (ACL tags) |
| subscribable | off = out of self-service: only a producer can put a consumer on it (a contract) |
| approval | auto (the key is issued at once) or manual (a producer reviews) |
| terms of use | a URL the requester must accept |
| usage statement | a question to the requester, optional or required |
| request form | the subscription metadata fields marked for the portal |
Pricing
A plan is free or paid: amount, currency, interval, optionally a price at Stripe (price_…), and a
grace period. The product decides access, Stripe decides the money: a paid subscription waits in
pending_payment, and its key is only projected once Stripe says it is paid. The pricing is frozen
in the snapshot: changing a price is a publication. How the money goes: Payments.