Re-evaluate OIDC admin groups on Admin Mode re-entry

What does this MR do and why?

Re-entering Admin Mode through OIDC now re-evaluates the user's OIDC admin_groups and required_groups membership, matching the SAML fix in !264737 (merged). A user removed from the IdP admin group can no longer enter Admin Mode, and loses the admin flag at that point instead of at their next full sign-in.

This MR is stacked on !264737 (merged) and targets its branch. Merge that one first.

Details

With the oidc_client_groups_claim licensed feature, OIDC users are built by Gitlab::Auth::Oidc::User, which derives the admin flag from admin_groups on sign-in. admin_mode_flow skipped that sync, the same gap the SAML MR closes.

  • The EE admin_access_after_saml_sync? becomes admin_access_after_sync?, and its new sync_user_on_admin_mode_entry? predicate covers SAML providers and Gitlab::Auth::Oidc::User. The CE stub only changes name.
  • Like SAML, it calls auth_user.save, which for OIDC is exactly what find_and_update! already did, so there is no extra group or seat sync.
  • An OIDC user who no longer meets required_groups makes save raise SignupDisabledError. This is rescued, so Admin Mode is refused. As on OIDC sign-in, nothing is persisted in that case and the admin flag is kept.
  • New behaviour for that case: with only the SAML fix, an OIDC user outside required_groups still passed admin_mode_flow, because the SAML-only check returned true. This MR refuses Admin Mode for them.
  • save also persists the recomputed auditor and external flags. OIDC external_groups takes precedence over admin_groups, so a user who is now in an external group loses admin and is refused.
  • Without the licensed feature, OIDC uses Gitlab::Auth::OAuth::User, which has no group-derived admin flag, so there is nothing to re-evaluate and behaviour is unchanged.
  • Plain OAuth providers (GitHub, Google, and so on) have no admin_groups setting, so this gap does not apply to them.

Reproduced and validated on a GDK with a mock OIDC provider (navikt/mock-oauth2-server) and admin_groups: ["Admins"]:

Scenario Before (SAML-only fix) With this MR
In Admins Admin Mode active Admin Mode active
Removed from Admins Admin Mode active, admin stays true Refused, admin set to false

The admin_groups section of doc/administration/auth/oidc.md now says that OIDC Admin Mode re-entry re-evaluates it.

References

Screenshots or screen recordings

Not applicable: no UI changes. A refused re-entry uses the existing "Invalid login or password" redirect to the Admin Mode sign-in page.

How to set up and validate locally

  1. Run a test OIDC provider, for example docker run -p 8081:8080 -e JSON_CONFIG='{"interactiveLogin":true}' ghcr.io/navikt/mock-oauth2-server:2.1.10.
  2. Configure an openid_connect provider pointing at it, with client_options: { gitlab: { admin_groups: ["Admins"] } }, and make sure the oidc_client_groups_claim licensed feature is available.
  3. Sign in through OIDC with the claim {"groups": ["Admins"]} and enter Admin Mode.
  4. Leave Admin Mode, then re-enter it through OIDC with the claim {"groups": ["Developers"]}.
  5. Confirm Admin Mode is refused and that User.find_by(username: '<user>').admin? returns false in the Rails console.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

This touches authentication and Admin Mode, so it needs AppSec review.

🤖 Generated with Claude Code

Edited by Michael Eddington

Merge request reports

Loading
Loading