feat(billing): write plan entitlements to keycloak #127

Sammanfogat
supernaut sammanfogade 2 incheckningar från feat/keycloak-entitlements in i main 2026-10-09 13:29:51 +00:00
Ägare

Refs #111. Staging verification is still open, so keep #111 open after merge.

What

  • src/kanidm.ts is replaced by src/keycloak.ts. The Identity interface and the billing.ts call sites are unchanged.
  • Client-credentials token for bitborg-billing, cached and refreshed 30 s before expiry.
  • User lookup by exact username. It fails closed unless exactly one user matches.
  • tier_pro membership add and remove by exact group name. Keycloak returns 204 for a repeat add or an absent remove.
  • Errors carry status and a short body prefix, never usernames, ids or the secret.
  • Env: KEYCLOAK_URL, KEYCLOAK_REALM, KEYCLOAK_CLIENT_ID, KEYCLOAK_CLIENT_SECRET replace KANIDM_API_URL and KANIDM_PAYMENT_TOKEN.
  • Version 0.10.0.

Not in this PR

  • Add-on role mapping. Nothing writes add-ons yet, and bitborg-billing cannot read realm roles (403 on staging). It comes with the first add-on writer.

Deploy

Merging deploys nothing: infra pins the image tag. The billing role env must switch to KEYCLOAK_* in the same infra change that moves the tag to v0.10.0, or the service fails on start.

Tests

413 pass with TEST_DATABASE_URL. Covers token reuse and expiry, idempotent add and remove, zero, two and prefix user matches, missing group, 403 and token refusal, no identifiers in errors.

Refs #111. Staging verification is still open, so keep #111 open after merge. ## What - `src/kanidm.ts` is replaced by `src/keycloak.ts`. The `Identity` interface and the `billing.ts` call sites are unchanged. - Client-credentials token for `bitborg-billing`, cached and refreshed 30 s before expiry. - User lookup by exact username. It fails closed unless exactly one user matches. - `tier_pro` membership add and remove by exact group name. Keycloak returns 204 for a repeat add or an absent remove. - Errors carry status and a short body prefix, never usernames, ids or the secret. - Env: `KEYCLOAK_URL`, `KEYCLOAK_REALM`, `KEYCLOAK_CLIENT_ID`, `KEYCLOAK_CLIENT_SECRET` replace `KANIDM_API_URL` and `KANIDM_PAYMENT_TOKEN`. - Version 0.10.0. ## Not in this PR - Add-on role mapping. Nothing writes add-ons yet, and `bitborg-billing` cannot read realm roles (403 on staging). It comes with the first add-on writer. ## Deploy Merging deploys nothing: infra pins the image tag. The billing role env must switch to `KEYCLOAK_*` in the same infra change that moves the tag to `v0.10.0`, or the service fails on start. ## Tests 413 pass with `TEST_DATABASE_URL`. Covers token reuse and expiry, idempotent add and remove, zero, two and prefix user matches, missing group, 403 and token refusal, no identifiers in errors.
supernaut lade till 2 incheckningar 2026-10-09 13:27:15 +00:00
Replace the Kanidm client with a Keycloak admin client for the
bitborg-billing client. It adds and removes tier_pro membership and
add-on realm role mappings, finding the user by exact username and
failing when there is not exactly one match.

Closes #111
refactor(billing): drop unused role mapping from the Keycloak client
Alla kontroller lyckades
ci / ci (pull_request) Successful in 2m1s
89c2798816
Nothing calls addRole or removeRole. Role mapping returns with the
first add-on writer. Also update Kanidm wording in entitlements.

Refs #111
supernaut schemalade den här ändringsförfrågan för automatisk sammanfogning när alla kontroller lyckas 2026-10-09 13:27:51 +00:00
supernaut sammanfogade incheckning 25c180402d till main 2026-10-09 13:29:51 +00:00
supernaut tog bort grenen feat/keycloak-entitlements 2026-10-09 13:29:51 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-09 13:29:53 +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-payment!127
Ingen beskrivning angiven.