Karyo
Documentation/ Decision records

ADR 0015: `principal_kind` preserves Phase 1 scope independently of roles

Karyo 2.1.1rendered at build time
On this page

Status: Superseded in part by ADR 0038 for kind-only operational scope after access cutover 2. ADR 0037 moves the approved kind onto the Karyo principal and lets a verified token claim only narrow it. ADR 0050 removes the legacy scope API; OWNER describes affiliation, never operational ownership. ADR 0051 renames the owner kind to BUSINESS_UNIT_USER in storage and session responses, and to business_unit_user in the claim and the user-create API.

Context

Karyo is adopting Company > Business Unit > Facility while preserving the current authorization behavior through the first two Phase 1 steps (ADR 0014). The existing token model distinguishes operations staff from a goods owner's users. Both can hold the same operation role, but operations staff currently span positive clients while an owner's users are restricted to their own client_id.

Roles cannot carry that distinction. A role says which operation a principal may perform, not which Business Unit's rows it may perform it on. Nor can client 0 carry it: both TenantEntity.clientId and TenantContext.clientId default to 0, so treating SYS as all-access would fail open.

Identity and tenancy owns the current tree-grant activation boundary. P1.01 and P1.02 do not add grants, change claims, narrow OPS, remove owner pickers, or introduce Facility selection.

Decision

  • Keep the legacy token claim during the Phase 1 alias step. principal_kind still accepts the wire values ops and owner. owner is compatibility vocabulary for a Business Unit user; it is not renamed in realms during P1.01 or P1.02.
  • Resolution continues to fail closed. An absent token claim narrows to OWNER; malformed supplied values are denied. A stored OPS principal is effective OPS only when the recognized token claim is also OPS, and a token can never promote a stored OWNER. Explicit background contexts are also OWNER.
  • Kind supplies the legacy compatibility boundary, not grants. Scope resolution owns selection narrowing and the access cutover boundary. A positive clientId is a Business Unit alias in Phase 1, never a Facility id. SYS 0 remains a restrictive identity, not authority.
  • Kind and roles remain independent axes. Neither implies the other. An ADMIN role does not make a principal OPS, and client 0 does not grant Company authority.
  • Granting a kind remains strict. Creating a user requires an explicit recognized kind. An OPS principal may create either kind; an OWNER principal may create only OWNER principals.
  • P1.01 and P1.02 deliberately preserve behavior. The Company and Business Unit APIs use the current scope and role ceilings. Tree grants, Company and Business Unit descendants, separate read/write profiles, and request context selection are P1.03 onward.

Consequences

  • Existing tokens and users keep their current access while Company and Business Unit identities are introduced additively.
  • A token without principal_kind remains restrictive rather than gaining Company-wide access.
  • The same role vocabulary continues to serve both principal kinds.
  • readScope() and writeScope() remain separate. After access cutover 2, ADR 0038 resolves them from different operation-action grants rather than kind alone.
  • The Business Unit alias alone is not isolation proof and does not fulfill the later tree-grant phase. The activation boundary linked above distinguishes administration from operational scope.
  • A Keycloak service-account token without the legacy claims still arrives as OWNER/client 0 and can reach almost nothing. P1.01 and P1.02 do not change that integration gap.

Alternatives considered

  • Rename the realm claim and every token in P1.02. Rejected. The domain alias does not require a claim cutover, and realm migration belongs to the later identity/grant step.
  • Treat client 0 as the Company principal. Rejected. Defaults and unprimed contexts use 0, so this would fail open.
  • Derive Company-wide scope from a role such as ADMIN. Rejected. A role says what may be done, not where it may be done.
  • Default an absent claim to OPS. Rejected. A fail-open default would widen old or misissued tokens.
  • Introduce Facility context in Phase 1. Rejected. Facility and operational rescoping begin in Phase 2.

Evidence

  • libs/karyo-security/src/main/kotlin/com/karyo/security/PrincipalKind.kt - the two legacy values and fail-closed resolution
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/TenantFilter.kt - claim extraction on an authenticated request
  • libs/karyo-security/src/main/kotlin/com/karyo/security/TenantContext.kt - restrictive defaults and explicit-owner contexts
  • libs/karyo-security/src/main/kotlin/com/karyo/security/FacilityScopes.kt - current read and write scopes; ADR 0050 removed the legacy kind-to-scope API
  • services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/service/PrincipalService.kt - who may see and administer each kind
  • infrastructure/keycloak/karyo-realm-prod.json and infrastructure/keycloak/karyo-realm.json - the unchanged principal_kind mappers