Skip to content

OSOS is multi-tenant, and the tenant model reaches into every API call: the same operation, with the same credential, returns different data depending on which space the request is scoped to. This page explains how that scope is established, how identity and delegation travel with a request, and — the part that matters most when designing an external client — what a credential cannot do across spaces, no matter how it is presented.

The identity headers themselves (x-user-id, x-shared-key and friends) are catalogued in Calling the HTTP API; why downstream services trust them at all is the subject of the security boundary. Here we follow the tenancy and delegation story end to end.

The space comes from the host, not the token

Section titled “The space comes from the host, not the token”

A client never sends a tenant identifier. The gateway’s space-resolver plugin runs at the head of the access chain, ahead of every authentication plugin: it reads the request’s Host header, looks it up in a Redis key named :spaces, and stamps the matching space’s id onto the request as x-space-id (plus x-space-maintenance when the space is closed to end users). A host that matches no space is rejected outright with 404 SPACE_ERROR (Since 1.10; it was 400) — before authentication is even attempted.

That :spaces cache is owned by the data service, which rewrites it whenever spaces change (refreshSpaceInRedis): an array of {id, hosts, name, is_end_user_deactivated} entries covering every active, non-deactivated space, each space’s host derived from its domain and subdomain identifier. A sibling plugin, domain-resolver, resolves the same Host against a :domains key into an X-DOMAIN-ID header the view-access check later requires.

Two consequences for a client author:

  • You address a tenant with a URL. Pointing the same client at hr.example.com and sales.example.com yields two different data worlds with no other change.
  • Whatever x-space-id you send is irrelevant. The gateway sets the header itself from the host lookup; Since 1.10 it first strips any x-space-id / x-space-maintenance the client supplied. (For OAuth flows the tenant is additionally bound into the signed token as the extra.domain claim — see Authentication & OAuth.)

Resolving a space from the host says nothing about whether you belong there. That is the user-space-checker plugin: for every authenticated request it verifies that the resolved x-space-id is among the calling user’s spaces, answering 403 SPACE_FORBIDDEN otherwise — helpfully carrying an available_spaces list (id, name, icon, URL) so a client can offer the user their actual spaces instead of a dead end.

Membership is fetched from the data service (GET /api/v1/spaces/user/{userId}) and cached in Redis for a configurable TTL (default 300 s), keyed per user. The staleness window is shorter than it looks: when a user’s space membership changes, the data service actively deletes that user’s gateway cache entry (invalidateKongUserSpacesCache), so the TTL is a backstop rather than the propagation delay.

A small allow-list of bootstrap endpoints — profile, own-spaces, language, themes and similar (bypass_paths in api-gateway/config/kong.yml) — skips the check, which is what lets a client ask “which spaces do I have?” before it is in any space.

Past the gateway, the space travels as the x-space-id header and nothing else. LoopBack services resolve it through a request-scoped provider (SpaceIdProvider) — which, before 1.10, fell back to the root space id when the header was absent (now it fails closed) — and controllers inject that resolved id into every command and query they issue; the data-plane controllers thread it through reads, writes, counts and exports alike.

Services with their own tenancy-sensitive resources enforce it again at their boundary. The packaging service is the clearest example: every operation requires the header outright (400 without it), and polling or manipulating an import session that belongs to another space is refused with 403 by an explicit ownership assertion. A long-running job is tenant property, not a global handle.

Services fail closed without a space Since 1.10

Section titled “Services fail closed without a space Since 1.10”

The root-space fallback above is gone (SpaceIdProvider):

  • Resolution order: the single, non-blank x-space-id header, then the ambient space scope (an in-process dispatch, or a background job re-entering the space its payload carries). If neither exists the call answers 400 SPACE_CONTEXT_MISSING instead of acting in the root space. A header sent twice counts as missing.
  • SPACE_SCOPE_ENFORCEMENT: when unset the code default is enforce; the chart renders spaceScope.enforcement, whose default is observe (log a warning, count osos_space_scope_fail_open_total, then use the root space). Any other value stops the service at startup.
  • The space is established as a scope for the whole request, so in-process calls inherit it. A header naming a different space than the one already in scope, or an unusable header inside a scope, answers 400 SPACE_NOT_RESOLVED. Infrastructure paths (/health, /ready, /live, /ping, /metrics, /explorer, /openapi.json) run in the root space.
  • Outbound service-to-service calls carry x-space-id from the scope.
  • Definition reads are space-scoped: entity and view definition lists return the Public definitions plus the Private / Shared ones that list the current space; another space’s private definitions are no longer returned.

Through the gateway none of this changes what a client does — the host still supplies the space. It matters to a script that calls a service directly on the cluster network, which now gets the 400 instead of silently reading the root space.

When one deployment serves several tenants, the host also decides the tenant. A host that maps to no active tenant answers 404 (APP_ERROR “Unknown host” at the gateway, TENANT_NOT_RESOLVED from a service). Each tenant has its own OIDC issuer, JWKS and clients, so validate tokens against the issuer of the tenant you call — see Per-tenant OpenID Providers. A browser client bootstraps from the public GET /api/identity/v1/tenant-config and obtains anonymous tokens from POST /api/identity/v1/anonymous/token (details). The gateway may also enforce a per-tenant request budget (429 RATE_LIMITED with Retry-After) — see Calling the HTTP API. And a tenant can be put under maintenance — while its data is restored from a backup, or while the operator holds it for a move to another cell — during which every service answers its requests with 503 TENANT_IN_MAINTENANCE and a Retry-After (Since 1.10; same link). The tenant stays routable and your credential stays valid: wait and retry.

View-scoped requests and the access object

Section titled “View-scoped requests and the access object”

Requests under /api/v1/v/{viewId}/… pass one more gate: the osos-access plugin loads the view’s access object and enforces, in order:

  1. Domain — the view must belong to the request’s resolved domain (403 otherwise; a missing domain id is 400 MISSING_DOMAIN_ID).
  2. Space — unless the view is marked public-space, the request’s x-space-id must appear in the view’s configured space list (403).
  3. Execution plan — the concrete URL and method must match the view’s allow-list of routes; a view with no plan accepts reads but rejects writes.
  4. Authentication mode — the access object declares who may enter: anonymous-only (0), any authenticated user (1), everyone (2), or explicitly-permitted users only (3), checked against the caller’s cached permission profile.

Only then is the path rewritten, the view id set as x-view-id, and the request forwarded to the owning service. Since 1.10 the plugin first clears any x-view-id the client sent, so a view can only be named through the path (details). This is why a 403 on a view-scoped path so often means “this view does not allow that” rather than “your token is bad” — the credential may be perfectly valid and the view still out of bounds in this space.

Two caches make this gate cheap, and both have visibility consequences: the access object itself (default 600 s) and the user’s permission profile (3600 s, keyed per user — and per delegation when one is active). A permission granted or revoked can therefore take up to an hour to be seen on view-scoped calls; compare the authentication caches in Token Lifecycle, which are tighter.

Delegation: acting as someone else, visibly

Section titled “Delegation: acting as someone else, visibly”

Delegation lets one person act for another during an authorized window, and it is the only sanctioned way a request runs under a different identity than its credential. The client’s part is a single header: X-Delegation-Id.

The gateway’s user-delegation plugin does the rest. It requires an authenticated caller, loads the delegation record (cached, default 600 s), and enforces the time window — outside it the request dies with 403 DELEGATION_EXPIRED. Within the window it rewrites the identity: x-user-id becomes the delegator (the person being acted for), the original caller moves to x-delegatee-id, and x-is-delegation: true marks the request. Both identities therefore reach every downstream service, which is what keeps history and audit truthful while permissions resolve as the delegator.

Downstream, delegation is not a free pass. The authentication strategy surfaces the delegation on the user profile, the data service narrows request-related views to the delegation’s configured scope by rewriting their filters, and the view gate demands explicit view permission for most views while a delegation is active. Delegation is a person-to-person instrument — for machine integrations, model the identity properly instead with a dedicated application user (Choosing a Credential).

The mechanics above add up to a set of hard limits that hold for any credential — OAuth bearer or application token — because they are enforced by the edge and the services, not by the token’s contents:

  • It cannot choose a tenant. The space and domain derive from the request host; client-supplied x-space-id is overwritten, and the identity headers cannot be forged through the gateway — the edge strips and re-issues x-shared-key, and only sets x-user-id from a validated credential.
  • It cannot enter a space its user does not belong to. Membership is checked per request; the only cross-space visibility a client ever gets is the available_spaces hint on the 403.
  • It cannot reach across tenants through side doors. View access is space-checked, and long-running job handles (exports, import sessions) are ownership-checked in their services.
  • It cannot escalate through a view. The access object’s authentication mode and execution plan bound what any caller may do on view-scoped paths, whoever they are.
  • It cannot impersonate. Acting as another user exists only as a live, time-boxed delegation — always leaving both identities in the audit trail — or as deployment-internal trust configuration that no external credential can invoke.

What a token can do across spaces is exactly one thing: be reused. The same credential works against every space host its owning user is a member of — the scope changes with the host, the identity does not. A client that serves several spaces should treat the host as part of its configuration, not attempt to multiplex tenants through headers.

Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27