Karyo
Documentation/ Decision records

ADR 0037: Karyo owns principals over exact external identity bindings

Karyo 2.1.1rendered at build time
On this page

Status: Accepted. Superseded in part by ADR 0048: a token's roles no longer narrow a compatibility-role ceiling because roles grant nothing, and the identity SPI no longer manages roles.

Context

Keycloak user ids and usernames were used directly as authorization keys, personal-state keys and operational owners. That made a provider replacement, a second issuer, a renamed user and a reused username unsafe. It also meant disabling a Karyo user depended on a provider administration call, and the browser clients depended on a provider-specific JavaScript adapter.

OIDC identifies a credential by the exact pair (issuer, subject). A subject alone is not globally unique. Provider claims are authentication evidence, not Karyo's durable business identity or an independent source of warehouse authority.

Decision

  • Karyo owns a stable UUID principal. External credentials bind to it by an exact canonical OIDC issuer and opaque subject. Issuer aliases require explicit attested configuration. Karyo never links by username, email or a normalized subject.
  • A verified token is resolved through its active binding on every request. Unknown, unlinked, suspended and retired principals are denied immediately. A migration cutover marker is required, so schema-only deployment does not enable first-login enrollment.
  • Quarkus OIDC remains the token verifier. The API requires the configured exact issuer, sub, RS256, token time validity and the karyo-api audience. The API accepts access tokens. A token's role set can only narrow the locally approved compatibility-role ceiling.
  • Authorization-sensitive references use principal UUIDs. Existing names and subjects remain as display and historical snapshots. Organization grants require separately reviewed activation; identity and tenancy owns the current activation boundary.
  • Identity administration is an optional SPI. The Keycloak adapter advertises supported lifecycle operations. An external provider may be authentication-only, in which case Karyo does not invent directory, create, disable, credential-reset or role-management capabilities.
  • Both browser applications use standards-based authorization code with PKCE through oidc-client-ts. They obtain normalized identity and authority from /api/v1/me, not by treating decoded token claims as the application's authorization model.
  • Existing installations cross the boundary with one reviewed, forward-only manifest. Ambiguity, nonterminal legacy provisioning, unresolved live work ownership, changed source counts or a changed already-applied manifest stops the cutover. There is no just-in-time principal creation.

Consequences

A provider can change while Karyo principal UUIDs, ownership and history remain stable. Local suspension and unlinking take effect on the next request even if the provider token remains valid. Two providers may issue the same subject without collision, while one exact provider/subject pair can never be reassigned.

The cost is an explicit maintenance cutover and a local identity ledger. Provider account state and Karyo access state are separate and must be presented separately. After new principal writes are accepted, rolling back to subject/name-authorizing binaries is unsafe; recovery is fix-forward or a coordinated restoration of application database, provider state and deployment.

Keycloak remains the managed default, but is no longer mandatory. Its event audit and lifecycle operations are available only when that adapter is configured. Authentication-only deployments must perform provider lifecycle work outside Karyo. A principal those deployments need after cutover is enrolled by a reviewed maintenance command, never by a runtime route. Delegated grants are keyed by principal UUID, so a grant reaches every active binding of its principal and survives a provider switch.

Alternatives considered

  • Keep Keycloak ids as application identity. Rejected because it binds ownership and access to one provider namespace and does not make issuer part of the key.
  • Link by username or email. Rejected because both can change or be reused, and an automatic match crosses an account-takeover boundary.
  • Create a principal at first login. Rejected because an arbitrary valid provider account could become locally enrolled or become the first administrator without reviewed affiliation.
  • Trust provider roles directly. Rejected because a provider mapping mistake would expand Karyo authority. Provider roles may only narrow a local ceiling.
  • Build provider-specific browser and Users implementations. Rejected because authentication is standard OIDC and optional administration capabilities can be represented directly by an SPI.

Evidence

  • services/karyo-app/src/main/resources/db/migration/auth/V1208__create_principals_and_external_identities.sql
  • services/auth-service/karyo-auth-api/src/main/kotlin/com/karyo/auth/identity/IdentityContracts.kt
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/PrincipalSecurityIdentityAugmentor.kt
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/ConfiguredIdentityAdministration.kt
  • services/karyo-app/src/main/resources/application.yaml
  • scripts/identity_migration.py
  • frontend/web/src/lib/keycloak.ts and frontend/mobile/src/lib/keycloak.ts