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?becomesadmin_access_after_sync?, and its newsync_user_on_admin_mode_entry?predicate covers SAML providers andGitlab::Auth::Oidc::User. The CE stub only changes name. - Like SAML, it calls
auth_user.save, which for OIDC is exactly whatfind_and_update!already did, so there is no extra group or seat sync. - An OIDC user who no longer meets
required_groupsmakessaveraiseSignupDisabledError. 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_groupsstill passedadmin_mode_flow, because the SAML-only check returnedtrue. This MR refuses Admin Mode for them. savealso persists the recomputedauditorandexternalflags. OIDCexternal_groupstakes precedence overadmin_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_groupssetting, 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
- Active SSO session bypasses the six-hour Admin ... (#630537) • Michael Eddington • 19.7
- !264737 (merged)
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
- 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. - Configure an
openid_connectprovider pointing at it, withclient_options: { gitlab: { admin_groups: ["Admins"] } }, and make sure theoidc_client_groups_claimlicensed feature is available. - Sign in through OIDC with the claim
{"groups": ["Admins"]}and enter Admin Mode. - Leave Admin Mode, then re-enter it through OIDC with the claim
{"groups": ["Developers"]}. - Confirm Admin Mode is refused and that
User.find_by(username: '<user>').admin?returnsfalsein 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.