ADR 0015: `principal_kind` preserves Phase 1 scope independently of roles
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_kindstill accepts the wire valuesopsandowner.owneris 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 alsoOWNER. - Kind supplies the legacy compatibility boundary, not grants.
Scope resolution owns selection narrowing and
the access cutover boundary. A positive
clientIdis a Business Unit alias in Phase 1, never a Facility id. SYS0remains a restrictive identity, not authority. - Kind and roles remain independent axes. Neither implies the other. An
ADMINrole does not make a principalOPS, and client0does 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_kindremains restrictive rather than gaining Company-wide access. - The same role vocabulary continues to serve both principal kinds.
readScope()andwriteScope()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
0and 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
0as the Company principal. Rejected. Defaults and unprimed contexts use0, 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 resolutionservices/karyo-app/src/main/kotlin/com/karyo/app/auth/TenantFilter.kt- claim extraction on an authenticated requestlibs/karyo-security/src/main/kotlin/com/karyo/security/TenantContext.kt- restrictive defaults and explicit-owner contextslibs/karyo-security/src/main/kotlin/com/karyo/security/FacilityScopes.kt- current read and write scopes; ADR 0050 removed the legacy kind-to-scope APIservices/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/service/PrincipalService.kt- who may see and administer each kindinfrastructure/keycloak/karyo-realm-prod.jsonandinfrastructure/keycloak/karyo-realm.json- the unchangedprincipal_kindmappers
Related
- ADR 0013 - the realm and mappers that mint the claim
- ADR 0014 - Company and Business Unit compatibility
- Identity and tenancy - current claim extraction and scope resolution
- Users, roles and permissions - current user creation behavior