Karyo
Documentation/ Decision records

ADR 0038: Operational scope comes from Karyo principal grants

Karyo 2.1.1rendered at build time
On this page

Status: Accepted. Supersedes the kind-only request-scope portions of ADR 0014 and ADR 0015 after access cutover 2. The staged cutover is superseded by ADR 0040: a grant is always in force and there is no marker. The coarse endpoint roles and the two operations.* actions are superseded by ADR 0048: every endpoint declares one catalogue action, resolved from grants alone.

ADR 0050 removes TenantScope and the copied Business Unit column from operational rows; separate Facility scopes now apply the boundary.

Context

A Karyo principal has an approved Business Unit affiliation and may hold Company or Business Unit grants. An operations principal can therefore have narrower authority than its legacy OPS scope. Using affiliation as the selected workspace would change Users visibility and personal layout ownership. Using a token subject for queued work would confuse credentials with the stable actor.

Decision

  • Access cutover marker 2 is the activation boundary for grant-backed operational HTTP scope, independent of the identity-enforcement configuration. Before it, preserve legacy scope.
  • Resolve operations.read and operations.write separately by active principal UUID, grants and current role ceilings. Company grants expand to positive Business Units; missing grants resolve to no rows. No selection or grant may turn SYS 0 into ambient authority.
  • Keep TenantContext.clientId as approved affiliation. Selected Business Unit and readable / writable sets have separate fields. X-Karyo-Business-Unit-Id narrows only an authorized set.
  • Apply read/write predicates before lists and aggregates, and check record scope before writes. Retained body clientId fields cannot contradict the resolved operational context.
  • Console and floor clients derive the current Business Unit from /api/v1/me choices and carry it on operational requests. Remove per-operation goods-owner pickers, not Users' affiliation control or the separately planned warehouse-setup Shared choice.
  • Bind floor queue entries to Karyo principal UUID, Business Unit, operation id and payload version. Require a successful online /me before enqueue; replay the captured context, never the next user's identity or current selection. IndexedDB version 2 retains old unbound entries as failed reconciliation work instead of silently rebinding them.
  • Leave schedulers on explicit ownerScoped contexts until the Facility work. No Facility grants, principal-kind rename, claim optionality or new grant-cascade rule is introduced here.

Consequences

Affiliation, selection and authority are independent. OPS plus a narrow grant cannot read a sibling Business Unit. Coarse endpoint roles remain necessary but insufficient. The SQL action catalogue, Kotlin role ceilings and Python manifest tables must evolve together; a parity test enforces that.

Application code remains the row-isolation boundary, not Hibernate filters or database RLS. Empty sets must remain empty through repositories and cross-module ports. Queue upgrades require device reconciliation; an offline acknowledgement is not proof of a server-side mutation.

Activation is a reviewed installation operation, not a side effect of applying V1210. Rehearse it in full on an isolated restored copy first, as the identity upgrade runbook describes.

Alternatives rejected

  • Overwrite affiliation with selection: silently changes identity administration and personal state.
  • Preserve unscoped OPS after activation: ignores narrow grants.
  • Rebind queued actions on login: changes actor or Business Unit without operator reconciliation.
  • Infer principal identity from sub: loses the exact-provider binding and stable UUID boundary.

Evidence

  • TenantFilter, TenantContext, FacilityScopes, CurrentAccessService and OrganizationAccessLookup
  • V1210__add_operational_scope_actions.sql and scripts/identity_migration.py
  • CurrentAccessKeycloakIT, OrganizationGrantResolutionTest and FacilityScopesTest
  • frontend/mobile/src/lib/offline/ and frontend/mobile/src/auth/auth-provider.test.tsx
  • Identity and tenancy