feat(auth): create accounts through the keycloak admin api #328

Sammanfogat
supernaut sammanfogade 2 incheckningar från feat/keycloak-accounts in i main 2026-10-09 14:23:33 +00:00
Ägare

Closes #311.

Do not merge before bitborg/bitborg-infra#631 is applied to prod. Prod web tracks latest. Without the pin, this merge ships a Keycloak portal to a Kanidm prod.

What

  • src/lib/kanidm.ts is replaced by src/lib/keycloak.ts: client-credentials token for bitborg-web-admin, create user with groups, exact lookup, profile read-merge-PUT, delete on rollback, ent_renovate role mapping, action email.
  • Sign-up: the user picks passkey or password. Required actions are stored on the user and Keycloak sends the link, which also verifies the email. Mail and reconcile run only after the consent row is stored. A failed consent write deletes the user.
  • Resend: re-sends only the actions still pending, to the address on file. Every outcome answers "sent".
  • Renovate toggle: role taken from the user's available or assigned realm roles, so the client needs no view-realm.
  • Session: groups are bare names, entitlements read for the panel. Existing sessions sign in again once.
  • Identity rules: Kanidm rules dropped, Forgejo intersection kept, minimum username length 3.
  • OIDC: issuer from OIDC_ISSUER, RS256 pinned, client_secret_basic checked, logout through the end-session endpoint.
  • A 401 from the admin API clears the cached token.
  • Env: KEYCLOAK_URL, KEYCLOAK_REALM, KEYCLOAK_ADMIN_CLIENT_ID, KEYCLOAK_ADMIN_CLIENT_SECRET replace KANIDM_*.
  • Version 1.27.0.

Verified on staging Keycloak

With bitborg-web-admin: create with groups 201, lookup 200, PUT 204, role map and unmap 204, available roles 200, action email permission passes, delete 204.

Still to verify on staging after merge

Sign-up with passkey and with password through first Forgejo sign-in, resend, Renovate toggle, logout, profile change.

Tests

589 pass. Lint, check, build and e2e pass.

Closes #311. **Do not merge before bitborg/bitborg-infra#631 is applied to prod.** Prod web tracks `latest`. Without the pin, this merge ships a Keycloak portal to a Kanidm prod. ## What - `src/lib/kanidm.ts` is replaced by `src/lib/keycloak.ts`: client-credentials token for `bitborg-web-admin`, create user with groups, exact lookup, profile read-merge-PUT, delete on rollback, `ent_renovate` role mapping, action email. - Sign-up: the user picks passkey or password. Required actions are stored on the user and Keycloak sends the link, which also verifies the email. Mail and reconcile run only after the consent row is stored. A failed consent write deletes the user. - Resend: re-sends only the actions still pending, to the address on file. Every outcome answers "sent". - Renovate toggle: role taken from the user's available or assigned realm roles, so the client needs no `view-realm`. - Session: groups are bare names, `entitlements` read for the panel. Existing sessions sign in again once. - Identity rules: Kanidm rules dropped, Forgejo intersection kept, minimum username length 3. - OIDC: issuer from `OIDC_ISSUER`, RS256 pinned, `client_secret_basic` checked, logout through the end-session endpoint. - A 401 from the admin API clears the cached token. - Env: `KEYCLOAK_URL`, `KEYCLOAK_REALM`, `KEYCLOAK_ADMIN_CLIENT_ID`, `KEYCLOAK_ADMIN_CLIENT_SECRET` replace `KANIDM_*`. - Version 1.27.0. ## Verified on staging Keycloak With `bitborg-web-admin`: create with groups 201, lookup 200, PUT 204, role map and unmap 204, available roles 200, action email permission passes, delete 204. ## Still to verify on staging after merge Sign-up with passkey and with password through first Forgejo sign-in, resend, Renovate toggle, logout, profile change. ## Tests 589 pass. Lint, check, build and e2e pass.
supernaut lade till 2 incheckningar 2026-10-09 13:50:42 +00:00
Replace the Kanidm client with a Keycloak admin client. Sign-up lets the
user pick a passkey or a password. The portal sets the matching required
actions and Keycloak mails the link, which also verifies the address.
Resend, profile and email-change writes, and the Renovate toggle (the
ent_renovate role) go through the same client. The session reads bare
group names and the entitlements claim. OIDC checks RS256 and client
secret basic auth and logs out through the end-session endpoint.

Env KEYCLOAK_URL, KEYCLOAK_REALM, KEYCLOAK_ADMIN_CLIENT_ID and
KEYCLOAK_ADMIN_CLIENT_SECRET replace KANIDM_*.

Closes #311
fix(auth): avoid role lookup and mail after consent is stored
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m55s
3c94f86e31
Read the ent_renovate role from the user's own role mappings, since the
service account cannot read /roles. Send the enrolment mail and trigger
the reconcile only after the consent row is stored, so a rolled-back
account never gets a link. Log the user id when a rollback delete
fails. Drop the cached admin token on a 401.

Refs #311
supernaut sammanfogade incheckning 72f087d8c0 till main 2026-10-09 14:23:33 +00:00
supernaut tog bort grenen feat/keycloak-accounts 2026-10-09 14:23:34 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-web!328
Ingen beskrivning angiven.