Repository navigation
Fixes #32000: Mint IdP-shaped principal claims in JWTTokenGenerator [2.0] - #34968
Conversation
…2.0] Backport of #33725 (cherry-picked from 54f4e80) to the 2.0 line. Since #26314 the confidential OIDC callback hands the browser an OpenMetadata-minted session JWT, and JwtFilter resolves the user from it with the IdP-oriented jwtPrincipalClaimsMapping. The minted token never carried a custom mapped claim such as username:suffixed_name, so every request failed with 401 "Invalid JWT token, 'username' claim is not present". JWTTokenGenerator.init now takes the AuthenticationConfiguration and minted tokens carry the mapped username/email claims (or the first configured order claim). The algorithm-only init stays as a deprecated overload for downstream callers. Conflicts: - JWTTokenGenerator: main's internal action-token helpers are not on 2.0; kept 2.0's code and took only the new init Javadoc. - JwtFilter: took main's reworded comment on the OM-issued-token domain exemption, kept 2.0's enforcePrincipalDomain condition (main's allowedEmailDomains branch is not on 2.0). - JWTTokenGeneratorTest: merged imports with the regression test below. - InternalActionTokenSignerTest and SocketAddressFilterSpoofRevalidationBypassTest do not exist on 2.0; dropped their hunks. Regression test (JWTTokenGeneratorTest): oidcSessionTokenResolvesToItsUserThroughCustomClaimMapping mints a session token the way the OIDC callback does under jwtPrincipalClaims [suffixed_name, email, preferred_username, sub] and mapping [username:suffixed_name, email:email], then resolves it the way JwtFilter does. On unpatched 2.0 it fails with the 401 AuthenticationException above. (cherry picked from commit 54f4e80)
❌ 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 Map<String, String> identityClaims(String userName, String email) { | ||
| String principal = nullOrEmpty(email) ? userName : email; | ||
| Map<String, String> claims = new LinkedHashMap<>(); | ||
| claims.put(SUBJECT_CLAIM, userName); | ||
| claims.put(USERNAME, userName); | ||
| if (!nullOrEmpty(email)) { | ||
| claims.put(EMAIL_CLAIM, email); | ||
| } | ||
| claims.put(PREFERRED_USERNAME, principal); | ||
| putConfiguredPrincipalClaims(claims, userName, principal); | ||
| return claims; | ||
| } | ||
|
|
||
| /** | ||
| * A deployment may resolve principals from claims we do not otherwise mint ({@code upn}, {@code |
There was a problem hiding this comment.
⚠️ Bug: Email in preferred_username/first claim can resolve token to wrong user
identityClaims now puts the email in preferred_username. With no mapping configured, putConfiguredPrincipalClaims also writes the email into the first configured order claim, even when that claim is sub or username. SecurityUtil.findUserNameFromClaims resolves the user from the first matching order claim and keeps only the part before @. So when a deployment's order reads preferred_username or sub first, any token minted after this change resolves to the email's local part, not to user.getName(). Before this change those claims held the bare name and resolved correctly.
This breaks every user or bot whose name differs from its email local part. Example: a bot my-bot with email [email protected], or an admin-created user john with email [email protected]. After login, refresh, or token regeneration (including the regenerate-bot-tokens ops command), their new token resolves to svc or john.doe. The result is a 401 or user-not-found, or the request runs as a different existing user with that name. Bot tokens are especially exposed: findUserNameFromClaims skips the mapping for isBot tokens and always uses the order.
The new tests pass only because every fixture uses an email whose local part equals the username ([email protected]). Suggested fix: only write the email into these claims when its local part (lowercased) equals userName, and otherwise keep the bare name. Also add a test where the name and the email local part differ.
Use the email as the principal only when it resolves back to the same username:
private Map<String, String> identityClaims(String userName, String email) {
final boolean isEmailConsistent =
!nullOrEmpty(email)
&& email.split("@")[0].equalsIgnoreCase(userName);
final String principal = isEmailConsistent ? email : userName;
...
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
Describe your changes:
Fixes #32000
Backports #33725 (
54f4e80ea3) to2.0. On 2.0.x, a confidential OIDC login whosejwtPrincipalClaimsMappingpoints at a custom identity-provider claim (for exampleusername:suffixed_name) fails every request with401 Invalid JWT token, 'username' claim is not present. Since 2.0 (#26314) the callback hands the browser an OpenMetadata-minted session JWT, andJwtFilterre-resolves the user from it with that mapping, but the minted token never carried the mapped claim.With this backport:
JWTTokenGenerator.init(AuthenticationConfiguration, JWTTokenConfiguration)records the principal-claim configuration.initoverload stays,@Deprecated(forRemoval = true), for downstream callers.On
main, #34967 goes further: confidential OIDC browsers get the identity provider's own ID token. This PR is the minimal fix for 2.0.x users.Release branch:
2.0.Type of change:
High-level design:
N/A — cherry-pick of #33725. Conflicts resolved:
JWTTokenGenerator:main's internal action-token helpers are not on 2.0 and are left out. The change itself matchesmain's diff.JwtFilter: only the comment update. 2.0 keeps its own domain-enforcement condition;main's email-first branch is not on 2.0.InternalActionTokenSignerTestandSocketAddressFilterSpoofRevalidationBypassTest, which do not exist on 2.0.All callers of
init(startup, security-configuration reload,OpenMetadataOperations) pass theAuthenticationConfiguration.Tests:
Use cases covered
jwtPrincipalClaimsMapping. This is the exact 2.0.0: OIDC callback returns OM's self-issued JWT instead of IdP's raw id_token, breaking custom jwtPrincipalClaimsMapping #32000 configuration: claims[suffixed_name, email, preferred_username, sub], mapping[username:suffixed_name, email:email].Unit tests
JWTTokenGeneratorTest#oidcSessionTokenResolvesToItsUserThroughCustomClaimMapping.AuthenticationException: Invalid JWT token, 'username' claim is not present.JWTTokenGeneratorTest14JwtFilterTest33SocketAddressFilterTest8AuthenticationCodeFlowHandlerTest41SecurityUtilTest53UserUtilTest29TestLoginServiceTest11MultiUrlJwkProviderTest6openmetadata-mcpcompiles.spotless:checkpasses.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
UI screen recording / screenshots:
Not applicable.
Checklist:
I have read the CONTRIBUTING document.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.I have commented on my code, particularly in hard-to-understand areas.
For JSON Schema changes: I updated the migration scripts or explained why it is not needed. No schema changes.
For UI changes: I attached a screen recording and/or screenshots above. No UI changes.
I have added tests (unit / integration / Playwright as applicable) and listed them above.
I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.