OIDC sign-in resets manually assigned roles to the default role #646

Closed
opened 2026-11-09 10:36:48 +01:00 by simon · 0 comments
Owner

Problem

With OIDC_ADMIN_GROUP_NAME set, every OIDC sign-in overwrites the user's role. Users in the admin group get Admin; everyone else gets the default role ("Mitglied"), including users an admin deliberately gave another role (e.g. a board role based on normal_user). Those users lose their permissions on their next sign-in, for example to review join requests.

Reported by a club using Authentik with OIDC_ADMIN_GROUP_NAME="admin", OIDC_GROUPS_CLAIM=groups, OIDC_ONLY="true".

Cause

Mv.OidcRoleSync.apply_admin_role_from_user_info/3 runs after every OIDC registration and sign-in (after_action hook in Mv.Accounts.User) and does:

target_role = if admin_group in groups, do: :admin, else: :mitglied

It only knows two roles and does not look at the current one. Existing tests pin the Admin ↔ Mitglied cases (test/mv/oidc_role_sync_test.exs), but no test covers a user holding any other role.

  • Missing or empty groups claim demotes every admin. If the provider stops sending the claim (claim renamed, scope dropped, provider misconfigured), groups is [], so every Admin is downgraded on sign-in.
  • Failures are silent. do_set_role/2 maps {:error, _} to :ok. A refused change (e.g. the last-admin guard EnsureAdminRemains) leaves no trace in the log.
  • No visibility in the UI. The role edit form does not say that a manual role change will be overwritten on the next OIDC sign-in.

Intended behavior (decision needed)

  • A — Only manage the admin bit (minimal fix). In the admin group → Admin. Not in the group → downgrade to the default role only if the user currently is Admin; any other role stays untouched.
  • B — Never demote. The group only promotes to Admin; removing admin rights is a manual action in Mila.
  • C — General group → role mapping. Configure several groups, each mapped to a role (e.g. vorstand → board role); users in no mapped group keep their role.

A fixes the reported case with the smallest change; C is a feature in its own right and can follow later.

Acceptance criteria

  • A user holding a role other than Admin and the default role keeps it across OIDC sign-ins (A/B), or gets the role their groups map to (C).
  • A sign-in whose token carries no groups claim at all does not change any role, and logs a warning.
  • A role change refused by the sync (e.g. last admin) is logged.
  • The role edit form / settings explain which roles OIDC manages.
  • Tests cover: custom role kept, Admin promotion, Admin demotion (per chosen option), missing claim, empty claim, last-admin refusal.

Workaround until fixed

Unset OIDC_ADMIN_GROUP_NAME (and the "Admin group name" setting, if set) and redeploy: the sync becomes a no-op and roles assigned in Mila persist. Admin rights are then no longer granted via the identity-provider group. Users whose role was reset need it reassigned once.

## Problem With `OIDC_ADMIN_GROUP_NAME` set, every OIDC sign-in overwrites the user's role. Users in the admin group get Admin; **everyone else gets the default role ("Mitglied")**, including users an admin deliberately gave another role (e.g. a board role based on `normal_user`). Those users lose their permissions on their next sign-in, for example to review join requests. Reported by a club using Authentik with `OIDC_ADMIN_GROUP_NAME="admin"`, `OIDC_GROUPS_CLAIM=groups`, `OIDC_ONLY="true"`. ## Cause `Mv.OidcRoleSync.apply_admin_role_from_user_info/3` runs after every OIDC registration and sign-in (`after_action` hook in `Mv.Accounts.User`) and does: ```elixir target_role = if admin_group in groups, do: :admin, else: :mitglied ``` It only knows two roles and does not look at the current one. Existing tests pin the Admin ↔ Mitglied cases (`test/mv/oidc_role_sync_test.exs`), but no test covers a user holding any other role. ## Related risks found in the same code - **Missing or empty groups claim demotes every admin.** If the provider stops sending the claim (claim renamed, scope dropped, provider misconfigured), `groups` is `[]`, so every Admin is downgraded on sign-in. - **Failures are silent.** `do_set_role/2` maps `{:error, _}` to `:ok`. A refused change (e.g. the last-admin guard `EnsureAdminRemains`) leaves no trace in the log. - **No visibility in the UI.** The role edit form does not say that a manual role change will be overwritten on the next OIDC sign-in. ## Intended behavior (decision needed) - **A — Only manage the admin bit (minimal fix).** In the admin group → Admin. Not in the group → downgrade to the default role *only if the user currently is Admin*; any other role stays untouched. - **B — Never demote.** The group only promotes to Admin; removing admin rights is a manual action in Mila. - **C — General group → role mapping.** Configure several groups, each mapped to a role (e.g. `vorstand` → board role); users in no mapped group keep their role. A fixes the reported case with the smallest change; C is a feature in its own right and can follow later. ## Acceptance criteria - A user holding a role other than Admin and the default role keeps it across OIDC sign-ins (A/B), or gets the role their groups map to (C). - A sign-in whose token carries no groups claim at all does not change any role, and logs a warning. - A role change refused by the sync (e.g. last admin) is logged. - The role edit form / settings explain which roles OIDC manages. - Tests cover: custom role kept, Admin promotion, Admin demotion (per chosen option), missing claim, empty claim, last-admin refusal. ## Workaround until fixed Unset `OIDC_ADMIN_GROUP_NAME` (and the "Admin group name" setting, if set) and redeploy: the sync becomes a no-op and roles assigned in Mila persist. Admin rights are then no longer granted via the identity-provider group. Users whose role was reset need it reassigned once.
simon closed this issue 2026-11-09 18:20:55 +01:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
local-it/mitgliederverwaltung#646
No description provided.