Repository navigation
Fixes #29142: mint IdP-shaped principal claims in JWTTokenGenerator - #33725
Conversation
OM-issued tokens (PATs, bot and session tokens) carried preferred_username as the bare username, while identity providers put the login/UPN email there. Run through the deployment's jwtPrincipalClaims / jwtPrincipalClaimsMapping, our own tokens resolved to an empty domain under principal-domain enforcement and to a synthesized name@principalDomain email that contradicted the user's real one; a mapping onto a provider-specific claim (upn, mail, ...) rejected them outright. JWTTokenGenerator now mints identity claims shaped the way the configured resolution reads them: preferred_username carries the email, the mapped username/email claims are minted, and the first configured order claim is minted when we would not otherwise emit it. init() takes the whole AuthenticationConfiguration so the claim configuration follows runtime security-config reloads. Co-Authored-By: Claude Opus 5 <[email protected]>
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
✅ Playwright Results — workflow succeededValidated commit ✅ 4538 passed · ❌ 0 failed · 🟡 7 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 6h 48m 2s ⏱️ Max setup 4m 34s · max shard execution 22m 37s · max shard-job elapsed before upload 26m 36s · reporting 20s 🌐 224.86 requests/attempt · 2.23 app boots/UI scenario · 37.95% common-shard skew Optimization targets still in progress:
🟡 7 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
… or username Review follow-up on #33725: with putIfAbsent, an order such as [sub, email] left sub as the bare name, so the first-match resolver synthesized name@principalDomain and domain enforcement saw an empty domain - the original bug for that configuration. A deployment that resolves principals from sub first has an identity provider whose sub is the email-shaped login, so our token mirrors that too. Co-Authored-By: Claude Opus 5 <[email protected]>
openmetadata-collate's SupportAwareAuthenticatorTest still initialises the generator with init(TokenValidationAlgorithm, JWTTokenConfiguration). The maven-collate-ci check builds Collate main against this PR, so without the old signature it is red here and Collate main stops compiling the moment this merges. The overload delegates to the new init with a configuration that holds only the algorithm and warns that no principal-claim configuration was supplied. Remove once the paired Collate test migration is merged. Co-Authored-By: Claude Opus 5 <[email protected]>
Code Review ✅ Approved🔴 High risk · JWT claim generation changes authentication identity resolution across issued tokens Fixes JWT principal claims minting to mirror the configured identity-provider shape, ensuring OpenMetadata-issued tokens (PATs, bot tokens, session tokens) resolve consistently with IdP tokens for the same user. OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
✅ SSO Login Nightly — PASSED View workflow run · Commit Totals: 28 passed · 0 failed · 0 flaky · 0 skipped · duration 3m 15s |
|
🤖 Backport to |
|
🤖 Backport to |
|
🤖 Backport to |
|
🤖 Backport to |
Describe your changes:
Fixes #29142
OpenMetadata-issued tokens (PATs, bot tokens, session/
OM_USERtokens) carriedpreferred_usernameas the bare username, while identity providers put the login / UPN email there (Okta login, Azure UPN). Every token is then resolved through the deployment'sjwtPrincipalClaims/jwtPrincipalClaimsMapping, so our own tokens resolved differently from the IdP's token for the same user:getFirstMatchJwtClaim-based extraction found no@→ empty domain → rejected (the ticket's scenario; fix: bypass domain enforcement for OM-internally-issued tokens #29433 papered over this with an OM-issued-token bypass);preferred_username— the UI's default for Azure is['preferred_username', 'email', 'upn', 'sub']— synthesizedname@principalDomain, contradicting the user's real email and making/users/loggedInUserfail with "Account already exists" whenprincipalDomain≠ the user's email domain;email:upn,email:mail, …): the claim is absent from our tokens altogether →AuthenticationException, every PAT rejected.JWTTokenGeneratornow mints identity claims shaped the way the configured resolution reads them, so a token we issue resolves to exactly the(name, email)the IdP's token yields for that user:sub,usernameemailnull)preferred_usernameusername:<claim>email:<claim>jwtPrincipalClaims(upn,unique_name, … — andsub/usernamewhen they come first)JWTTokenGenerator.init()now takes the wholeAuthenticationConfiguration(was: just theTokenValidationAlgorithm) so the generator sees the principal-claim config — and stays in sync on runtime SSO reload, sincereinitializeAuthSystemalready re-callsinit. All four production callers and four test callers are updated. Downstream callers ofinit()need the same one-line change.JwtFilter: comment-only. The #29433 enforcement bypass for OM-issued tokens is kept — unlimited-expiry bot tokens minted before this change still carry a barepreferred_username; it can be dropped once those are rotated.Type of change:
High-level design:
Approach. Fix at the source: make our minted claims consistent with what the IdP emits, driven by the same
jwtPrincipalClaims/jwtPrincipalClaimsMappingthe filter resolves with.identityClaims()builds the fixed set (sub,username,email,preferred_username);putConfiguredPrincipalClaims()adds whatever the configuration reads that we would not otherwise emit. Identity claims are applied to the builder first, so the fixed claims (roles,isBot,tokenType,iss, …) always win on a name collision.Alternatives rejected.
SecurityUtil/JwtFilterresolution (read our own claims when kid+issuer prove the token is ours). Works, but it is a second identity-resolution path and a hack around the real mismatch; also has to be replicated inSocketAddressFilter.preferred_username = email. Fixes the order-based cases in one line but not mappings onto provider-specific claims.Backward compatibility / rollout. Forward-only: existing tokens keep their old shape and keep working under the default order as today (the enforcement bypass covers them). Under the default order
sub/usernameare unchanged, so nothing keyed on the subject moves. An order that readssuborusernamefirst gets the email there too (review follow-up): a deployment resolving principals fromsubfirst has an IdP whosesubis the email-shaped login, so mirroring it is the consistent choice — and nothing inopenmetadata-service/openmetadata-mcpreadssub/usernamefrom our tokens directly (InternalActionTokenSignermints and reads its own tokens).Downstream.
maven-collate-cibuilds Collatemainagainst this PR's sha, and Collate'sSupportAwareAuthenticatorTeststill calledinit(TokenValidationAlgorithm, JWTTokenConfiguration). The old signature is kept as a@Deprecated(forRemoval = true)shim that delegates with anAuthenticationConfigurationholding only the algorithm (and warns that no principal-claim configuration was supplied), so this check is green and Collatemainkeeps compiling when this merges. Paired Collate PR moving that test to the new signature: open-metadata/openmetadata-collate#6771 (draft; merge after this). The shim can be removed once it lands.Tests:
Use cases covered
mohit/[email protected]) resolves to the right user under the default claim order.[preferred_username, email, upn, sub](the UI default): our token resolves to the real email and passes principal-domain enforcement on the real domain.username:upn, email:mail): our token carries them and resolves.unique_name): minted, so first-match lands on an email.usernameandemailmapped onto the same claim: the email wins.sub([sub, email]):subcarries the email,usernamestays bare, resolution and enforcement pass.Unit tests
JWTTokenGeneratorTest(8 new tests, incl. one for the deprecated shim — each mints a real token and resolves it through the realSecurityUtil.findUserNameFromClaims/findEmailFromClaims/validateDomainEnforcementwith the same configuration; no mocks),InternalActionTokenSignerTest,SocketAddressFilterTest,SocketAddressFilterSpoofRevalidationBypassTest(newinit()signature).mintedIdentityClaimsMirrorProviderShape→expected: <[email protected]> but was: <mohit>;…UnderPreferredUsernameOrder→expected: <[email protected]> but was: <[email protected]>;mintedTokenCarriesMappedProviderClaims→AuthenticationException: 'username' claim is not present;…FirstConfiguredClaimWhenNotMappedfails on the synthesized email.mvn -P static-code-analysis test jacoco:report, security suite — 257 tests, 0 failures): changed methodsidentityClaims9/9 lines,putConfiguredPrincipalClaims10/10,init24/26 (the two misses are the pre-existing key-loadingcatch).JWTTokenGenerator.javaoverall 68.3 % line — the remainder is pre-existing untested code (generateImpersonationToken— no callers —,getJWKSResponse,getTokenExpiryFromJWT, RS-384/512 and EC branches, expiry cases), left out of scope.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
No local stack was run for this PR; verification is the round-trip unit tests above (real signing, real resolution code). To reproduce the ticket by hand:
jwtPrincipalClaims: [preferred_username, email, sub],principalDomain: open-metadata.org,enforcePrincipalDomain: true; create usermohitwith email[email protected].preferred_usernameshould be[email protected](wasmohit).GET /api/v1/users/loggedInUserwith the PAT → 200 and the user's real email (was 400 "Account already exists", or 401 with enforcement before fix: bypass domain enforcement for OM-internally-issued tokens #29433).UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.Bug fix
🤖 Generated with Claude Code
The PR appears safe to merge; no outstanding correctness, security, or repository-rule issue was identified.
Summary
This PR aligns identity claims in OpenMetadata-issued JWTs with the deployment’s configured principal-claim resolution.
JWTTokenGenerator, including during runtime reloads.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[AuthenticationConfiguration] --> B[JWTTokenGenerator.init] B --> C[Principal claim order and mapping] D[User name and email] --> E[identityClaims] C --> E E --> F[Signed OpenMetadata JWT] F --> G[SecurityUtil claim resolution] G --> H[Resolved user name and email] G --> I[Principal-domain validation]Reviews (4) · Last reviewed commit: "Keep a deprecated algorithm-only init ov..."