Skip to main content

Wiring multi-tenancy

This is the practical companion to Organizations (multi-tenancy). It shows how each backend turns an authenticated principal into a selected org snapshot: the resolver, the local-dev header, and the front-end org picker.

It works the same way everywhere, and matches the identity resolver you already supply:

Archenstack gives you a resolver that answers "which org is this request?". In production it reads the OIDC org claim off the already-validated principal. It fails closed — an unresolved org denies, and the runtime never silently substitutes the root org.

For how the org claim itself is defined (the organization scope, sub as identity, roles kept internal), see the claim contract.

How a request picks its org​

Org is carried out-of-band of the canonical snapshot — never as a /orgs/{org}/… path prefix (that would break every fixed route). There are two ways a request names its org, in order of preference:

  1. Ambient (resolver-derived) — the server reads the caller's org from the OIDC claim. This is the default for single-org users: zero client change.
  2. Explicit header — a cross-org admin (a host capability, not a matrix role) selects a specific tenant with a request header. Once an org is selected, that admin is still restricted by that org's matrix like anyone else.

The header differs by transport surface: the HTTP management API accepts X-Archenstack-Org (sent by the web client), and a backend's insecure local-dev resolver, where it ships one, reads X-Rbac-Org (the Java adapter ships none — it reads org via its JWT-claims resolver, honoring X-Archenstack-Org for an authenticated cross-org admin).

The dev header is dev-only

The X-Rbac-Org header path lets any client claim any org. Where a backend ships an insecure dev resolver (Node, Go and Rust do; Django and the Java adapter do not) it is for local development only. Production — and the Java adapter's JWT-claims resolver — reads the org from the validated claim, honoring X-Archenstack-Org only for a caller whose token asserts platform authority, and only for a tenant inside that caller's bound. An out-of-bound target denies rather than falling back to the caller's own org.

Django​

archenstack-rbac-django exposes an org resolver that mirrors its subject (identity) resolver exactly. Configure it in the ARCHENSTACK_RBAC settings dict:

# settings.py
ARCHENSTACK_RBAC = {
# A dotted path to callable(user) -> org-slug. Takes precedence when set.
"SCOPE_ORG_RESOLVER": "myapp.rbac.resolve_org",
# Otherwise, read this attribute off the authenticated user.
"SCOPE_SUBJECT_ORG_ATTR": "rbac_org",
}

SCOPE_ORG_RESOLVER (a dotted callable) wins when set; otherwise the adapter reads the SCOPE_SUBJECT_ORG_ATTR attribute off request.user. Either way, returning None means "no org" and the caller is denied — fail closed. A typical resolver reads the org straight off the validated JWT claim your auth layer already attached:

# myapp/rbac.py
def resolve_org(user):
# `user.claims` is populated by your JWT auth backend after it validates
# the token against the issuer's JWKS. Archenstack never validates the token.
return getattr(user, "claims", {}).get("org") # None ⇒ deny (fail closed)

Every check then selects the caller's org snapshot before it decides: a missing or unknown org denies (NONE) before any resolution runs, so no tenant's matrix is ever consulted for the wrong caller.

The root default is env-sourced

The dev/seed/backfill org comes from the ARCHENSTACK_RBAC_DEFAULT_ORG environment variable (no inline default — an unset value fails loudly). It seeds and backfills root; it is never a runtime fallback for a missing claim. rbac_seed and the migration backfill target it; resolve_org never does.

Java (Spring Boot)​

The starter's RbacPrincipalResolver — the one bean you supply to identify the caller — carries a resolveOrg method with a fail-closed default:

@FunctionalInterface
public interface RbacPrincipalResolver {
String resolveSubjectId(HttpServletRequest request); // your principal → OIDC `sub`

default String resolveOrg(HttpServletRequest request) { // your principal → org slug
return null; // fail closed: an unresolved org denies, never the root org
}
}

Override resolveOrg in your bean to read the validated org claim. The adapter stays out of authentication — the token is already verified by your Spring Security resource server (oauth2ResourceServer().jwt() against the issuer's JWKS); the resolver just reads a claim off the authenticated principal:

@Bean
RbacPrincipalResolver rbacPrincipalResolver() {
return new RbacPrincipalResolver() {
@Override public String resolveSubjectId(HttpServletRequest req) {
return jwt(req).getClaimAsString("sub"); // stable identity; null ⇒ deny
}
@Override public String resolveOrg(HttpServletRequest req) {
return jwt(req).getClaimAsString("org"); // null ⇒ deny (fail closed)
}
};
}

Every controller resolves the caller's org and selects that org's snapshot (snapshots.snapshot(org)) before deciding.

The built-in JWT-claims resolver (archenstack-rbac.jwt-resolver.enabled=true) reads the org from the configured claim (default org), and honors the X-Archenstack-Org header only for a caller whose token asserts platform authority (the cross-org admin capability that sits above any single org's rbac.manage) — a non-platform caller's header is ignored and they stay pinned to their own org claim, and an out-of-bound target denies, so a caller can never resolve their role against a foreign tenant. The archenstack-rbac.default-org slug is used only for seeding and the migration backfill — never a request-time fallback — and is sourced solely from the ARCHENSTACK_RBAC_DEFAULT_ORG environment variable (no inline literal):

PropertyEnv varPurpose
archenstack-rbac.default-orgARCHENSTACK_RBAC_DEFAULT_ORGThe dev/seed/backfill org slug (e.g. root). Env-only, no inline default; not a runtime fallback for a real request.

Web (front-end)​

The RbacClient is org-aware. A cross-org admin pins a client to a tenant with withOrg(org), which returns a scoped clone that adds the X-Archenstack-Org header to every request — the path constants stay identical, since org is out-of-band transport metadata:

import { RbacClient } from "@archenstack/rbac-web";

const client = new RbacClient({ baseUrl: "/api/v1", token });

// Single-org user: nothing to do — the server resolves the org from the claim.
await client.myPermissions();

// Cross-org admin: pin a client to a specific tenant.
const acme = client.withOrg("acme"); // every request now sends X-Archenstack-Org: acme
await acme.getMatrix(); // acme's matrix

An unpinned client sends no org header, so the server resolves the org from the claim (the ambient path). Discover which orgs a caller may target from /me/ (its orgs membership) or GET /permissions/orgs/:

const orgs = await client.listOrgs(); // Org[] = { slug, label, is_active }

The PermissionsAdmin org picker​

The drop-in React admin renders an org picker automatically. It reads the caller's orgs from /me/ (falling back to listOrgs()), and when the caller can target more than one tenant it shows a selector. Switching orgs re-scopes the client with withOrg(...) and reloads every panel against the newly-selected tenant:

import { PermissionsAdmin } from "@archenstack/rbac-web/react";
import "@archenstack/rbac-web/react/styles.css";

// Renders the org picker + all seven panels, each scoped to the active org.
<PermissionsAdmin client={client} onError={notify} />

Because roles/features/matrix are per-org, every panel is a per-org view: a "this slug already exists" 409 is scoped to the active tenant, and is_system_admin / is_developer are resolved for the active org, not across all of them.

Clear the object-check cache on switch

If you build a custom org switcher rather than using PermissionsAdmin, the object-decision cache must be partitioned by org (or cleared on every switch) so org A's cached allowed = true can never be served to org B. withOrg clones carry the org slug for exactly this partitioning; a hand-rolled switch that reuses one cache across orgs is a cross-tenant leak.

Assigning users to roles​

Archenstack owns roles. Your host supplies identity — the stable OIDC sub — and the role is read from Archenstack's own (org, sub) → role assignment table on every request. The token authenticates; it never carries an application role, and your identity provider learns nothing about your app's roles.

That single rule is what makes the rest of this page work:

  • Per-org correctness. Roles are unique per (org, slug) and a caller can belong to several orgs. One role claim cannot express "manager in acme, staff in globex" — an assignment per org can.
  • The anti-lockout check is meaningful. It counts admin-capable subjects; with roles arriving from a token it would be protecting an empty set.
  • Revocation is immediate. Lookups are per-request reads, so removing an assignment denies on the very next call instead of whenever a token happens to expire.

Wire the identity resolver: in Django set SCOPE_SUBJECT_RESOLVER (a dotted callable(user) -> sub) alongside the org resolver; in the Spring starter implement resolveSubjectId(request) on your RbacPrincipalResolver bean. No subject ⇒ no assignment ⇒ no role ⇒ denied.

The single-org adapters differ, by design

Node, Go and Rust are single-org, in-memory adapters with no assignment store, so they keep a host role resolver. None of the three arguments above binds there: there is no second org to get wrong, no durable assignment table to keep correct, and no admin UI writing to it.

Manage assignments over the org-scoped API — each route requires rbac.manage FULL and applies to the caller's active org:

MethodPathPurpose
GET/permissions/assignments/list the active org's { subject, role } assignments
POST/permissions/assignments/assign (upsert) a role to a subject — one active role per subject per org
DELETE/permissions/assignments/{subject}/revoke

Assignments are per-org (an assignment in one org is invisible in another), fail-closed (an unassigned subject resolves to no role and is denied), and carry their own anti-lockout rule: you cannot revoke or reassign the last subject holding an rbac.manage-FULL role, so an org can never be locked out of its own administration. The React admin renders an Assignments panel (list, assign, revoke) inside PermissionsAdmin for administrators, scoped to the active org.

Because Archenstack owns no user directory, the subject field is free text by default. Pass your users (or the IdP's) as subjects — { subject, label? }[] — to PermissionsAdmin (or AssignmentsTable) and the field becomes a dropdown so admins pick a person instead of typing an opaque sub:

<PermissionsAdmin client={client} subjects={[{ subject: "okta|amina", label: "Amina Okafor" }]} />
Assignments are adapter state

The assignment table is adapter state, like the matrix rows themselves — not part of the normative wire snapshot, so it never affects cross-language canonical bytes. The core still resolves decide(feature, role); assignments only decide which role the caller resolves to.

See also​