Projection

The product never enforces anything itself: it projects what a published snapshot describes onto the Otoroshi cluster of the installation, through the Otoroshi Admin API. Only what the gateway needs to enforce is pushed.
The Api entity
Deploying a snapshot writes one Otoroshi Api entity, whose id is the product's API id:
{
"_loc": { "tenant": "default", "teams": ["default"] },
"kind": "Api",
"id": "api_01a1eb8054c5…",
"name": "Books 1.0.0",
"domain": "books.oto.tools",
"contextPath": "/v1",
"state": "published",
"metadata": {
"created_by": "external=otoroshi-api-management",
"apim_api_id": "api_01a1eb8054c5…",
"apim_workspace": "ws_01a1eb8016…",
"deployment_ref": "snap_01a1eb806b…",
"apim_snapshot_number": "2"
},
"routes": [ … ], // one per resource
"backends": [ … ], // with their client settings
"flows": [ … ], // shared policy groups expanded in place
"plans": [ … ], // auth kind, rate limiting, restrictions, plan plugins
"documentation": null
}
- Managed as code. An
Apiwhosecreated_byisexternal=<tool id>is managed as code by an outside tool: each write is a deploy — the API may be created already published, the fields locked in production take the body, state transitions are still checked — and a write that changes what is live is recorded in Otoroshi's own deployment history (deployments), owned by the marker. The product's tool id isotoroshi-api-management. - The snapshot, on the gateway side.
deployment_refnames the snapshot deployed: Otoroshi gives it to the deployment it records as itsref, sodeployments[0].refsays which snapshot is live, and the console lists the gateway's deployments by snapshot (Settings › Technical details). Otoroshi keeps the last five (OTOROSHI_APIS_DEPLOYMENTS_HISTORY_SIZE); the product keeps its whole history. - Ownership. The marker and
apim_api_idare how the product recognises its own entities on a gateway that also serves other things — for drift detection, adopt mode and cleanup. - No tenancy. Everything lands in the default location: a workspace is never an Otoroshi tenant.
Derived objects
Otoroshi objects that follow from the description of an API are derived by the product:
| Derived from | Otoroshi object | Id |
|---|---|---|
a jwt plan that describes how its tokens are validated | JWT verifier | apim_jwt_<api>_<plan> |
the trusted CAs of an mtls plan | certificate (CA, no private key) | apim_ca_<api>_<plan>_<hash of the certificate> |
an oauth2-remote plan that describes its authorization server | auth module (oauth2) | apim_auth_<api>_<plan> |
They are written before the Api that references them, marked with the same created_by marker
plus apim_api_id and apim_derived, shown in the deployment diff, compared by drift detection
(on what the product owns: the gateway adds the dates of a certificate, and may not give a secret
back), and removed after the Api when no plan derives them any more. What does not follow from an API — the cluster, global
plugins, data exporters, listeners — is infrastructure the product references and never owns.
Subscriptions and keys
An active subscription is written as an Otoroshi ApiSubscription, with the same id as the
product's subscription:
{
"id": "sub_01a1eb808c84…",
"status": "enabled",
"plan_ref": "plan_…",
"api_ref": "api_…",
"owner_ref": "app_…",
"subscription_kind": "apikey",
"metadata": { "id_ref": "app_…", "apim_subscription_id": "sub_…", "apim_workspace": "ws_…" }
}
On apikey and oauth2-local plans Otoroshi mints the key from the plan's template. The key carries
apiRef = { api, plan, sub }, the plan's throttling strategy and restrictions, and the
subscription's metadata — among which id_ref, the application. That is what answers
"which APIs does this application consume" and "which keys to revoke if it is compromised".
On jwt, mtls and oauth2-remote plans the consumer calls with its own token or certificate.
The ApiSubscription carries the client_id the application declares, and Otoroshi provisions the
key the plan resolves for that consumer — jwt_<api>_<plan>_<client id>, with the same apiRef
and metadata — enabled while the subscription is. These plans are projected with
subscription_required: a valid token or certificate whose client id no enabled subscription
declares is not a consumer of the plan. The client id of a subscription never changes on the
gateway: when the application declares another one, the subscription is made again, the key of the
previous client id left disabled. A client id changed on the gateway, or a provisioned key enabled
or disabled by hand, is reported as drift.
A suspended subscription is projected disabled; a pending or rejected one is not projected at all;
closing deletes the subscription, and Otoroshi revokes its keys.
One key for every API
The subscriptions of an application that calls every API with one key
share the credential of the application: an Otoroshi apikey authorized on nothing by itself,
whose sharedCredential.owner is the application (owner_ref). Each one asks for it at its
creation — token_refs: [{"shared": true}] —, the first one making it; Otoroshi then names it, and
mints the subscription an alias, built from its plan, whose apiRef.credential is the credential:
"token_refs": [{ "apikey": "<credential>", "shared": true }, { "apikey": "<alias>" }]
A call made with the credential is identified, on each API, as the alias of its subscription: its
quotas, restrictions and plugins, its apiRef in the events. The gateway never moves such a
subscription to another API, so a transfer to another version makes it again there, sharing the
same credential; an alias lost with its credential is made again the same way at the next resync.
The credential is never updated, disabled or deleted with a subscription — it leaves the gateway
with the application. A credential disabled or with another secret on the gateway is reported as
drift, and a resync enables it again.
Asynchronous and replayable
Every projection goes through a task queue. A task is idempotent — it computes the wanted
state and makes the gateway match — and retried with a backoff (2, 4, 8… seconds, at most 5 minutes)
while the gateway is unreachable. A refusal of the gateway (4xx) fails it at once; so do 25
attempts. A subscription accepted while the API is not deployed waits, and is projected at the
deployment.
The Gateway page of the console shows the queue, and what each task works on. A task that failed — the gateway refused it, or it failed too many times — does not run again by itself: fix its cause and retry it, or dismiss it when it no longer applies (an installation administrator). A failed task whose object is gone — a subscription deleted since, a deployment of a deleted API — is dismissed by itself, saying why. At the bottom of the sidebar the gateway pill counts the failed projections (red), the waiting ones (orange) and the drift — of the workspaces of the person, all of them for an installation administrator — and leads to the first of them. What keeps working while the gateway, or the product, is down: When the product is down.
Never projected
| Stays in the product | Even though Otoroshi has the notion |
|---|---|
| drafts and the snapshot history | Otoroshi Drafts and API deployments |
| documentation pages | ApiDocumentation |
| catalogue visibility, subscribability, approval workflow | plan visibility and validation labels |
| terms of use, usage statements, request forms | — |
| pricing, payment state | plan pricing |
| metadata | entity metadata |
| workspaces and teams | tenants and teams |
The escape hatch
No longer need to is not no longer able to. In API → Settings → Technical details
the console shows the Otoroshi entity behind the API, the marker, the gateway's own deployment count,
a link to open it in the Otoroshi backoffice, and the entity exactly as the gateway holds it. The
admin API serves the same at GET /api/workspaces/<ws>/apis/<api>/projection: the expected entity,
the actual one and the last drift report.