v16 spike: IdP-driven team/org membership via dynamic OIDC group mappings #77

Öppen
öppnade 2026-07-17 11:52:21 +00:00 av supernaut · 4 kommentarer
Ägare

Tier 2 v16 follow-up: spike. Deferred until tenant orgs exist. Gated on #73 (landed, prod on Forgejo 16).

Forgejo v16 ships dynamic OIDC group mappings (upstream PR forgejo#11656, docs). Placeholder patterns on the auth source map IdP group claims to Forgejo org and team membership at login.

This is net-new membership sync. The reconciler does no team or org membership today. The mapping cannot set quota groups, allow_create_organization, the has_actions unit or Renovate collaborators, so it complements the reconciler and replaces nothing (ADR 0017).

How it works in v16

The auth source reads one group claim (--group-claim-name) from the ID token or userinfo at login. The group names in that claim are matched against the configured mappings. Config lives on the Forgejo auth source (forgejo admin auth add-oauth / update-oauth, or Site Admin, Authentication Sources).

CLI flag Purpose
--group-claim-name Claim that carries group names. One claim, shared by every mapping below.
--group-team-map Static JSON map: group to {org: [teams]}.
--group-team-map-removal Remove users from mapped teams they no longer claim.
--dyn-group-maps Dynamic placeholder patterns, e.g. ["group-{org}-{team}"].
--dyn-group-maps-removal Removal for the dynamic path.
--admin-group Claim value that grants site admin.
--restricted-group Claim value that marks the account restricted.

Dynamic patterns take {org} and {team} from the group name. A claimed group group-acme-developers with pattern group-{org}-{team} adds the user to org acme, team developers. New orgs need no config change.

Limits:

  • Login time only. Membership lags until the user signs in again. There is no timer.
  • Adds to existing orgs and teams only. It never creates one.
  • Org and team names are lowercased for matching.
  • The same claim feeds admin, restricted, static and dynamic mappings.

Risk: the removal toggles

With a removal toggle on, the mapping is authoritative over team membership. It strips any team a user was added to by hand. Keep removal off at first and treat the mapping as additive. Enable it per org only once trusted.

Keycloak specifics

  • Groups come from the groups claim. The mapper in opentofu/keycloak/clients.tofu (keycloak_openid_group_membership_protocol_mapper.groups) sets claim_name = "groups" and full_path = false, so the claim holds bare group names.
  • Forgejo already reads that claim: forgejo_oidc_group_claim is groups and the admin value is forgejo_admins when Kanidm is off (ansible/roles/forgejo/defaults/main.yml).
  • The old forgejo_role claim-map prerequisite is gone. Team groups are plain Keycloak groups, added in opentofu/keycloak/groups.tofu.
  • Keep the team group names distinct from tier_* and forgejo_*, so the reconciler's group handling stays unambiguous. Mind the lowercasing.
  • roles/forgejo/tasks/oidc-source.yml now updates a drifted source through update-oauth. Add the new flags there.

Phased plan

  1. Local-forgejo spike, never prod first:
    • Map one Keycloak group to one existing team with a dynamic pattern. Decode the ID token and confirm the group arrives in groups.
    • Exercise the removal toggle on purpose. Confirm what it strips, and whether it can remove operators from hand-curated teams.
    • Decide the naming convention for groups that encode {org} and {team}, for example fjteam-{org}-{team}.
  2. First real mapping: a Keycloak group to the bitborg org owners or maintainers team. Removal off, additive only.
  3. When tenant orgs ship: a dynamic pattern maps fjteam-{org}-{team} groups to tenant org teams.
  4. If adopted: design doc and ADR update (ADR 0016 moves team maps from "available, unused" to "in use"), and wire the flags into roles/forgejo/tasks/oidc-source.yml.

Recommendation: conditional go, but not now. With a handful of users and one first-party org there is little team management to automate. Adopt it when the multi-tenant team product ships.

**Tier 2 v16 follow-up: spike.** Deferred until tenant orgs exist. Gated on #73 (landed, prod on Forgejo 16). Forgejo v16 ships dynamic OIDC group mappings (upstream PR [forgejo#11656](https://codeberg.org/forgejo/forgejo/pulls/11656), [docs](https://forgejo.org/docs/latest/admin/advanced/oidc-group-mappings/)). Placeholder patterns on the auth source map IdP group claims to Forgejo org and team membership at login. This is net-new membership sync. The reconciler does no team or org membership today. The mapping cannot set quota groups, `allow_create_organization`, the `has_actions` unit or Renovate collaborators, so it complements the reconciler and replaces nothing (ADR 0017). ## How it works in v16 The auth source reads one group claim (`--group-claim-name`) from the ID token or userinfo at login. The group names in that claim are matched against the configured mappings. Config lives on the Forgejo auth source (`forgejo admin auth add-oauth` / `update-oauth`, or Site Admin, Authentication Sources). | CLI flag | Purpose | | -------------------------- | ------------------------------------------------------------------------------- | | `--group-claim-name` | Claim that carries group names. One claim, shared by every mapping below. | | `--group-team-map` | Static JSON map: group to `{org: [teams]}`. | | `--group-team-map-removal` | Remove users from mapped teams they no longer claim. | | `--dyn-group-maps` | Dynamic placeholder patterns, e.g. `["group-{org}-{team}"]`. | | `--dyn-group-maps-removal` | Removal for the dynamic path. | | `--admin-group` | Claim value that grants site admin. | | `--restricted-group` | Claim value that marks the account restricted. | Dynamic patterns take `{org}` and `{team}` from the group name. A claimed group `group-acme-developers` with pattern `group-{org}-{team}` adds the user to org `acme`, team `developers`. New orgs need no config change. Limits: - Login time only. Membership lags until the user signs in again. There is no timer. - Adds to existing orgs and teams only. It never creates one. - Org and team names are lowercased for matching. - The same claim feeds admin, restricted, static and dynamic mappings. ## Risk: the removal toggles With a removal toggle on, the mapping is authoritative over team membership. It strips any team a user was added to by hand. Keep removal off at first and treat the mapping as additive. Enable it per org only once trusted. ## Keycloak specifics - Groups come from the `groups` claim. The mapper in `opentofu/keycloak/clients.tofu` (`keycloak_openid_group_membership_protocol_mapper.groups`) sets `claim_name = "groups"` and `full_path = false`, so the claim holds bare group names. - Forgejo already reads that claim: `forgejo_oidc_group_claim` is `groups` and the admin value is `forgejo_admins` when Kanidm is off (`ansible/roles/forgejo/defaults/main.yml`). - The old `forgejo_role` claim-map prerequisite is gone. Team groups are plain Keycloak groups, added in `opentofu/keycloak/groups.tofu`. - Keep the team group names distinct from `tier_*` and `forgejo_*`, so the reconciler's group handling stays unambiguous. Mind the lowercasing. - `roles/forgejo/tasks/oidc-source.yml` now updates a drifted source through `update-oauth`. Add the new flags there. ## Phased plan 1. Local-forgejo spike, never prod first: - [ ] Map one Keycloak group to one existing team with a dynamic pattern. Decode the ID token and confirm the group arrives in `groups`. - [ ] Exercise the removal toggle on purpose. Confirm what it strips, and whether it can remove operators from hand-curated teams. - [ ] Decide the naming convention for groups that encode `{org}` and `{team}`, for example `fjteam-{org}-{team}`. 2. First real mapping: a Keycloak group to the `bitborg` org `owners` or `maintainers` team. Removal off, additive only. 3. When tenant orgs ship: a dynamic pattern maps `fjteam-{org}-{team}` groups to tenant org teams. 4. If adopted: design doc and ADR update (ADR 0016 moves team maps from "available, unused" to "in use"), and wire the flags into `roles/forgejo/tasks/oidc-source.yml`. Recommendation: conditional go, but not now. With a handful of users and one first-party org there is little team management to automate. Adopt it when the multi-tenant team product ships.
Upphovsperson
Ägare

Spike written up internally (not committed). Headline: conditional GO, but not now — defer until the tenant-org/team product exists.

What it does (v16, PR 11656 + docs): the OIDC auth source reads one group claim (--group-claim-name) at login and syncs org-team membership. Static map (--group-team-map), dynamic placeholders {org}/{team} (--dyn-group-maps), plus removal toggles (--group-team-map-removal / --dyn-group-maps-removal) and admin/restricted group values. Login-time only (no timer); adds to existing orgs/teams only (won't create); names lowercased.

Fit: net-new — the reconciler does no team membership today, so this replaces nothing and complements it (reconciler keeps quota/org-create/has_actions/Renovate; ADR 0016/0017 — none are claim-mappable). Real value is future tenant-org teams; near-zero today (~a handful of users, one first-party org).

Interactions: login-time ⇒ membership lags to next login vs the reconciler's ~15-min timer; removal toggle is the "dangerous half" (can strip hand-curated teams) — keep off, additive only. Orthogonal to #80 (JWT).

Prerequisite (do first): our single group claim is already spoken-for — --group-claim-name=forgejo_role with --admin-group=admin; scopes include groups. Cleanest path: extend the Kanidm forgejo_role claim-map to also emit team tokens (keep admin intact) rather than repoint to raw groups. Verify Kanidm scope/claim-map on the live client before adopting. Also: oidc-source.yml is add-only — enabling on the existing source needs auth update-oauth (runbook).

**Spike written up** internally (not committed). Headline: **conditional GO, but not now** — defer until the tenant-org/team product exists. **What it does (v16, PR 11656 + [docs](https://forgejo.org/docs/latest/admin/advanced/oidc-group-mappings/)):** the OIDC auth source reads one group claim (`--group-claim-name`) at **login** and syncs org-**team** membership. Static map (`--group-team-map`), dynamic placeholders `{org}/{team}` (`--dyn-group-maps`), plus removal toggles (`--group-team-map-removal` / `--dyn-group-maps-removal`) and admin/restricted group values. Login-time only (no timer); adds to **existing** orgs/teams only (won't create); names lowercased. **Fit:** net-new — the reconciler does **no** team membership today, so this **replaces nothing** and complements it (reconciler keeps quota/org-create/`has_actions`/Renovate; ADR 0016/0017 — none are claim-mappable). Real value is future tenant-org teams; near-zero today (~a handful of users, one first-party org). **Interactions:** login-time ⇒ membership **lags to next login** vs the reconciler's ~15-min timer; removal toggle is the "dangerous half" (can strip hand-curated teams) — keep off, additive only. Orthogonal to #80 (JWT). **Prerequisite (do first):** our single group claim is already spoken-for — `--group-claim-name=forgejo_role` with `--admin-group=admin`; scopes include `groups`. Cleanest path: extend the Kanidm `forgejo_role` claim-map to also emit team tokens (keep admin intact) rather than repoint to raw `groups`. Verify Kanidm scope/claim-map on the live client before adopting. Also: `oidc-source.yml` is add-only — enabling on the existing source needs `auth update-oauth` (runbook).
Upphovsperson
Ägare

Retarget: Kanidm is being replaced by Keycloak before launch (bitborg/bitborg-docs#127). After cutover this reads Keycloak groups, roles and user attributes instead of Kanidm.

Retarget: Kanidm is being replaced by Keycloak before launch (bitborg/bitborg-docs#127). After cutover this reads Keycloak groups, roles and user attributes instead of Kanidm.
Upphovsperson
Ägare

Forgejo v17 note. The group-team map flags (--group-team-map, --group-team-map-removal, --dyn-group-maps, --dyn-group-maps-removal) are unchanged from 16.0.6, so this can be prepared now.

v17 changes:

  • A dynamic map pattern needs exactly one {org} and one {team}, or it is skipped with an error log. The rest of the pattern is regex-quoted.
  • Maps are cached per login source, so changing them with update-oauth needs a Forgejo restart.
  • Members of an org's last owner team are skipped on removal.

Prep: add the flags to both argv lists and the drift compare in oidc-source.yml, behind a variable that stays empty. The Keycloak groups mapper must emit bare names: a leading / does not match the placeholders.

Forgejo v17 note. The group-team map flags (`--group-team-map`, `--group-team-map-removal`, `--dyn-group-maps`, `--dyn-group-maps-removal`) are unchanged from 16.0.6, so this can be prepared now. v17 changes: - A dynamic map pattern needs exactly one `{org}` and one `{team}`, or it is skipped with an error log. The rest of the pattern is regex-quoted. - Maps are cached per login source, so changing them with `update-oauth` needs a Forgejo restart. - Members of an org's last owner team are skipped on removal. Prep: add the flags to both argv lists and the drift compare in `oidc-source.yml`, behind a variable that stays empty. The Keycloak groups mapper must emit bare names: a leading `/` does not match the placeholders.
Upphovsperson
Ägare

Forgejo v17.0.0 (live since 2026-10-17) hardens dynamic OIDC group mappings (PR13056). It escapes regex characters, skips patterns with a wrong placeholder count and never removes the last owner of a team. That removes the worst failure mode of the removal toggles. Spike on v17.

Forgejo v17.0.0 (live since 2026-10-17) hardens dynamic OIDC group mappings (PR13056). It escapes regex characters, skips patterns with a wrong placeholder count and never removes the last owner of a team. That removes the worst failure mode of the removal toggles. Spike on v17.
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-infra#77
Ingen beskrivning angiven.