Skip to content

feat: add support for mapping user admin status from OIDC claims - #1033

Open
UiP9AV6Y wants to merge 4 commits into
gotify:masterfrom
UiP9AV6Y:feature/oidc-claim-mapping
Open

feat: add support for mapping user admin status from OIDC claims#1033
UiP9AV6Y wants to merge 4 commits into
gotify:masterfrom
UiP9AV6Y:feature/oidc-claim-mapping

Conversation

@UiP9AV6Y

Copy link
Copy Markdown

an optional new configuration setting allows operators to define a JMESPath expression to calculate the admin status of a user based on their OIDC claims. this feature can also be used to deny users access alltogether, by mapping their claims to a special role value.

closes #957

@UiP9AV6Y
UiP9AV6Y requested a review from a team as a code owner August 20, 2026 19:40
Comment thread api/oidc.go Outdated
@UiP9AV6Y
UiP9AV6Y force-pushed the feature/oidc-claim-mapping branch 2 times, most recently from 1cda078 to 7c460e4 Compare August 22, 2026 12:59
jmattheis and others added 3 commits August 23, 2026 11:36
Some IdPs don't provide or only provide the claims in the ID token /
userinfo. Most clients will check both claims.
Co-Authored-By: Jannis Mattheis <contact@jmattheis.de>
Comment thread api/rbac.go Outdated
switch roles := subject.(type) {
case string:
return r.resolveSlice([]string{roles}), nil
case []string:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work. the groups are provided here as []any. (I've already adjusted this).

Comment thread api/rbac.go Outdated

// RBACResolver allows for arbitrary input to be mapped to roles for
// use in a permission system.
type RBACResolver interface {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is pretty overengineered. All this matching and conversion should be done in a single function. This makes this IMO easier to understand. (I've already adjusted this)

@jmattheis
jmattheis force-pushed the feature/oidc-claim-mapping branch from 7c460e4 to 20629d3 Compare August 23, 2026 09:42
@jmattheis

Copy link
Copy Markdown
Member

@eternal-flame-AD Could you take a look at these changes? I've made some larger adjustments and would like a second pair of eyes (:


I've tested this with authentik and Authelia with different combinations of settings and groups.

@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.41096% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.75%. Comparing base (54deea6) to head (20629d3).

Files with missing lines Patch % Lines
api/oidc.go 90.00% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1033      +/-   ##
==========================================
+ Coverage   75.49%   75.75%   +0.26%     
==========================================
  Files          66       66              
  Lines        3559     3622      +63     
==========================================
+ Hits         2687     2744      +57     
- Misses        662      667       +5     
- Partials      210      211       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@eternal-flame-AD

Copy link
Copy Markdown
Member

sure, will do tonight :)

Comment thread api/oidc.go Outdated
}

if user != nil {
if admin != nil && user.Admin != *admin {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status of being not an admin is simply the lack of the admin role in the group claim, there isn't really a third "empty" state here IMO. Every case where there is not an admin role present is just not an admin.

Why not just make admin a boolean instead of tristate , and update the admin flag if GOTIFY_OIDC_GROUPS_ADMIN is defined. Ideally also check this configuration and prohibit manual admin changes in UpdateUserById()

The main risk I am worried about is accidentally omitting a code path where the admin status isn't stripped when it should be. I don't think there is really a use case where you might have this situation where you have some users have the GroupClaim but other don't.

@jmattheis jmattheis Aug 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just make admin a boolean instead of tristate , and update the admin flag if GOTIFY_OIDC_GROUPS_ADMIN is defined.

Okay

Ideally also check this configuration and prohibit manual admin changes in UpdateUserById()

I think I skip this for now, as we still allow logging in with user/pass for oidc accounts. I create a new ticket for this, as this is likely not that straightforward. => #1037

Comment thread gotify-server.env.example
# GOTIFY_OIDC_USERNAMECLAIM=preferred_username

# OIDC ID-token claim containing the group memberships as a list of strings.
# The claim must be part of the requested scopes (GOTIFY_OIDC_SCOPES). When

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check this or maybe just silently add it if it's not present?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we can. Afaik, this isn't standardized (https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.4) , so the claim-key could be something like "http://example.info/claims/groups" and the scope maybe too. Most IdPs use groups, but I rather not force this and instead document this per IdP in our OIDC documentation.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

OIDC: Map group claims to admin user flag

3 participants