Repository navigation
fix: bypass domain enforcement for OM-internally-issued tokens (#29433) [1.13 backport] - #29553
Vishnuujain wants to merge 1 commit into
Conversation
* 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
❌ 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 |
| public void checkValidationsForToken( | ||
| Map<String, Claim> claims, String tokenFromHeader, String userName, String impersonatedBy) { | ||
| String tokenKeyId = null; | ||
| try { | ||
| tokenKeyId = JWT.decode(tokenFromHeader).getKeyId(); | ||
| } catch (JWTDecodeException e) { | ||
| LOG.debug("Unable to read key id from token during OpenMetadata issuer check", e); | ||
| } | ||
| checkValidationsForToken(claims, tokenFromHeader, tokenKeyId, userName, impersonatedBy); | ||
| } |
There was a problem hiding this comment.
Public overload re-decodes JWT without signature verification
The backward-compat public checkValidationsForToken(4-arg) calls JWT.decode(tokenFromHeader).getKeyId() — this is a raw, unverified decode. In all current callers (SocketAddressFilter.validatePrefixedTokenRequest and checkForUsernameAndImpersonationValidation), the claims and token already come from the same signature-verified source, so the behavior is correct today. But the method signature makes no guarantee that tokenFromHeader and claims correspond to the same JWT, and a future caller that passes mismatched arguments would silently get a wrong key-ID match result — meaning the bypass either fires when it shouldn't, or doesn't fire when it should, depending on which token carries the OM key ID. A Javadoc note asserting the contract (claims must be extracted from the same already-verified tokenFromHeader) would prevent this footgun.
Code Review ✅ ApprovedBypasses domain enforcement for internally-issued tokens by cherry-picking the upstream fix into the 1.13 branch. No issues found. OptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|
The Python checkstyle failed. Please run You can install the pre-commit hooks with |
|
🟡 Playwright Results — all passed (11 flaky)✅ 2890 passed · ❌ 0 failed · 🟡 11 flaky · ⏭️ 24 skipped
🟡 11 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 |



Cherry-pick of a0c306b (#29433) onto 1.13.
Resolved merge conflicts: dropped
validateRedirectUriredirect helpers and session/cached-token tests (from #26314 Session Management, not in 1.13); addedJWTTokenGeneratorimports 1.13 lacked. Functional changes identical to original.Verified: spotless clean, compiles, 54/54 tests pass (42 SecurityUtilTest + 12 JwtFilterTest).
Greptile Summary
This backport (cherry-pick of #29433 onto 1.13) fixes a bug where OM-internally-issued tokens (PATs, session tokens, user tokens) were incorrectly rejected by domain enforcement because they embed bare usernames without an
@domainsuffix, causing the domain extraction logic to produce an empty string and fail enforcement. The fix gatesvalidateDomainEnforcementbehindisInternallyIssuedToken, which checks that both the token's key ID andissclaim match OM's configured signing identity — the same trust guarantee that already existed for bot tokens.SecurityUtil.isOpenMetadataIssuedToken— new static helper that returnstrueonly when both the token's key ID and issuer claim match OM's own signing key and issuer; returnsfalsesafely when either value is unconfigured (null/empty), preserving domain enforcement on deployments where OM signing is not set up.JwtFilter— refactorsvalidateJwtAndGetClaimsintodecodeAndVerify+extractClaims, extractstokenKeyIdupfront from the verified JWT, and adds anisInternallyIssuedTokenguard around the domain-enforcement call; adds a backward-compatible public 4-arg overload ofcheckValidationsForTokenthat re-decodes the raw token string to obtain the key ID for callers (e.g.SocketAddressFilter) that don't have the pre-decoded value.JWTTokenGenerator— adds@Gettertoissuerandkidfields; three new integration tests inJwtFilterTestcover the bypass path, enforcement when the server has no signing identity, and rejection of a spoofed key ID with a non-matching signature.Confidence Score: 4/5
Safe to merge; the bypass only activates after cryptographic signature verification, and the safe-fail null guards ensure domain enforcement is preserved when OM's signing identity is unconfigured.
The trust chain is solid — the key ID and issuer used for the bypass check both come from the same already-signature-verified DecodedJWT, so an external token cannot spoof its way past enforcement. The one subtle point is the public 4-arg checkValidationsForToken overload, which re-decodes the raw token string without signature verification to recover the key ID for backward-compatible callers like SocketAddressFilter. All current callers pass the same pre-verified token string, so there is no present defect, but the method carries an implicit contract that is not documented and could trap a future caller.
The public checkValidationsForToken(Map, String, String, String) overload in JwtFilter.java deserves a second look — it re-decodes the raw JWT string without signature verification, relying on callers to ensure tokenFromHeader and claims always correspond to the same pre-verified token.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Client participant JwtFilter participant JWTTokenGenerator participant SecurityUtil participant validateDomainEnforcement Client->>JwtFilter: HTTP request (Authorization: Bearer token) JwtFilter->>JwtFilter: extractToken() JwtFilter->>JwtFilter: decodeAndVerify(token) — decode, check expiry, verify signature JwtFilter->>JwtFilter: extractClaims(decodedJwt) → claims JwtFilter->>JwtFilter: "tokenKeyId = decodedJwt.getKeyId()" JwtFilter->>JwtFilter: checkValidationsForToken(claims, token, tokenKeyId, ...) JwtFilter->>JwtFilter: validateTokenIsNotUsedAfterLogout(token) alt "enforcePrincipalDomain == true" JwtFilter->>JWTTokenGenerator: getInstance().getIssuer() / getKid() JWTTokenGenerator-->>JwtFilter: omIssuer, omKid JwtFilter->>SecurityUtil: isOpenMetadataIssuedToken(claims, tokenKeyId, omIssuer, omKid) SecurityUtil-->>JwtFilter: true (OM-issued) or false (external IdP) alt "isInternallyIssuedToken == false" JwtFilter->>validateDomainEnforcement: validateDomainEnforcement(...) validateDomainEnforcement-->>JwtFilter: OK or AuthenticationException else "isInternallyIssuedToken == true" JwtFilter->>JwtFilter: skip domain enforcement end end JwtFilter->>JwtFilter: validateBotToken / validatePersonalAccessToken JwtFilter-->>Client: set SecurityContext or throw AuthenticationException%%{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 (Authorization: Bearer token) JwtFilter->>JwtFilter: extractToken() JwtFilter->>JwtFilter: decodeAndVerify(token) — decode, check expiry, verify signature JwtFilter->>JwtFilter: extractClaims(decodedJwt) → claims JwtFilter->>JwtFilter: "tokenKeyId = decodedJwt.getKeyId()" JwtFilter->>JwtFilter: checkValidationsForToken(claims, token, tokenKeyId, ...) JwtFilter->>JwtFilter: validateTokenIsNotUsedAfterLogout(token) alt "enforcePrincipalDomain == true" JwtFilter->>JWTTokenGenerator: getInstance().getIssuer() / getKid() JWTTokenGenerator-->>JwtFilter: omIssuer, omKid JwtFilter->>SecurityUtil: isOpenMetadataIssuedToken(claims, tokenKeyId, omIssuer, omKid) SecurityUtil-->>JwtFilter: true (OM-issued) or false (external IdP) alt "isInternallyIssuedToken == false" JwtFilter->>validateDomainEnforcement: validateDomainEnforcement(...) validateDomainEnforcement-->>JwtFilter: OK or AuthenticationException else "isInternallyIssuedToken == true" JwtFilter->>JwtFilter: skip domain enforcement end end JwtFilter->>JwtFilter: validateBotToken / validatePersonalAccessToken JwtFilter-->>Client: set SecurityContext or throw AuthenticationExceptionReviews (1): Last reviewed commit: "fix: bypass domain enforcement for OM-in..." | Re-trigger Greptile