Repository navigation
fix: bypass domain enforcement for OM-internally-issued tokens - #29433
Conversation
❌ 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 |
🟡 Playwright Results — all passed (20 flaky)✅ 4456 passed · ❌ 0 failed · 🟡 20 flaky · ⏭️ 38 skipped
🟡 20 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 |
|
|
|
Failed to cherry-pick changes to the 1.13 branch. |
|
Failed to cherry-pick changes to the 1.12.13 branch. |
Code Review ✅ Approved 1 resolved / 1 findingsBypasses domain enforcement for internally issued tokens by gating the filter with a key-ID and issuer validation check. The change also optimizes the hot path by removing redundant JWT decodes and includes comprehensive test coverage for security scenarios. ✅ 1 resolved✅ Performance: Token re-decoded on every request even when enforcement off
OptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
* fix: bypass domain enforcement for OM-internally-issued tokens * review: fix comment accuracy and short-circuit bypass when enforcement disabled * refactor: eliminate redundant JWT decode in JwtFilter hot path



Root Cause
When
enforcePrincipalDomain = true,validateDomainEnforcementcallsgetFirstMatchJwtClaimto extract the domain from the token. OpenMetadata-issued tokens (PATs, session tokens, bot tokens) setpreferred_username = userName(bare, no@domainsuffix). Ifpreferred_usernameappears beforeemailinjwtPrincipalClaimsorder, the domain resolves to"", which fails enforcement — even though the user was already validated when their account was created in OM.Issue: #29488
Fix
Gate
validateDomainEnforcementwith anisInternallyIssuedTokencheck inJwtFilter.checkValidationsForToken. A token is considered internally issued when:kid(key id header) matchesJWTTokenGenerator's signing key idissclaim matchesJWTTokenGenerator's configured issuerThe
kidis the trust anchor: signature verification against the JWK provider already ran before this check, so a matchingkidproves OM's private key produced the signature — an external IdP cannot forge it. Theisscheck is defense-in-depth against a key id collision in a multi-source JWK provider (OM JWKS + external IdP JWKS).Falls back to enforcing when
JWTTokenGeneratoris uninitialized (nullissuer/kid), so deployments without a configured signing key are unaffected.Tradeoff / Known Behavior
Greptile Summary
This PR fixes a bug where OM-internally-issued tokens (PATs, session tokens, bot tokens) fail domain enforcement when
preferred_usernameappears beforeemailin the JWT claims order, causinggetFirstMatchJwtClaimto resolve an empty domain. The fix bypassesvalidateDomainEnforcementfor tokens verifiably minted by OpenMetadata, identified by matching bothkidandissagainstJWTTokenGenerator's configured values.JwtFilteris refactored to splitvalidateJwtAndGetClaimsintodecodeAndVerifyandextractClaims, eliminating a redundant decode in the main request path and threadingtokenKeyIdthrough tocheckValidationsForToken.SecurityUtil.isOpenMetadataIssuedTokenis added as the detection predicate, returningfalse(enforce) whenJWTTokenGeneratoris uninitialized.JwtFilterTestcover the bypass, fail-closed fallback, and spoofed-key rejection.Confidence Score: 5/5
Safe to merge — the bypass is correctly gated behind signature verification, making it impossible for an external IdP to forge an OM-issued identity.
The trust chain is solid: decodeAndVerify runs the full JWK signature check before isInternallyIssuedToken is consulted, so a matching kid/iss pair without a valid OM signature is rejected at the earlier step. The fallback when JWTTokenGenerator is uninitialized correctly defaults to enforcing, and three integration tests plus dedicated unit tests cover all the critical paths.
No files require special attention.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Client participant JwtFilter participant JWTTokenGenerator participant SecurityUtil participant validateDomainEnforcement Client->>JwtFilter: HTTP request with Bearer token JwtFilter->>JwtFilter: decodeAndVerify(token) JwtFilter->>JwtFilter: extractClaims + tokenKeyId JwtFilter->>JwtFilter: validateTokenIsNotUsedAfterLogout alt "enforcePrincipalDomain == true" JwtFilter->>JWTTokenGenerator: getInstance().getIssuer() / getKid() JWTTokenGenerator-->>JwtFilter: omIssuer, omKid JwtFilter->>SecurityUtil: isOpenMetadataIssuedToken(claims, tokenKeyId, omIssuer, omKid) alt kid AND iss match OM config SecurityUtil-->>JwtFilter: true - skip domain enforcement else external token OR uninitialized generator SecurityUtil-->>JwtFilter: false - enforce domain JwtFilter->>validateDomainEnforcement: validateDomainEnforcement(...) validateDomainEnforcement-->>JwtFilter: pass or throw AuthenticationException end end JwtFilter->>JwtFilter: validateBotToken / validatePersonalAccessToken / validateSessionBoundToken JwtFilter-->>Client: SecurityContext set%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Client participant JwtFilter participant JWTTokenGenerator participant SecurityUtil participant validateDomainEnforcement Client->>JwtFilter: HTTP request with Bearer token JwtFilter->>JwtFilter: decodeAndVerify(token) JwtFilter->>JwtFilter: extractClaims + tokenKeyId JwtFilter->>JwtFilter: validateTokenIsNotUsedAfterLogout alt "enforcePrincipalDomain == true" JwtFilter->>JWTTokenGenerator: getInstance().getIssuer() / getKid() JWTTokenGenerator-->>JwtFilter: omIssuer, omKid JwtFilter->>SecurityUtil: isOpenMetadataIssuedToken(claims, tokenKeyId, omIssuer, omKid) alt kid AND iss match OM config SecurityUtil-->>JwtFilter: true - skip domain enforcement else external token OR uninitialized generator SecurityUtil-->>JwtFilter: false - enforce domain JwtFilter->>validateDomainEnforcement: validateDomainEnforcement(...) validateDomainEnforcement-->>JwtFilter: pass or throw AuthenticationException end end JwtFilter->>JwtFilter: validateBotToken / validatePersonalAccessToken / validateSessionBoundToken JwtFilter-->>Client: SecurityContext setReviews (7): Last reviewed commit: "Merge branch 'main' into fix/mcp-domain-..." | Re-trigger Greptile