Key entitlements by Keycloak user id, not username #81

Stängd
öppnade 2026-10-08 21:12:31 +00:00 av supernaut · 0 kommentarer
Ägare

What

Tier and role sets hold Keycloak usernames and are matched against the Forgejo login. The identity step joins on the user id (login_name) and renames accounts.

Why

The two joins disagree. A rename Forgejo refuses leaves the old login in place while the sets carry the new name.

Failing case

A Keycloak user alice is renamed alice2. Forgejo refuses the rename (422, name taken or reserved). The account stays alice. The sets now hold alice2, so a paying user falls back to the zero-quota participant group and loses org-create and Actions. This repeats every run. A local Forgejo account named like a Keycloak user, with an empty login_name, would also inherit that user's entitlements.

Fix

Return ids with each member from the Keycloak reads. Key the sets by id. Map each Forgejo account by login_name. Fall back to the normalised login only for accounts with an empty login_name (exempt, break-glass).

Done when

  • A refused rename keeps the user's entitlements
  • A local account with a colliding name gets none
  • Case-insensitive matching is kept for the fallback

Plan outline

  1. Return {id, username} from getGroupMembers, getRoleUsers and resolveRoleMembers.
  2. Build UserSets keyed by id. Build a login_name to login map from listAccounts.
  3. Pass the account (login, login_name) to classifyUser. Check id first, then the normalised-login fallback for exempt and local accounts.
  4. Keep the all-tiers-empty refusal working on the new set type. Do the groups-by-id change first.
  5. Add tests for a refused rename and a name collision. Minor version bump, no env change.
## What Tier and role sets hold Keycloak usernames and are matched against the Forgejo login. The identity step joins on the user id (`login_name`) and renames accounts. ## Why The two joins disagree. A rename Forgejo refuses leaves the old login in place while the sets carry the new name. ## Failing case A Keycloak user `alice` is renamed `alice2`. Forgejo refuses the rename (422, name taken or reserved). The account stays `alice`. The sets now hold `alice2`, so a paying user falls back to the zero-quota participant group and loses org-create and Actions. This repeats every run. A local Forgejo account named like a Keycloak user, with an empty `login_name`, would also inherit that user's entitlements. ## Fix Return ids with each member from the Keycloak reads. Key the sets by id. Map each Forgejo account by `login_name`. Fall back to the normalised login only for accounts with an empty `login_name` (exempt, break-glass). ## Done when - [ ] A refused rename keeps the user's entitlements - [ ] A local account with a colliding name gets none - [ ] Case-insensitive matching is kept for the fallback ## Plan outline 1. Return `{id, username}` from `getGroupMembers`, `getRoleUsers` and `resolveRoleMembers`. 2. Build UserSets keyed by id. Build a login_name to login map from `listAccounts`. 3. Pass the account (login, login_name) to `classifyUser`. Check id first, then the normalised-login fallback for exempt and local accounts. 4. Keep the all-tiers-empty refusal working on the new set type. Do the groups-by-id change first. 5. Add tests for a refused rename and a name collision. Minor version bump, no env change.
Logga in för att delta i denna konversation.
Ingen milstolpe
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#81
Ingen beskrivning angiven.