Repository navigation
Fixes #32960: Sync SSO roles from the provider's id_token at the OIDC callback - #32961
Conversation
… callback Since #26314 the OIDC confidential-client callback hands the browser an OpenMetadata-issued session JWT instead of the provider's raw id_token. That token carries the roles already stored in OpenMetadata, so the useRolesFromProvider sync in JwtFilter/UserResource ends up comparing the database against itself: new SSO users are never granted the roles in their Keycloak token, and users whose roles were revoked in Keycloak keep theirs. Apply the provider's roles at the callback, which is the last point where the id_token claims are in hand, before the session token is minted. Making revocation work meant dropping the non-empty guard in reSyncUserRolesFromToken. That guard was load-bearing: without it an empty role set from a deployment that never configured a roles claim would wipe every user's roles. getUserRolesFromClaims now returns null for "the provider said nothing about roles" and a possibly-empty set for "these are the roles", and the sync treats only the latter as authoritative. Also fixes the same claim read in the two other places it is duplicated: a role emitted as a scalar string rather than a one-element array was read as no roles at all, both on the login path and in the SSO test dialog customers use to verify their roles claim. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
| private void syncRolesFromProvider(User user, Map<String, Object> claims) { | ||
| if (!Boolean.TRUE.equals(authorizerConfiguration.getUseRolesFromProvider()) | ||
| || !claims.containsKey(ROLES_CLAIM)) { | ||
| return; | ||
| } | ||
| UserUtil.reSyncUserRolesFromToken( | ||
| null, user, new HashSet<>(getClaimAsList(claims.get(ROLES_CLAIM)))); | ||
| } |
There was a problem hiding this comment.
💡 Edge Case: Present-but-null roles claim collapses to "revoke all roles"
When the id_token carries a roles claim whose value is JSON null, claims.containsKey(ROLES_CLAIM) is true, so getClaimAsList(null) returns an empty list and reSyncUserRolesFromToken treats it as the authoritative empty set — revoking every role. This is the same case the PR's null-vs-empty distinction is meant to protect against ("the provider said nothing"), yet a null-valued claim is indistinguishable from a real empty revocation. Same behavior exists on the JwtFilter path via an auth0 NullClaim. Impact is low (requires a provider/mapper emitting an explicit null), but consider treating a null value as "no info" by checking the value is non-null before syncing.
Treat a null-valued roles claim as "no info" rather than an empty revocation.:
private void syncRolesFromProvider(User user, Map<String, Object> claims) {
if (!Boolean.TRUE.equals(authorizerConfiguration.getUseRolesFromProvider())
|| claims.get(ROLES_CLAIM) == null) {
return;
}
UserUtil.reSyncUserRolesFromToken(
null, user, new HashSet<>(getClaimAsList(claims.get(ROLES_CLAIM))));
}
Was this helpful? React with 👍 / 👎
Describe your changes:
Fixes #32960
Role sync from a Keycloak custom-OIDC token stops working on 2.0.0 with
useRolesFromProvider: trueand a confidential client: new SSO users get none of the roles in their token, and users whose roles were revoked in Keycloak keep their old ones.Root cause.
useRolesFromProviderhas always worked by reading therolesclaim off the bearer token. Through 1.10.6 that bearer was the provider'sid_token—AuthenticationCodeFlowHandler.sendRedirectWithTokenredirected withid_token=credentials.getIdToken().getParsedString(), soJwtFiltersaw Keycloak's roles on every request andUserResource#getCurrentLoggedInUsersynced them.Since #26314 (session management, in 2.0.0, not in 1.10.6) the callback mints an OpenMetadata session JWT from
getRoleListFromUser(user)— the roles already in OM's database. The provider's roles are read at the callback and dropped, and the sync downstream compares OM against itself, so it never detects a change.I applied the provider's roles at the callback, before the session token is minted, since that is the last point where the
id_tokenclaims are in hand.Making revocation work required dropping the non-empty guard in
reSyncUserRolesFromToken. That guard was load-bearing — without it, an empty role set on a deployment that never configured arolesclaim would wipe every user's roles on login. SogetUserRolesFromClaimsnow returnsnullfor "the provider said nothing about roles" (feature off, bot, or claim absent) and a possibly-empty set for "these are the roles", and only the latter is treated as authoritative.getRolesFromAuthorizationTokenreads the raw record component rather thangetUserRoles(), which flattenednullinto an empty set.Two related defects in the same claim read, fixed in the same pass since all three copies route through it:
"roles": "DataSteward") rather than a one-element array was read as no roles —Claim.asList()returnsnullfor a scalar. Now uses the existingSecurityUtil.getClaimAsList.TestLoginService.resolveRoles— the SSO test dialog customers use to verify their roles claim — had the same bug, so it would report "no roles" for exactly the configuration login would grant.Admin remains promotion-only. Demoting on a missing admin role would lock out anyone who is an admin via
adminPrincipalsrather than via the provider; that is called out in the javadoc.Type of change:
High-level design:
N/A — small change (55 lines of production code across 5 files, all on the existing role-sync path).
Tests:
Use cases covered
rolesclaimuseRolesFromProvider: truebut norolesclaim keeps its users' roles untouched (this is the case the removed guard used to protect)useRolesFromProvider: falseignores the claim entirelyrolesclaim is matched case-insensitively, as the callback's claims map already isAdminpromotes the user; a provider omitting it does not demote anadminPrincipalsadminrolesclaim is honoured, on both the login path and in the SSO test dialogUnit tests
Files updated:
openmetadata-service/src/test/java/org/openmetadata/service/security/AuthenticationCodeFlowHandlerTest.java— 7 tests on the callback sync (the regression itself)openmetadata-service/src/test/java/org/openmetadata/service/security/JwtFilterTest.java— 6 tests on the claim → security-context signal, including the null-vs-empty distinctionopenmetadata-service/src/test/java/org/openmetadata/service/util/UserUtilTest.java— 7 tests on the sync semantics matrixopenmetadata-service/src/test/java/org/openmetadata/service/security/auth/TestLoginServiceTest.java— 2 tests on the SSO test dialog's claim readI verified the new tests actually catch the regression rather than just passing: reverting the three production files and re-running produces 14 failures/errors across the three classes, with the rest of the suites still green.
Backend integration tests
openmetadata-integration-tests/today.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
Not performed — reproducing requires a Keycloak confidential-client deployment with a top-level
rolesclaim mapper. The reporting customer's environment is the natural place to confirm; the behaviour is pinned by the unit tests above and by the 1.10.6-vs-2.0.0 diff insendRedirectWithTokenthat identifies the regression.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.Bug fix
AuthenticationCodeFlowHandlerTestfor future reference.Note for reviewers
The
useRolesFromProviderflag reads the literalrolesclaim (JWTTokenGenerator.ROLES_CLAIM); there is nojwtRoleClaimMappingcounterpart to the existingjwtTeamClaimMapping. Keycloak users need a mapper that puts roles at the top level rather than underrealm_access.roles— that was equally true on 1.10.6, so this PR restores parity rather than changing the contract. Adding a configurable role claim name would be a reasonable follow-up.Separately: SAML (
SamlAuthServletHandler) also mints its token from database roles and has never read a roles claim, souseRolesFromProviderdoes not work there either. That is a pre-existing gap rather than a 2.0 regression, so I left it out of this PR.🤖 Generated with Claude Code