Skip to content
25 min readUpdated 23 Nov 2026

Auth

reaktor-auth answers two questions for every call: who is calling, and may they do this. heimdall, a Postgres schema, records people, services and agents, the apps and tenants they belong to, and the roles they hold. The auth server, which is itself a reaktor-graph of 14 nodes, turns a sign-in into a short-lived signed token. Every Worker, server and graph port verifies that token locally and then asks a relationship model: an OpenFGA engine that runs in process, whose objects are the code's own graphs, services and operations. Each app declares its roles in code next to that model, and Hangar's Auth pane keeps heimdall in step with them. The agent kernel uses the same engine to decide what each AI agent may do.

This page is the design at a glance; the Auth reference has the detail. It covers reaktor-auth-core, reaktor-auth, heimdall and Hangar's Auth pane, for BestBuds, CompanyOS, Manna and Hangar. In every figure, green is the repository, amber is heimdall, blue is a running service, violet is Hangar and grey is a caller or provider outside. Dark lines and numbered dots trace the path a section is about, and dashed lines are optional links.

The page starts with the whole picture and a playground for the token check, then explains each part, what the design improves on and where it falls short.

Overview#

Callers sit at the top of the picture. The auth server and heimdall sit on the left; they are the only places that issue tokens and store people. Everything a caller actually uses sits on the right: Workers, Spring servers, graph ports and the agent kernel. None of them asks the auth server whether a token is good. Each verifies the token's signature itself, with the public keys the auth server publishes.

Figure 1. Callers sign in at the auth server and receive tokens, then call Workers, servers and graph ports, which verify the token with published keys and check the access model that ships with the code. heimdall stores people and roles; Hangar manages heimdall and the role files. CALLERS People in apps BestBuds, CompanyOS, Manna, Hangar Google, Apple or a guest session Developer tools CLI, MCP servers and CI personal access token (rkt_) Workers and servers one service calling another service account credentials AI agents working for a person token exchange with an act claim Identity providers Google and Apple Supabase email is designed, not built Auth server reaktorServer · api.reaktor.build/auth AuthRuntimeGraph: 14 nodes wired by ports sign-in · refresh · PAT · service accounts token exchange · tenant switch · JWKS Where calls land each one checks the caller itself Workers Spring servers Agent kernel Graph ports token names first, then the OpenFGA model heimdall Postgres schema in Supabase identities and provider accounts principals and memberships apps, tenants and contexts roles, permissions, role grants sessions, tokens, audit trail Hangar · Auth pane the operator's desktop app People Roles Access Sessions Audit Security production writes need data-writer; all are audited Repository beside each app's code auth/<app>.fga the relationship model auth/<app>.fga.json roles, tuples, tests, modes reaktor-graph code graphs, services, operations 1 sign in, get an ID token 2 ID token, PAT or client credentials 3 access token (1 h) and refresh (30 d) 4 Bearer token on every call 5 public keys (JWKS), cached verifies the ID token reads people and roles writes sessions and audit model, roles and code objects decisions, recorded gives, takes and syncs roles edits roles and the model

Figure 1. Callers prove who they are at the auth server once (1 to 3), then send the access token on every call (4). Workers, servers and graph ports check the token with the published keys (5) and ask the model that ships with the code. heimdall holds people and roles, and Hangar manages heimdall and the role files.

The access model and the role catalog are files in the repository. Workers and the auth server have them compiled in, and Hangar loads the same files, so every checker applies the same rules as the code it guards. heimdall is the one store of people, memberships and role grants. Hangar's Auth pane reads it directly and changes it only in audited transactions.

The agent kernel works a little differently. AI agents reach it through their seat, such as codex or claude, and carry no token. The kernel decides each of its operations with the same engine and its own model, auth/hangar.fga, which lets every seat call every operation, in shadow mode, until a grant narrows it.

Try it#

Before any relationship is checked, LocalAuthorizer compares the claims in a verified token with what the operation requires. It runs one gate at a time and stops at the first that fails. The box below holds a token's claims and an operation's requirement. On the right, a line joins each permission the call needs to the permission in the token that covers it. Below, the gates are listed in order with what each one found, and why each permission is covered. The playground ports LocalAuthorizer and the rules in Capability.kt and Ceiling.kt, without the resource gate and the anyOf and allOf alternatives.

Some changes to try:

  1. Change the required data:read@reports/2026 to data:read@users. Nothing the token holds covers it, because data:write@reports covers reading reports, not users. The call fails at Permissions with 403.
  2. Then add superadmin to the token's roles. A superadmin of the tenant skips the permission list, but the call now fails at the credential ceiling: data:*@reports does not reach @users.
  3. Change the token's audience to hangar. The first gate fails with 401, and no later gate runs.
  4. Add a line delegated by billing-worker to the token. The call fails at Delegation, unless the requirement says delegation allowed.
  5. Leave ceiling with nothing after it. A ceiling that reaches nothing refuses every permission, which is also what happens when the claim cannot be read.

The token also takes principal service, and the requirement takes roles.

# The claims in a signed-in user's access token
token
  app docs
  tenant acme
  audience docs
  principal user
  roles editor
  permissions data:write@reports, messages:write
  ceiling data:*@reports, messages:read

# What the operation requires
requirement
  app docs
  tenant acme
  audience docs
  principals user, service
  permissions data:read@reports/2026, messages:read

The relationship check that runs next, can_invoke on the operation, has its own playground under Try a check.

How it works#

The sections below follow one person from their identity to a decided call: who they are in heimdall, the token they sign in for, the checks every call passes, the relationship model those checks ask, how the code becomes that model's objects, roles, tenants, and how Hangar manages all of it.

Who is who: identity, apps and tenants#

A person is one identity, shared by every app. Each way they sign in, such as a Google or an Apple account, is a provider account attached to that identity. Accounts are matched by the provider's issuer and subject; an email address never links two accounts. The identity acts through a principal, and the principal is what a token names in sub. Services and agents are principals with no identity behind them.

Everything else belongs to one app and carries its app_id. A tenant is an organisation inside the app, and a context is a smaller scope where a grant can apply. A membership puts a principal into the app, optionally inside one tenant and one context. A role grant gives a principal one role, optionally only inside one context. When a token is minted for a membership, heimdall collects the roles that apply there and the permissions those roles hold. The token carries both lists, with the app as aud, the tenant as tid and the context as ctx.

Figure 2. Provider accounts belong to one identity per person. The identity acts as principals, which join an app through memberships with an optional tenant and context, and hold roles through role grants that may be limited to a context. Roles hold flattened permissions. ONE PERSON, EVERY APP provider account a Google or Apple login matched by issuer + subject identity one per person shared by every app many belong to one principal user, service, agent, actor token claim sub acts as services and agents are principals with no identity INSIDE ONE APP every row in this frame carries app_id app a product namespace token claim aud tenant an organisation inside the app; token claim tid context a smaller scope for grants; token claim ctx membership a principal in the app, maybe a tenant, context role grant principal_role row, optionally in a context role declared in the catalog token claim roles permission group:action@path token claim permissions has has optional optional optional scope of holds, flattened joins holds

Figure 2. The heimdall tables behind a token. Everything inside the right frame belongs to one app. A token is cut for one membership, so it names one app, at most one tenant and at most one context.

Permission names#

Permissions are written group:action@path. An action covers the levels below it: admin covers every action in its group, and write covers read. The permission * covers everything. A path narrows a permission to part of the app and covers everything under it, so a holder of data:write@reports passes a check for data:read@reports/2026 and fails one for data:read@users.

A role named superadmin covers every permission inside its own tenant, including permissions added later. It only skips the permission list. Every other gate still applies: the app, tenant, audience and context, the kind of principal, the credential's ceiling, any role the requirement names, and the rule for delegated calls.

A personal access token, and every access or delegated token exchanged from one, carries a ceiling: the ceil claim lists the permissions that credential may ever reach. A permission outside the ceiling is refused even for a superadmin, and the relationship check runs a second time with only the ceiling's permissions before it allows a call. A ceil claim with an unknown version, or one that cannot be read, closes the credential, so it reaches nothing that needs a permission. Tokens made from older personal access tokens, minted before ceilings existed, have no ceiling.

Signing in and the tokens it returns#

The auth server is one reaktor-graph, AuthRuntimeGraph. Each of its 14 nodes declares the ports it provides and the ports it needs. autoWire() connects them, and requireFullyWired() stops the server from starting if any port is left unconnected. In reaktorServer the graph runs inside Spring, where a thin adapter hands it the database adapter and the signing keys, and installs a web filter that turns each bearer token into an AuthContext.

Figure 3. The auth server graph. Inputs heimdall and config feed six building-block nodes, which feed seven capability nodes; the Auth service serves the /auth routes. A sign-in uses the Auth service, Login, Jwt, Repository, Session lifecycle and Audit. INPUTS BUILDING BLOCKS CAPABILITIES HTTP ROUTES heimdall ExposedAdapter Config keys, providers Repository AuthRepositoryNode Audit AuthAuditNode Session lifecycle AuthSessionLifecycleNode Jwt AuthJwtNode Personal tokens AuthPersonalTokenNode Service accounts AuthServiceAccountNode Login LoginInteractorNode Sessions AuthSessionNode Token grants AuthTokenGrantNode PAT AuthPatNode Tenant authority AuthAuthorityNode Account AuthAccountNode App service AuthAppServiceNode Auth service AuthHttpServiceNode serves /auth/* each route passes RelationAccess /auth/sign-in /auth/anonymous /auth/session/refresh me · logout · logout-all /auth/token PAT · client · exchange /auth/pat/mint /auth/pat/verify /auth/authority/grants /auth/authority/resolve /auth/account/deactivate /apps/ /apps/{id} 1 2 5 3 4 6

Figure 3. Each card is one node of AuthRuntimeGraph. A link runs from the node that provides a port to the node that uses it. The dark links and the numbered dots trace a sign-in; the faint links are the rest of the wiring.

  1. The app gets an ID token from Google or Apple and posts it, with its app id, to /auth/sign-in. The Auth service hands it to Login.
  2. Login asks the Jwt node to verify the ID token against the provider's keys.
  3. The Repository node finds the provider account, identity, principal and membership in heimdall, creating any that are missing, and reads the roles and permissions of that membership.
  4. The Session lifecycle node opens a session and its first refresh token.
  5. The Jwt node mints the access token: ES256, type at+jwt, signed with the stable key whose kid the JWKS publishes.
  6. The Audit node records the mint, and Login returns both tokens.
CredentialWhat it isLifetimeUsed for
Access tokenES256 JWT, type at+jwt, checked against the JWKS1 hourEvery API, Worker, graph and service call
Refresh tokenrkr_ opaque token, stored as a SHA-256 hash30 days from sign-in; a new one on every useRenewing a session. Replaying an old one revokes the whole family, with a 60-second grace for two tabs refreshing at once
Personal access tokenrkt_ token with an offline checksum, stored hashedUntil it expiresCLI, MCP tools and CI, exchanged at /auth/token for an access token
Service accountClient id plus a private-key JWT or a secretUntil rotatedclient_credentials for Workers and servers calling each other
Delegated tokenAccess token whose act claim names the service acting (RFC 8693)ShortA service or agent working for a person
Tenant tokenAccess token for one tenant and one permission60 seconds at mostAn operator switching tenant (see Tenants)
Guest sessionThe normal token pair with credential_type=anonymousLike a sessionTrying an app before signing up

Every checker pins the issuer, the audience and the expiry. Workers use WorkerJwtVerifier, which keeps the key set in isolate memory, then in the data centre's Cache API, then in KV, and fetches it only on a miss or an unknown kid. Spring servers use ReaktorSecurityWebFilter, and other JVM code calls JwtVerifier directly.

The auth server checks its own routes against the model too. Callers who are not signed in reach only its sign-in routes, and one of the five model tests in the BestBuds store checks exactly that.

How one call is decided#

A guarded call passes up to four checks, in this order.

Figure 4. A call passes four checks in order: the token check, the requirement check, the relationship check and an optional object check in the handler. Each of the last three records an AccessDecision. A call arrives Bearer token, contract and operation 1 · Verify the token ES256 signature, JWKS issuer and audience not expired → AuthContext WorkerJwtVerifier ReaktorSecurityWebFilter 2 · Requirement check LocalAuthorizer reads the names the token carries: app, tenant, audience, principal kind, permissions, roles AuthRequirements SecuredProviderPort 3 · Relationship check OpenFGA engine, in process can_invoke on operation:<service>.<op> shadow records, enforce refuses RelationAccess AccessGuard 4 · Object check in the handler, when it needs one object circle:alpha#viewer with facts it loaded ObjectAccess token context allowed allowed 401 · sign in 403, or 401 403 when enforced handler refuses shadow: recorded, and the call goes on AccessDecision, one per check subject · relation · object · allowed · mode · rule · facts · model · tenant · trace on the call's span, in Worker logs, replayed by Hangar's Access tab

Figure 4. The four checks of one guarded call. A failed token check answers 401. The requirement check answers 403, or 401 when the token was issued for another audience. The relationship check refuses only in enforce mode.

The first two checks read only the token. The token check proves who is calling and builds an AuthContext. The requirement check, LocalAuthorizer, compares the names in that context with an AuthRequirement: the app, tenant and audience the call must be for, the kinds of principal allowed, and the permissions or roles it needs.

The third check asks the relationship model whether the caller has can_invoke on the operation being called. The caller's token becomes contextual tuples for this one check, so the engine reads no database. Each service runs in one of two modes. In shadow mode the decision is recorded and the call goes on; in enforce mode a denial refuses the call. Modes are set per service in the store, with * as the default, and BestBuds runs every service in shadow mode. A Worker whose model fails to load logs why and checks nothing.

The fourth check is for handlers that need an answer about one object, such as whether Ada may view circle alpha. ObjectAccess.decide asks the model with the facts the handler has just loaded, such as the circle's members, added as contextual tuples.

Checks two to four each produce one AccessDecision. It rides on the call's span, Workers log the ones that deny, and Hangar's Access tab replays recorded decisions against the saved model and any draft. A model change therefore shows which real calls it would start refusing before it ships.

The relationship model#

OpenFGA itself is not deployed anywhere. The fga package in reaktor-auth-core is a Kotlin engine that reads OpenFGA's modelling language (schema 1.1), validates a model, and answers Check with an explanation, Expand, ListObjects and ListUsers. It is common Kotlin, so the same engine runs in Workers through Kotlin/JS, in the JVM servers, in the agent kernel and in Hangar.

Figure 5. The model's types. Callers are users, service accounts or agents. They are assignees of roles and holders of permissions, and roles' members hold permissions. Roles and permissions are granted relations on graphs, services and operations. A service points to its graph and an operation to its service. BestBuds adds a circle type. CALLERS user a person service_account a Worker or server agent an AI agent user:anonymous when nobody is signed in WHO HOLDS WHAT role assignee can include other roles permission holder from the role catalog THE CODE graph parent owner operator viewer rights flow down from the parent service graph owner caller viewer graph owners, operators are callers operation service invoker blocked can_invoke can_invoke is (invoker or caller from service) but not blocked HOW A TUPLE READS object#relation@subject the subject has that relation on the object role:member #assignee@user:ada Ada is a member service:bestbuds.circles #caller @role:authenticated#assignee anyone signed in may call it AN APP'S OWN TYPE circle member blocked viewer viewer is member but not blocked; the handler passes the members it loaded assignee holder members hold it granted relations graph service

Figure 5. The types in config/access/bestbuds.fga. Roles and permissions sit between callers and the code's objects, so a grant can name one caller, a role's members or a permission's holders. Every app starts from the same code types and may add its own, as BestBuds adds circle.

BestBuds and Reaktor keep their model and store together in config/access/. The reader also accepts workspace catalogs under auth/ during the move. This is the whole BestBuds model:

model
  schema 1.1

type user

type service_account

type agent

type role
  relations
    define assignee: [user, service_account, agent, role#assignee]

type permission
  relations
    define holder: [user, service_account, agent, role#assignee]

type graph
  relations
    define parent: [graph]
    define owner: [user, role#assignee] or owner from parent
    define operator: [user, service_account, agent, role#assignee] or owner or operator from parent
    define viewer: [user, service_account, agent, role#assignee] or operator or viewer from parent

type service
  relations
    define graph: [graph]
    define owner: [user, role#assignee] or owner from graph
    define caller: [user, user:*, service_account, service_account:*, agent, agent:*, role#assignee, permission#holder] or owner or operator from graph
    define viewer: [user, service_account, agent, role#assignee] or caller or viewer from graph

type operation
  relations
    define service: [service]
    define invoker: [user, user:*, service_account, service_account:*, agent, agent:*, role#assignee, permission#holder]
    define blocked: [user, service_account, agent, role#assignee]
    define can_invoke: (invoker or caller from service) but not blocked

type circle
  relations
    define member: [user]
    define blocked: [user, role#assignee]
    define viewer: member but not blocked

Tuples come from six places:

SourceExample tupleRead
The code's structureoperation:bestbuds.circles.discover#service@service:bestbuds.circlesWhen the model loads
A contract's ServiceAccessservice:bestbuds.circles#caller@role:authenticated#assigneeWhen the model loads, and again for the operation being called
The role catalogpermission:companyos:audit:view#holder@role:companyos:auditor#assigneeWhen the model loads
Tuples written in the storeNone in BestBudsWhen the model loads
The caller's tokenrole:authenticated#assignee@user:ada, plus one tuple for each role and permission the token namesOn every call
Facts a handler loadedcircle:alpha#member@user:adaOn each object check

The store also carries tests that run against the model. BestBuds has five, among them "callers who are not signed in reach only public services" and "a circle's members see it unless they are blocked".

Try a check#

The box below holds a small model in the same language, the tuples it reads, and a few checks. It runs a TypeScript copy of the fga package's check, which answers each one the same way and gives the same explanation. Choose a check to see why it was allowed or denied. The tree under Why is the engine's own explanation, and the picture marks the tuples that allowed the check in green and any tuple that blocked it in red.

Things to try:

  1. Leave it as it is. Grace may call chat.send and Ada may not. Grace's path runs through five tuples: she is an assignee of role:ops, ops operates graph:app, graph:app is the parent of graph:app/chat, the chat service sits in that graph, and chat.send belongs to the service.
  2. Give Ada the role: add role:ops#assignee@user:ada under tuples. Her check is now allowed. A token that names the role adds this same tuple for one call, which is how the real check reads it.
  3. Block Grace: add operation:chat.send#blocked@user:grace. Her check is denied, and the blocking tuple turns red. but not blocked wins over every grant.
  4. Move the service: change service:chat#graph@graph:app/chat to service:chat#graph@graph:billing. Grace loses access, because graph:billing has no parent and nobody operates it. Moving code moves its access with it.
  5. Open the service to everyone: add service:chat#caller@user:*. The tuple is refused, because caller admits only user and role#assignee. Add user:* to caller's type list and Ada may call it too, unless she is blocked.
  6. Break the model: change the operator line to define operator: operator from parent. Nothing could ever grant it, so the model does not load and nothing is checked, just as a Worker would refuse it.
model
  schema 1.1

type user

type role
  relations
    define assignee: [user, role#assignee]

type graph
  relations
    define parent: [graph]
    define operator: [user, role#assignee] or operator from parent

type service
  relations
    define graph: [graph]
    define caller: [user, role#assignee] or operator from graph

type operation
  relations
    define service: [service]
    define invoker: [user, role#assignee]
    define blocked: [user, role#assignee]
    define can_invoke: (invoker or caller from service) but not blocked

tuples
  role:ops#assignee@user:grace
  graph:app#operator@role:ops#assignee
  graph:app/chat#parent@graph:app
  service:chat#graph@graph:app/chat
  operation:chat.send#service@service:chat

checks
  user:grace can_invoke operation:chat.send
  user:ada can_invoke operation:chat.send

The code is the object tree#

The model's objects are computed from reaktor-graph. CodeAccess.resources walks a graph's shape. Each scope that holds a service becomes a graph object whose parent is the enclosing scope. Each service node becomes a service object linked to its graph, and each operation of its contract becomes an operation object linked to the service. A contract declares who may call it with ServiceAccess, for example Callers.SignedIn, and that declaration becomes a caller tuple on the service. When an operation names callers of its own, they replace the service's for that operation, and each operation gets an invoker tuple instead.

Figure 6. The BestBudsApplication graph, its circles child graph, the CirclesApi service node and its discover operation become four objects in the model with parent, graph and service links. Ada's call to discover is allowed because her token makes her an assignee of role:authenticated and the contract declares signed-in callers. IN THE CODE BestBudsApplication the root graph circles a child graph CirclesApi a service node ServiceAccess(Callers.SignedIn) discover an operation of the contract IN THE MODEL graph:bestbuds graph:bestbuds/circles service:bestbuds.circles caller: role:authenticated#assignee operation:bestbuds.circles.discover becomes parent graph service A CALL BY ADA user:ada signed in, so her token says so role:authenticated built in; every signed-in caller Allowed can_invoke on the operation the rule it records service:bestbuds.circles#caller @role:authenticated#assignee assignee, from the token caller, from the contract callers flow down

Figure 6. Four pieces of code become four objects, and the parent, graph and service links come from the code. Ada may call discover because her token makes her an assignee of role:authenticated and the contract declares signed-in callers.

Because the parent links come from the code, moving a service into another graph moves its access with it, and a grant on a graph reaches every service and operation beneath it. Each runtime holds the links for its own island: CodeAccess.island puts the island's graph under the app's root, graph:bestbuds/messaging under graph:bestbuds, and links each contract the island guards to it. Workers build these links from the contracts they serve and the auth server from its contract list, so graph:bestbuds#operator@role:ops#assignee reaches every island and a grant on graph:bestbuds/messaging reaches the messaging Worker only. A Durable Object's island sits under its Worker's island, built from a path such as listOf("chat", "ChatService"). Hangar builds the same links from the island catalog the Workers export, with the same function, and answers each island the way it answers itself.

Guards sit in two places. RelationAccess is a service interceptor: Workers install it on the contracts they serve, and the auth server installs it on its own two services. Graph.guard installs AccessGuard on every port of a graph that has a requirement, belongs to a contract operation or was declared with providesProtected. It follows nodes and child graphs added after it starts and releases them when they leave or the graph closes, so calls between nodes inside one process are checked the same way as calls over HTTP. A port declared with providesProtected is checked as its own object in the model, a port linked to its node and that node's graph, so a grant can name the port, its node or any graph above it.

A port can also carry its own AuthRequirement through SecuredProviderPort or SecuredConsumerPort. AccessGuard then scopes any required permission that has no path to the port's place in the graph: messages:write on a port is checked as messages:write@<graph>/<node>/<port>, so a holder of messages:write@<graph> may use the ports inside that graph and no others.

Roles as code#

Each app declares its roles in the roles list of its .fga.json store, next to the model. A role has a name, a title, a description, its permissions and the roles it includes.

Figure 7. The roles list in config/access/bestbuds.fga.json is checked and flattened by RoleCatalog. The roles become model tuples that every model load reads, and Hangar's Roles tab compares them with heimdall and builds a sync plan, applied in one transaction with a ROLE_CHANGE event. Giving or taking a role writes heimdall directly. IN THE REPOSITORY config/access/bestbuds.fga.json the roles list e2e5 permissions companyos:superadminincludes 4 roles companyos:ca20 permissions companyos:cs23 permissions companyos:auditor11 permissions companyos:accountant12 permissions each role also has a title and a description RoleCatalog refuses names over 50 chars or using characters other than letters, digits and - _ . : refuses everyone, authenticated refuses loops, unknown includes checks the permission grammar then flattens includes Model tuples permission:<p>#holder@role:<r>#assignee role:<inc>#assignee@role:<r>#assignee made by CodeAccess.tuples Every load of this store Worker bundles, the auth server, Hangar Hangar · Roles tab compares heimdall with the catalog, role by role, and labels each role's status Sync plan shown in words and SQL; you pick the steps create permissions · create roles link · unlink permissions retire roles (a choice) drop unused permissions (a choice) heimdall roles, flattened permissions, grants a holder's next token carries the role's flattened permissions Give or take a role People tab, or a role's holders in the Roles tab read CodeAccessPolicy.load the catalog's view heimdall's view builds one transaction + ROLE_CHANGE writes principal_role ROLE_GRANT · ROLE_REVOKE start the catalog

Figure 7. One file declares the roles. The model reads it directly, and heimdall follows it through Hangar's sync plan. Giving or taking a role writes heimdall directly, with its own audit events. The dashed path starts a catalog for an app that has none.

RoleCatalog checks the list once and refuses anything heimdall or the model could not hold. It then flattens includes, so companyos:superadmin carries every permission of the four roles it includes. From there the roles go two ways. CodeAccess.tuples turns them into model tuples, which every load of the store adds, so a Worker, the auth server and Hangar all see the same roles. heimdall gets them through Hangar: the Roles tab compares heimdall with the catalog role by role and builds a sync plan. Retiring a role that people hold takes it from them, so the plan offers retiring and dropping as choices. The chosen steps run in one transaction with a ROLE_CHANGE audit event.

heimdall stores each role with its flattened permissions, so issuing tokens did not need to change: a holder's next token carries everything the role implies.

The Roles tab labels each role In heimdall, Not in heimdall yet, heimdall differs, Not in the catalog, Test leftover or No catalog yet. An app with no catalog can start one from what heimdall holds, leaving out test leftovers. BestBuds declares six roles: e2e for the Karate suite, and five companyos roles, which live here because CompanyOS signs in through the BestBuds app id.

Apps, tenants and switching between them#

Tenancy has three levels. The app is the hard boundary: a token names exactly one app as its audience, every check pins it, and an app's roles mean nothing in another app. A tenant is an organisation inside an app, and a context is a smaller scope. A membership, and so a token, carries at most one of each.

LocalAuthorizer runs these gates in order and stops at the first one that fails:

GateFails whenAnswer
TokenThere is no verified token401
AudienceThe token was issued for another audience401
AppThe token is for another app403
TenantThe token is for another tenant, or for none403
Principal kindThe caller is a kind the requirement does not allow403
ResourceThe resource's app, tenant or context differs from the token's403
AlternativesNo requirement in anyOf allows the call, or one in allOf refuses itThat requirement's answer
PermissionsA required permission is not covered, and the caller is not superadmin of the tenant403
Credential ceilingThe token's ceil claim does not reach a required permission, even for a superadmin403
RolesA required role is missing403
DelegationThe call is delegated and the requirement does not allow it403

Switching tenant#

An operator signed in to one app can act in a tenant of another app without signing in again, through the tenant authority routes.

Figure 8. Switching tenant. The operator's app lists its grants, then asks to resolve one target and one permission. The auth server reads heimdall again, checks the permission, writes the audit event first and returns a token for the target that lives at most 60 seconds. Operator's app signed in to app A Auth server AuthorityService heimdall current grants GET /auth/authority/grants with the operator's token read current memberships and roles app, tenant, context and roles for each grant resolve: target app, tenant, context, one permission read the grants again for that exact target LocalAuthorizer: app, audience, tenant, permission, users only; then the model write TOKEN_EXCHANGE first; if that fails, stop token for the target: tid, ctx, one permission, ≤ 60 s

Figure 8. A tenant switch. Every resolve reads heimdall again, checks the one permission asked for and writes the audit event before it mints anything.

The switch never copies authority from the token the operator already has, including a superadmin role. Each resolve reads heimdall again for that exact app, tenant and context, checks the one permission with LocalAuthorizer and the model, and writes the TOKEN_EXCHANGE audit event before minting anything. If that write fails, no token is issued. The new token carries only that permission as its scope and lives at most 60 seconds, never past the source token or session. Only a person's own access token can start a switch; a PAT, a service token or a delegated token cannot.

Where tenancy goes next#

The unified context proposal replaces the separate tenant and context columns with one context tree, so that a grant at any node covers everything beneath it. It is a design with no code yet.

Figure 9. Today an app has a flat list of tenants and a flat list of contexts, and a membership names one of each. The proposal is one tree from product to app surface to tenant to resource, where a grant on a node covers its subtree. TODAY app tenants tenant A tenant B contexts context X context Y membership a tenant + a context a role grant names one context; nothing is inherited PROPOSED IN AUTH-ANALYSIS §26 · NOT BUILT product (root) surface: restaurants tenant: restaurant 42 resource: outlet 7 resource: menu 3 tenant: restaurant 77 grant: admin at restaurant 42 covers outlet 7 and menu 3 not covered a grant covers its node and everything below it (an ltree path prefix)

Figure 9. Today and the proposal. Today a grant names one context and nothing inherits. In the proposed tree a grant covers its node and every node beneath it, so tenant isolation becomes a property of the tree.

Two gaps are known. CompanyOS signs in through the BestBuds app id, so its roles sit in the BestBuds catalog until it gets an app of its own. And one identity shared by every app suits a single owner's apps; customers who each need a sealed user pool would need that assumption revisited.

Managing it from Hangar#

Hangar's Auth pane has six tabs, all reading heimdall through the workbench kernel. Writes to production need the data-writer role in Reaktor and pass through the same gate as the Data pane. Every write is one transaction with an audit event.

The Auth pane's People tab: services, people and an agent, each with how they sign in, what they can reach in each app, their sessions and when they were last seen.
The People tab, here with test data: who each principal is, how they sign in, and their roles in each app.
TabWhat it is for
PeopleThe directory. A person's roles in each app, with give and take, and Can they…?, which runs LocalAuthorizer on what a token of theirs would carry in one membership
RolesThe catalog beside heimdall, a role wizard with service and permission selection, live reach and separate save, assign and sync actions
AccessOne workspace with Graph, Relationships, Matrix and Source; a shared caller, policy, selection, checks and draft
SessionsSessions and personal access tokens, with the token wizard
AuditThe trail of mints, refreshes, exchanges, revokes, failures and role events
SecurityFindings, including roles that no catalog declares, the trust map and table exposure

Access uses the same system graph as the Graph pane. Protection marks distinguish public, signed-in, permission-protected, unguarded and unknown operations. The Looking as control shows a person or role’s reach. Working and Deployed compare repository policy with policy digests retained in runtime decisions; missing decision evidence stays Unknown. The Graph pane’s Access lens opens an operation in this workspace.

Relationships follows role includes and object relations through bounded neighbourhoods, including intersection and exclusion operators. Source puts the model, tuples and saved checks together. Checks show token, local requirement, credential ceiling, relationship and object stages. Answers from edited policy say Simulated; retained decisions provide Observed evidence.

Create roles from selected operations, read-only access, a duplicate or an included role. The wizard shows permission reach and requires acceptance of extra operations before saving. Assignment and removal preview the whole policy, including surviving paths. Current credentials retain their issued claims; new-token and draft previews show the proposed result. A selected operation can also seed a narrowed token.

Review groups changes by owner: repository source, heimdall, memberships, deployment, credentials and enforcement. Saving files records hashes and refuses stale source. Syncing heimdall and rolling out a requirement are separate actions. Resource sharing shows its deciding relationships; writes stay disabled with an explicit reason when no audited owner operation is connected.

What it improves#

Usual approachWhat goes wrongReaktor's approach
Each service asks an auth server about every tokenEvery request waits on another network hop, and the auth server becomes a single point of failure.Access tokens are signed JWTs. Every Worker, server and graph port verifies them locally with the published keys, and nothing calls the auth server per request.
Permission checks written by hand in each handlerThe checks drift from one handler to the next, and nobody can list who may call what.Requirements and ServiceAccess declare access next to the contract, and the same LocalAuthorizer decides every call.
A hosted authorization service such as OpenFGA or SpiceDBIt is one more service to run, and every check is a network call.The OpenFGA modelling language runs in process, in Workers, servers, the agent kernel and Hangar. The caller's token becomes contextual tuples, so a check reads no database.
Access rules that name URLs or services in a separate policy fileMoving or renaming code silently breaks the rules, or leaves stale grants behind.The model's objects are computed from the code's own graphs, services, operations and protected ports, so moving a service moves its access with it.
Roles edited by hand in a databaseEnvironments drift apart, and nobody knows which roles a release expects.Roles are declared in code next to the model. Hangar compares heimdall with the catalog and applies the difference in one audited transaction.
Long-lived API keys that carry everything their owner may doA leaked key reaches everything its owner can.Personal access tokens, and the tokens exchanged from them, carry a ceiling that bounds what they may ever reach, even for a superadmin.
Turning on enforcement in one stepA wrong rule locks real users out in production.Services start in shadow mode. Decisions are recorded, Hangar replays them against a draft model, and enforcement is switched on per service once they look right.

Limitations#

  • BestBuds runs in shadow mode. Its services record each relationship decision but do not refuse calls yet; the token check and requirements still refuse.
  • An access token lives until it expires. Signing out revokes the refresh-token family, but an access token already issued stays valid for the rest of its hour, because there is no access-token denylist yet.
  • One identity is shared by every app. That suits one owner's apps. Customers who each need a sealed user pool would need that assumption revisited.
  • CompanyOS signs in through the BestBuds app id, so its roles sit in the BestBuds catalog until it gets an app id of its own.
  • Ceilings cover new personal access tokens. Tokens made from personal access tokens minted before ceilings existed keep their old behaviour.
  • The token playground is a model. It ports the gates of LocalAuthorizer and the capability and ceiling rules. It leaves out the resource gate, anyOf, allOf and scopes, and it does not run the relationship check, which Try a check covers.

What is built and what is open#

Built:

  • The auth server as a reaktor-graph; ES256 tokens with a stable key and JWKS; rotating refresh tokens with reuse detection; PATs, service accounts, guest sessions, delegated tokens and tenant switching.
  • The audit trail, including role grants, revokes and catalog syncs.
  • The in-process OpenFGA engine, can_invoke on every guarded call in Workers and the auth server, and object checks with loaded facts.
  • The role catalog: validation, flattening, model tuples and the heimdall sync plan.
  • Credential ceilings on personal access tokens and the tokens exchanged from them, and guarded ports that are checked as their own objects in the model.
  • Hangar's Auth pane with its six tabs.

Open:

  • The first production sync of heimdall from the Roles tab, which needs the owner with data-writer.
  • Redeploying the Workers and reaktorServer, so that their bundles carry the catalog and their island's structure.
  • Moving services from shadow to enforce once the recorded decisions look right.
  • An app id of its own for CompanyOS, and catalogs for Manna and the operator app.
  • Stored object tuples, and a stored may_act policy for delegation.
  • Supabase email, magic link and OTP sign-in; browser PKCE, BFF cookies and DPoP.
  • The single context tree described under Where tenancy goes next.

Reference#

PiecePath
Kernel: AuthContext, AuthRequirement, LocalAuthorizer, Capability, CredentialCeilingreaktor/reaktor-auth-core/…/auth/kernel
OpenFGA engine and AccessDecisionreaktor/reaktor-auth-core/…/auth/fga
CodeAccess, CodeAccessPolicy, RoleCatalogreaktor/reaktor-auth-core/…/auth/graph
RelationAccess, AuthRequirements, ObjectAccess, bearer interceptorsreaktor/reaktor-auth/src/commonMain/…/auth/transport
AccessGuard, secured ports, AuthNode, code resourcesreaktor/reaktor-auth/src/commonMain/…/auth/graph
AuthRuntimeGraph and its 14 nodesreaktor/reaktor-auth/src/jvmMain/…/auth/runtime
The heimdall schemareaktor/reaktor-auth/src/jvmMain/…/auth/heimdall.sql
Spring adapter, web filter, JWKSreaktor/reaktor-auth/src/jvmMain/…/auth/spring
ServiceAccess and Callersreaktor/reaktor-service/…/service/Access.kt
BestBuds model and storebestbuds/config/access/bestbuds.fga, bestbuds/config/access/bestbuds.fga.json
How Workers load and log the modelbestbuds/modules/app/src/jsMain/…/cloudflare/core/BestBudsAccess.kt
How the auth server loads the modelservices/reaktorServer/…/ServerAccess.kt
The agent kernel's own model, auth/hangar.fgahangar/host/…/KernelAccessModel.kt
Hangar's Auth panehangar/core/src/jvmMain/…/workbench/auth

CapabilityTest and CeilingTest in reaktor-auth-core cover how permissions cover each other and the ceiling, and CredentialCeilingIntegrationTest and PortAccessTest in reaktor-auth cover ceilings on real tokens and guarded ports.

The Auth reference goes deeper on each part: the authorization model, sessions, PATs, service accounts, Worker verification, the schema, provider authorization and the open design questions. Secrets covers where signing keys and credentials live.