Karyo
Documentation/ Decision records

ADR 0013: Keycloak is the mandatory OpenID Connect provider

Karyo 2.1.1rendered at build time
On this page

Status: Superseded by ADR 0037. Keycloak remains the optional managed adapter; it is no longer the mandatory identity provider.

Context

Karyo is signed into by operators on shared floor devices, by office staff at desks and by administrators, and it has to support integrating systems. It is installed on a host the operating company controls, so identity has to run there too; a hosted identity service would make every installation depend on a third party and on that party's pricing.

The security features a warehouse installation needs - brute-force protection, multi-factor authentication, federation with a corporate directory, session management, an audit of sign-ins - are exactly the ones that are expensive and risky to build.

Decision

  • Keycloak is the only identity provider. There is no built-in user store and no alternative authentication mode. It runs as its own container, proxied by nginx at /auth/ (ADR 0022).
  • The application validates bearer tokens with Quarkus OIDC against the karyo realm, as the karyo-backend client.
  • The realm has three Karyo clients:
    • karyo-web - public; used by both front ends; authorization code with PKCE (S256) and check-sso; exact redirect URIs under KARYO_PUBLIC_ORIGIN for /, /m/ and their silent check pages; no direct access grants.
    • karyo-backend - confidential service account; the token audience the application validates and the account that reads Keycloak events and users for the sign-in audit.
    • karyo-admin - confidential service account used only for user administration through the Keycloak admin API.
  • Karyo's own claims come from user attributes through mappers on both token-issuing clients. Managed Keycloak fixtures owns the current mapping; ADR 0014 and ADR 0015 own its scope semantics.
  • Roles are realm roles: fine-grained permissions such as inventory-read and order-write, and composites (ADMIN, MANAGER, OPERATOR, RECEIVER, VIEWER, INTEGRATOR).
  • Two realm definitions ship. The development realm carries demonstration users. The production realm carries no human users: the first administrator is provisioned from one-time bootstrap credentials supplied at deployment, and bootstrap access is then retired.
  • Sign-ins are audited from Keycloak. A scheduled poller reads the Keycloak events API and journals LOGIN, LOGOUT and LOGIN_FAILED (ADR 0010).

Consequences

  • Authentication is standard OpenID Connect. Federation, multi-factor authentication and brute-force protection (on in the production realm, five failures) come from Keycloak rather than from Karyo code, and tokens are validated locally once the signing keys are fetched.
  • Keycloak is a fourth container with its own database schema and memory footprint, and its start, including the first realm import, gates the application's start.
  • A revoked token stays valid until it expires.
  • Mappers must stay aligned across both token-issuing clients and both realm files. A missing mapper does not fail: the claim is simply absent and the application falls back to its restrictive defaults.
  • A realm file is imported only when the realm does not yet exist, so changing an installed realm is a maintenance procedure rather than a redeploy (Deploying).
  • No client for an integrating system ships. Direct access grants are off on every client, and karyo-web is the only client with a standard flow; it is bound to the deployment's own origin. An integrating system needs a provider client of its own that obtains a karyo-api access token, and a reviewed SERVICE principal bound to that client's issuer and subject. The realm roles, INTEGRATOR and integration-read included, authorize nothing: a grant does (ADR 0048, Identity for an integrating system).

Alternatives considered

  • A hosted identity service (Auth0, Firebase Authentication). Rejected. It cannot run on a customer-controlled host, per-user pricing is prohibitive when one warehouse has fifty to two hundred operators, and it moves identity data out of the customer's control.
  • Karyo's own authentication and token issuing. Rejected. Authentication is a solved problem, and building it in-house means owning every security property - federation, multi-factor authentication, brute-force protection, audit - that an identity provider supplies.
  • Keycloak as optional, with a built-in fallback user store. Not adopted. The cost recorded against it is two authentication code paths to maintain; no other reason is recorded.

Evidence

  • services/karyo-app/src/main/resources/application.yaml, quarkus.oidc, quarkus.keycloak.admin-client - OIDC validation as karyo-backend, and the karyo-admin admin client
  • services/karyo-app/src/main/resources/application.yaml, karyo.auth-audit - the sign-in audit poller's switch and interval
  • infrastructure/keycloak/karyo-realm-prod.json - the production realm: three clients, their flows, mappers and roles, no human users
  • infrastructure/keycloak/karyo-realm.json - the development realm
  • frontend/web/src/lib/keycloak.ts, OidcSession.init, createLoginRedirect and frontend/mobile/src/lib/keycloak.ts, OidcSession.init, createLoginRedirect - check-sso, PKCE S256 and the silent check pages
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/KeycloakEventPoller.kt, KeycloakEventPoller - sign-in events polled through the karyo-backend service account
  • scripts/deploy-server.sh, bootstrap_credentials_required, bootstrap_credentials_assigned - the one-time bootstrap credentials required for a fresh production realm
  • infrastructure/docker/nginx/nginx.conf, location /auth/ - Keycloak proxied at /auth/