fix(projection): match owner names case-insensitively #42

Sammanfogat
supernaut sammanfogade 1 incheckning från fix/owner-name-case-insensitive in i main 2026-08-16 13:39:20 +00:00
Ägare

Closes #28.

The bug

Forgejo treats owner names case-insensitively. It routes on them that way and enforces uniqueness
through a lower_name column. The projection compared them case-sensitively. A name whose casing
differed from the declaration matched nothing.

The reconciler is authoritative. It adds the owner to the group it computed and removes it from
every other candidate. So an unmatched name does not just fail to grant. It demotes, and re-asserts
that demotion every tick. That is how a case-only rename of the platform org on 2026-08-04 blocked
every push and all CI for about 90 minutes.

The fix

ownerKey() normalises one name. ownerSet() builds the only kind of set owner names may be
matched against. Both sides of every comparison go through them.

Scope is wider than the issue asked, deliberately. #28 names the two exempt lists. The seven
Kanidm-derived tier sets are matched against the same Forgejo-supplied names. They carry the same
bug in per-user form: a casing mismatch silently drops a paying seat into the fail-closed
zero-quota participant group. Fixing only the exempt lists would have left that live.

Why OwnerSet is branded

A plain ReadonlySet<string> would let a later caller reintroduce a raw new Set() that compares
the wrong way. Nothing would catch it until the next incident. The brand makes ownerSet() the
only way to build one. That turned "did we get them all?" from a review question into a compile
error. It located every construction site in one typecheck, including the ones in the tests.

Deliberately not changed

  • reconcileIdentity matches on Kanidm UUID, not name. It never had the bug.
  • classifyProfile's name comparison stays case-sensitive. Kanidm owns the login. Renaming Forgejo
    to Kanidm's casing is the intended self-heal for this kind of drift. Normalising it would disable
    that.

Verification

pnpm typecheck, pnpm lint and pnpm test are clean. 118 tests pass.

The new tests are not vacuous. With ownerKey temporarily reduced to the identity function, 5 of
the 7 new projection tests fail:

× keeps an exempt org exempt after a case-only rename
× matches an exempt org however the DECLARATION is cased
× keeps an exempt user exempt after a case-only rename
× does not fail a paying user closed over casing alone
× matches the org-create and Actions entitlements case-insensitively too

The other two are the intended negative control (a different tenant org is still capped) and a case
the test helper alone would satisfy. That one was rewritten to build its set with the production
ownerSet().

Follow-up, not in this PR

#28 also notes the demotion path is silent. org <name>: quota=org-default is an INFO line
indistinguishable from the normal tenant case. Nothing alerts when the platform's own org gets
capped. That is a monitoring change in bitborg-infra, not a reconciler one. Filed as
bitborg-infra#423.

Closes #28. ## The bug Forgejo treats owner names case-insensitively. It routes on them that way and enforces uniqueness through a `lower_name` column. The projection compared them case-sensitively. A name whose casing differed from the declaration matched nothing. The reconciler is authoritative. It adds the owner to the group it computed and removes it from every other candidate. So an unmatched name does not just fail to grant. It demotes, and re-asserts that demotion every tick. That is how a case-only rename of the platform org on 2026-08-04 blocked every push and all CI for about 90 minutes. ## The fix `ownerKey()` normalises one name. `ownerSet()` builds the only kind of set owner names may be matched against. Both sides of every comparison go through them. Scope is wider than the issue asked, deliberately. #28 names the two exempt lists. The seven Kanidm-derived tier sets are matched against the same Forgejo-supplied names. They carry the same bug in per-user form: a casing mismatch silently drops a paying seat into the fail-closed zero-quota `participant` group. Fixing only the exempt lists would have left that live. ### Why OwnerSet is branded A plain `ReadonlySet<string>` would let a later caller reintroduce a raw `new Set()` that compares the wrong way. Nothing would catch it until the next incident. The brand makes `ownerSet()` the only way to build one. That turned "did we get them all?" from a review question into a compile error. It located every construction site in one typecheck, including the ones in the tests. ## Deliberately not changed - `reconcileIdentity` matches on Kanidm UUID, not name. It never had the bug. - `classifyProfile`'s name comparison stays case-sensitive. Kanidm owns the login. Renaming Forgejo to Kanidm's casing is the intended self-heal for this kind of drift. Normalising it would disable that. ## Verification `pnpm typecheck`, `pnpm lint` and `pnpm test` are clean. 118 tests pass. The new tests are not vacuous. With `ownerKey` temporarily reduced to the identity function, 5 of the 7 new projection tests fail: ``` × keeps an exempt org exempt after a case-only rename × matches an exempt org however the DECLARATION is cased × keeps an exempt user exempt after a case-only rename × does not fail a paying user closed over casing alone × matches the org-create and Actions entitlements case-insensitively too ``` The other two are the intended negative control (a different tenant org is still capped) and a case the test helper alone would satisfy. That one was rewritten to build its set with the production `ownerSet()`. ## Follow-up, not in this PR #28 also notes the demotion path is silent. `org <name>: quota=org-default` is an INFO line indistinguishable from the normal tenant case. Nothing alerts when the platform's own org gets capped. That is a monitoring change in bitborg-infra, not a reconciler one. Filed as bitborg-infra#423.
supernaut lade till 1 incheckning 2026-08-16 11:24:29 +00:00
fix(projection): match owner names case-insensitively
Alla kontroller lyckades
ci / ci (pull_request) Successful in 32s
fce71a7bec
Forgejo treats user and organisation names case-insensitively — it routes on
them that way and enforces uniqueness through a lower_name column. The
projection compared them case-sensitively, so a name whose casing differed from
the declaration matched nothing.

That is not a failure to grant. The reconciler is authoritative: it adds the
owner to the group it computed and removes it from every other candidate. An
unmatched name is actively DEMOTED, and re-demoted every tick, which defeats any
manual repair. Renaming the platform org bitborg -> Bitborg on 2026-08-04 capped
it at the tenant quota and disabled Actions, blocking every push and all CI for
~90 minutes.

Normalises both sides of every owner-name comparison, not just the two exempt
lists named in the issue. The Kanidm-derived tier sets carry the same hazard in
per-user form: a casing mismatch there silently drops a paying seat into the
fail-closed zero-quota participant group.

OwnerSet is branded so the sets can only be built through ownerSet(). A plain
ReadonlySet<string> would let a later caller reintroduce a raw new Set() that
compares the wrong way, and the brand turned that from a review question into a
compile error — it found every construction site in one pass.

reconcileIdentity is untouched: it matches on Kanidm UUID, not name, so it never
had the bug. classifyProfile's name comparison is also left case-sensitive on
purpose — Kanidm owns the login, so renaming Forgejo to Kanidm's casing is the
intended self-heal for exactly this drift.

Five of the seven new projection tests fail against the old comparison.
supernaut sammanfogade incheckning 6327f8a50e till main 2026-08-16 13:39:20 +00:00
supernaut tog bort grenen fix/owner-name-case-insensitive 2026-08-16 13:39:20 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-08-16 13:39:20 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-09-29 13:50:31 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-09-29 13:54:28 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-02 17:57:03 +00:00
supernaut refererade denna ändringsförfrågan från en incheckning 2026-10-02 17:57:03 +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-auth-reconciler!42
Ingen beskrivning angiven.