Karyo
Documentation/ Decision records

ADR 0053: A fresh installation signs in once as System, a console-only setup account that disables itself

Karyo 2.1.1rendered at build time
On this page

Status: Accepted.

Context

ADR 0048 makes Karyo's own grants the only authority, and its delegation rule lets a principal grant only a profile whose actions it already holds. That rule leaves a fresh installation with a chicken-and-egg problem: no principal exists, so nobody can grant the first Administrator anything. The production realm import defines no application users, and first sign-in never creates an administrator.

Until now the answer was a workaround: an operator wrote a reviewed identity manifest and applied it with a maintenance command, outside the console and outside the audit an implementer reads. Issue #166 asked for a product answer, bound by these constraints:

  • The delegation rule does not change. The answer must work through it, not around it.
  • Setup access must end. A standing all-powerful account is the risk the workaround avoided; whatever replaces it must stop by itself, and only the server may bring it back.
  • It is a person at a console, not an integration. No API tokens, no /mcp, no agents.
  • Everything it does is attributable. An auditor must see which grants came from setup.
  • No password in the repository or the realm export, and no password that outlives first use.

Decision

  • System is a principal the installation provisions once. On a fresh managed-Keycloak installation - no principal and no identity cutover recorded - with a one-time password configured, Karyo creates the provider account system ("System (setup)"), binds it to a SYSTEM principal, and records identity cutover 1 itself, since a fresh installation has nothing to cut over. karyo.setup_principal holds the one row that remembers it. An external (authentication-only) provider gets no System: Karyo cannot create accounts there, and the identity manifest stays that installation's route.
  • It holds every standard profile at the Company, so the unchanged delegation rule lets it grant each one. Viewer, Receiver, Operator, Manager, Administrator, Integrator and Integrations are granted to System at installation, by no one. No grant can be added to it later.
  • The sign-in choice: a generated one-time password that the provider forces System to replace. deploy-server.sh generates the password on a fresh managed installation, writes it to the private file scripts/.karyo-setup-password (mode 0600) and hands it to the application only, as KARYO_SETUP_PASSWORD in the rendered application environment. Karyo sets it as a temporary credential, so Keycloak requires a new password at the first sign-in. The password is never in the repository, the realm export or the operator's scripts/.env.prod.
  • Console only. System's token is admitted only when it was issued to Karyo's browser client (the azp claim); a token from any other client - a service client or an agent - is refused at sign-in. Its agent access can never be enabled.
  • It disables itself when its job is done, with a fixed backstop. When at least one Administrator and one Manager exist, System can confirm "Setup is complete"; Karyo then suspends the principal and disables the provider account. Fourteen days after provisioning, whichever comes first, the scheduler disables it the same way (EXPIRED). An administrator may suspend it earlier (SUSPENDED).
  • Only server configuration reopens it. The console cannot restore System or enable its provider account. An operator sets a new KARYO_SETUP_REOPEN marker with a new KARYO_SETUP_PASSWORD and redeploys; Karyo resets the credential as temporary, restores the principal and gives it a fresh 14-day expiry. Each marker reopens it once.
  • Every step is audited as "System (setup)". Provisioning, each grant System makes, each user it creates, its disablement and any reopening are identity facts in identity_change_log, and System's own sessions carry the name "System (setup)", so the operational audit attributes its actions the same way. The Users page shows System its checklist and the "Setup is complete" action, and System's user record shows its state, its expiry and its activity.

Consequences

  • An implementer brings an installation up from the console. Sign in as system, change the password, create the first Administrator and Manager (and any Operators), confirm setup is complete. No manifest and no maintenance command are needed on a managed installation.
  • The window is bounded. System exists for at most fourteen days after installation, and usually minutes.
  • The delegation rule is visibly intact. An Administrator System creates still cannot grant Manager unless it holds Manager's actions; System could only because it holds every profile.
  • A reopened System is a deliberate server-side act, recorded as one, with a fresh password.
  • The password file is the operator's to delete once setup is done; the deploy's closing message says so.
  • External-provider installations still use the identity manifest for their first principals.

Alternatives considered

  • Keep the identity manifest as the only route. Rejected: it is a maintenance procedure outside the console and outside the audit an implementer reads, and issue #166 asked for a product answer.
  • Make the first principal to sign in an administrator. Rejected: whoever reaches the sign-in page first would own the installation.
  • Let the operator choose the password in scripts/.env.prod. Rejected as the default: the value would stay in a long-lived file. It remains the reopen route, where an operator must supply one, and the deploy uses it if it is set on a fresh installation.
  • A setup token in the URL instead of an account. Rejected: it would be a second sign-in path beside OIDC, and its actions would have no principal to attribute them to.
  • Let an administrator re-enable System from the console. Rejected: anyone holding users.manage could then bring back an account that holds every profile.
  • Narrow the delegation rule for setup. Rejected: issue #166 keeps the rule unchanged, and a special case in the rule would be a permanent hole rather than a temporary account.

Evidence

  • services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/service/SetupPrincipalService.kt, SetupPrincipalService - reconcile, the loop; check, the console-only gate; provision, provisioning; disable, disabling; reopen, reopening; LIFETIME, the fixed lifetime; STANDARD_PROFILES, the standard profiles.
  • services/karyo-app/src/main/resources/db/migration/auth/V1218__setup_principal.sql - the record.
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/PrincipalSecurityIdentityAugmentor.kt, PrincipalSecurityIdentityAugmentor.resolve - the gate at sign-in and the "System (setup)" name.
  • services/auth-service/karyo-auth-core/src/main/kotlin/com/karyo/auth/service/PrincipalService.kt, PrincipalService.requireNotSetupPrincipal - no restore from the console; AccessDelegationService.requireMayReceiveGrants no grants to System.
  • services/karyo-app/src/main/kotlin/com/karyo/app/auth/SetupPrincipalScheduler.kt - the schedule.
  • frontend/web/src/pages/users/setup-panel.tsx - the checklist, the confirmation and the record.
  • scripts/deploy-server.sh - provision_setup_password and the reopen preflight.
  • services/karyo-app/src/test/kotlin/com/karyo/app/auth/SetupPrincipalTest.kt - the pinned behaviour.
  • ADR 0048 - grants and the delegation rule.
  • ADR 0037 - principals over provider identities, and the managed administration adapter System is created through.
  • ADR 0052 - the profile a fresh installation starts with.
  • Deploying and the implementer guide.