Skip to content

feat(oidc): opt-in P_OIDC_SYNC_ROLES to make provider groups authoritative - #1867

Open
stalingino wants to merge 2 commits into
parseablehq:mainfrom
stalingino:feat/oidc-sync-roles
Open

stalingino wants to merge 2 commits into
parseablehq:mainfrom
stalingino:feat/oidc-sync-roles

Conversation

@stalingino

@stalingino stalingino commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #1864.

Description

For a returning OIDC user, roles from the groups claim are added to the roles they already have and nothing is removed. That preserves roles assigned inside Parseable (#1356), but it also means removing a user from a group in the identity provider never revokes the matching Parseable role.

This adds an opt-in setting, P_OIDC_SYNC_ROLES / --oidc-sync-roles (default false). When enabled, at every login the user's roles are set to exactly the roles their groups name, falling back to the default role as today. With the default, behaviour is unchanged.

Under sync, the native-account fallback (a native user with the same email lends its roles) is skipped, so removing a user's last group can't hand the role back; the default role still applies.

The merge rule is a small merge_oidc_roles function, and resolve_roles now receives the defined roles, users and default role instead of reading StorageMetadata/DEFAULT_ROLE, so it reads no global state and is unit-tested directly. update_user_if_changed already persists a shrunk role set.

Note: an existing session keeps its roles until it expires; the sync applies at the next login.

Testing

  • New unit tests (merge_oidc_roles_tests, 8 passed): for merge_oidc_roles, a new user gets the group roles, existing roles are kept by default, and with sync a removed group's role is revoked. Through resolve_roles: with sync, the last group removed does not restore roles from a same-email native account; without sync, that fallback still works; groups replace existing roles; the default role applies when no group matches.
  • End to end with Dex on a v3.2.7 release build carrying this patch, P_OIDC_SYNC_ROLES=true: first login → roles [authors] (the user's group); an admin adds extra-by-hand via PATCH /user/{id}/role/add → [authors, extra-by-hand]; next login → [authors]; the session can query.
  • cargo clippy --lib -- -D warnings and cargo fmt --check are clean.

This PR has:

RetriggerView in GreptileConfidence Score: 5/5

The reviewed changes appear safe to merge; no blocking issues remain.

Summary

Adds opt-in OIDC role sync while keeping the existing behavior by default. The follow-up fixes the previously reported native-account fallback and adds direct tests for role selection.

  • OIDC users can sync their roles from provider groups at login.

Reviews (7) · Last reviewed commit: "fix(oidc): keep the native-account fallb..." · Reviewed by Greptile

…ative

For a returning OIDC user, roles from the groups claim are added to the roles
the user already has and nothing is removed. That keeps roles assigned inside
Parseable (parseablehq#1356), but it also means removing a user from a group in the
identity provider never revokes the matching Parseable role.

P_OIDC_SYNC_ROLES=true (--oidc-sync-roles) makes the provider the source of
truth: at every login the user's roles become exactly the roles their groups
name, falling back to the default role as before. The default is off, so
existing behaviour is unchanged. The merge rule is extracted into
merge_oidc_roles with unit tests for both modes.
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Comment thread src/handlers/http/oidc.rs Resolved
With P_OIDC_SYNC_ROLES, removing a user's last provider group left an empty
role set, and the native-account fallback (a native user with the same email)
then handed the removed role back. Under sync that fallback is now skipped;
the default role still applies.

resolve_roles now receives the defined roles, users and default role instead
of reading StorageMetadata and DEFAULT_ROLE, so it reads no global state and
is unit-tested directly, including the native-account case.
@stalingino

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removing a user from an identity-provider group never revokes the OIDC role

1 participant