feat: prompt a reconcile after each tier_pro change #73

Sammanfogat
supernaut sammanfogade 2 incheckningar från feat/14-shim-trigger in i main 2026-10-03 19:32:09 +00:00
Ägare

What

  • After each successful Kanidm tier_pro write (grant, revoke, withdrawal, sweep), the service
    posts to the reconcile auth shim with a bearer token. Refs #14.
  • Fix the stale ent_orgs nesting comment in src/entitlements.ts. Refs #15.

How

  • kanidmIdentity takes an optional onChange callback, called after the Kanidm write succeeds.
    All four paths go through deps.identity, so one hook covers them. No Kanidm write, no call
    (for example a revoke skipped because another live subscription remains).
  • src/reconcile-trigger.ts: POST with Authorization: Bearer, no body, 3 s timeout. Returns
    at once and never throws. Failures log the status or error message, never the token.
  • Config is RECONCILE_TRIGGER_URL and RECONCILE_TRIGGER_TOKEN. Either unset or empty: nothing
    is sent and the 5-minute tick applies the change.
  • The shim only needs "reconcile please", so no desired state is sent.
  • .env.example and README updated.

Tested

pnpm test: 227 passed, 46 skipped (the Postgres tests, no TEST_DATABASE_URL here). 7 new tests:
bearer and no body, failing shim and 401 logged without the token, unset env sends nothing,
fires after grant and revoke, not after a failed Kanidm write, hanging or failing shim does not
fail the membership write. pnpm lint, pnpm typecheck, pnpm build clean.

Infra side (not in this PR, needs an apply)

The shim role already accepts a payment source. Nothing to change in the shim.

  1. Vault: set vault_payments_webhook_token (openssl rand -hex 32). It is declared and empty in
    group_vars/vault.example.yml. Empty means the shim omits the payment source.
  2. Apply --tags reconciler: re-renders reconcile-shim.env.j2 with payment=<token> and
    restarts the shim (reconcile_shim_env_file).
  3. roles/billing/templates/billing.env.j2: add, only when the token is non-empty,
    RECONCILE_TRIGGER_URL={{ reconcile_shim_internal_url }} and
    RECONCILE_TRIGGER_TOKEN={{ vault_payments_webhook_token }}.
    reconcile_shim_internal_url is a roles/reconciler default
    (http://bitborg-reconcile-trigger:8099/). Check it resolves in a --tags billing run, or
    copy it into group_vars. Then apply --tags billing.
  4. No Caddy route or nftables allowlist is needed: the billing container and the shim share the
    bitborg_network podman network on one host. #14 assumed cross-host. Revisit if billing moves.
  5. Not done here: confirm the Loki "event-path silent" alert and kick logs cover the payment
    source.

Open questions

  • #15 asked for three things. The comment fix is done. The other two are not: a recorded decision on
    how the priced org add-on is granted, and handling of overwrite_members: true on ent_orgs.
    The comment now states both facts. Today a paying org customer gets no org-creation. The issue
    closes on merge as instructed, so open a follow-up for the decision.
  • #14 is not closed by this PR: it stays open until the infra apply above lands.
## What - After each successful Kanidm `tier_pro` write (grant, revoke, withdrawal, sweep), the service posts to the reconcile auth shim with a bearer token. Refs #14. - Fix the stale `ent_orgs` nesting comment in `src/entitlements.ts`. Refs #15. ## How - `kanidmIdentity` takes an optional `onChange` callback, called after the Kanidm write succeeds. All four paths go through `deps.identity`, so one hook covers them. No Kanidm write, no call (for example a revoke skipped because another live subscription remains). - `src/reconcile-trigger.ts`: `POST` with `Authorization: Bearer`, no body, 3 s timeout. Returns at once and never throws. Failures log the status or error message, never the token. - Config is `RECONCILE_TRIGGER_URL` and `RECONCILE_TRIGGER_TOKEN`. Either unset or empty: nothing is sent and the 5-minute tick applies the change. - The shim only needs "reconcile please", so no desired state is sent. - `.env.example` and README updated. ## Tested `pnpm test`: 227 passed, 46 skipped (the Postgres tests, no `TEST_DATABASE_URL` here). 7 new tests: bearer and no body, failing shim and 401 logged without the token, unset env sends nothing, fires after grant and revoke, not after a failed Kanidm write, hanging or failing shim does not fail the membership write. `pnpm lint`, `pnpm typecheck`, `pnpm build` clean. ## Infra side (not in this PR, needs an apply) The shim role already accepts a `payment` source. Nothing to change in the shim. 1. Vault: set `vault_payments_webhook_token` (`openssl rand -hex 32`). It is declared and empty in `group_vars/vault.example.yml`. Empty means the shim omits the `payment` source. 2. Apply `--tags reconciler`: re-renders `reconcile-shim.env.j2` with `payment=<token>` and restarts the shim (`reconcile_shim_env_file`). 3. `roles/billing/templates/billing.env.j2`: add, only when the token is non-empty, `RECONCILE_TRIGGER_URL={{ reconcile_shim_internal_url }}` and `RECONCILE_TRIGGER_TOKEN={{ vault_payments_webhook_token }}`. `reconcile_shim_internal_url` is a `roles/reconciler` default (`http://bitborg-reconcile-trigger:8099/`). Check it resolves in a `--tags billing` run, or copy it into `group_vars`. Then apply `--tags billing`. 4. No Caddy route or nftables allowlist is needed: the billing container and the shim share the `bitborg_network` podman network on one host. #14 assumed cross-host. Revisit if billing moves. 5. Not done here: confirm the Loki "event-path silent" alert and kick logs cover the `payment` source. ## Open questions - #15 asked for three things. The comment fix is done. The other two are not: a recorded decision on how the priced org add-on is granted, and handling of `overwrite_members: true` on `ent_orgs`. The comment now states both facts. Today a paying org customer gets no org-creation. The issue closes on merge as instructed, so open a follow-up for the decision. - #14 is not closed by this PR: it stays open until the infra apply above lands.
supernaut lade till 2 incheckningar 2026-10-03 00:14:01 +00:00
A grant or revoke only reached Forgejo on the next 5-minute reconcile tick.
After a successful Kanidm membership write the service now posts to the
reconcile auth shim with its bearer token (ADR 0037). The request is
fire-and-forget with a 3 s timeout and carries no state, so a down shim
cannot fail or delay the webhook. Unset RECONCILE_TRIGGER_URL or
RECONCILE_TRIGGER_TOKEN and nothing is sent.

Refs #14
docs: correct the entitlements comment on org-creation
Alla kontroller lyckades
ci / ci (pull_request) Successful in 1m47s
0b3ac9d25f
The comment said ent_orgs lists tier_pro, so every seat can create
organisations. ent_orgs was emptied and nothing is nested into it, so
that is no longer true. Only the runner groups still inherit from
tier_pro. The comment now says so, and notes that a per-person ent_orgs
grant would be removed by the next converge (overwrite_members).

Closes #15
supernaut sammanfogade incheckning 02af93df0e till main 2026-10-03 19:32:09 +00:00
supernaut tog bort grenen feat/14-shim-trigger 2026-10-03 19:32:10 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-03 19:32:11 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-04 06:03:41 +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!73
Ingen beskrivning angiven.