Skip to content

fix: bypass domain enforcement for OM-internally-issued tokens (#29433) [1.13 backport] - #29553

Closed
Vishnuujain wants to merge 1 commit into
1.13from
cherry-pick/29433-domain-bypass-1.13
Closed

Vishnuujain wants to merge 1 commit into
1.13from
cherry-pick/29433-domain-bypass-1.13

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Cherry-pick of a0c306b (#29433) onto 1.13.

Resolved merge conflicts: dropped validateRedirectUri redirect helpers and session/cached-token tests (from #26314 Session Management, not in 1.13); added JWTTokenGenerator imports 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 @domain suffix, causing the domain extraction logic to produce an empty string and fail enforcement. The fix gates validateDomainEnforcement behind isInternallyIssuedToken, which checks that both the token's key ID and iss claim match OM's configured signing identity — the same trust guarantee that already existed for bot tokens.

  • SecurityUtil.isOpenMetadataIssuedToken — new static helper that returns true only when both the token's key ID and issuer claim match OM's own signing key and issuer; returns false safely when either value is unconfigured (null/empty), preserving domain enforcement on deployments where OM signing is not set up.
  • JwtFilter — refactors validateJwtAndGetClaims into decodeAndVerify + extractClaims, extracts tokenKeyId upfront from the verified JWT, and adds an isInternallyIssuedToken guard around the domain-enforcement call; adds a backward-compatible public 4-arg overload of checkValidationsForToken that 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 @Getter to issuer and kid fields; three new integration tests in JwtFilterTest cover 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

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java Refactors validateJwtAndGetClaims into decodeAndVerify + extractClaims, extracts key ID upfront, and gates domain enforcement on isInternallyIssuedToken. Core logic is sound; the public 4-arg overload re-decodes the token string without signature verification (safe today, implicit contract for future callers).
openmetadata-service/src/main/java/org/openmetadata/service/security/SecurityUtil.java Adds isOpenMetadataIssuedToken static helper with safe-fail null guards (returns false when issuer or kid is unconfigured). Logic is correct: requires both key ID match and issuer claim match, safe against spoofed key IDs since signature is verified before this point.
openmetadata-service/src/main/java/org/openmetadata/service/security/jwt/JWTTokenGenerator.java Minimal change: adds @Getter to issuer and kid fields to expose them for the new bypass check. No logic changes.
openmetadata-service/src/test/java/org/openmetadata/service/security/JwtFilterTest.java Adds three new tests covering: OM-issued token bypass, enforcement when server has no signing identity (null issuer/kid), and spoofed key ID without matching signature. Tests correctly mock JWTTokenGenerator singleton via MockedStatic.
openmetadata-service/src/test/java/org/openmetadata/service/security/SecurityUtilTest.java Adds unit tests for isOpenMetadataIssuedToken covering all combinations of matching/mismatching issuer and key ID, including null/empty server identity. Comprehensive coverage.

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
Loading
%%{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 AuthenticationException
Loading

Reviews (1): Last reviewed commit: "fix: bypass domain enforcement for OM-in..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

* 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
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 skip-pr-checks label.

@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Jun 28, 2026
Comment on lines 214 to +223
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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

@gitar-bot

gitar-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Bypasses domain enforcement for internally-issued tokens by cherry-picking the upstream fix into the 1.13 branch. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@github-actions

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format and py_format_check in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (11 flaky)

✅ 2890 passed · ❌ 0 failed · 🟡 11 flaky · ⏭️ 24 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 2 733 0 2 7
🟡 Shard 4 753 0 4 9
🟡 Shard 5 692 0 1 0
🟡 Shard 6 712 0 4 8
🟡 11 flaky test(s) (passed on retry)
  • Features/BulkEditEntity.spec.ts › Glossary (shard 2, 1 retry)
  • Features/DataQuality/TestCaseImportExportBasic.spec.ts › should navigate to bulk edit page from Logical Test Suite page (shard 2, 1 retry)
  • Pages/CustomProperties.spec.ts › Entity Reference (shard 4, 1 retry)
  • Pages/CustomProperties.spec.ts › Integer (shard 4, 1 retry)
  • Pages/DataContracts.spec.ts › Contract Status badge should be visible on condition if Contract Tab is present/hidden by Persona (shard 4, 1 retry)
  • Pages/Domains.spec.ts › Rename domain with data products attached at domain and subdomain levels (shard 4, 1 retry)
  • Pages/EntityDataConsumer.spec.ts › Tier Add, Update and Remove (shard 5, 1 retry)
  • Features/AutoPilot.spec.ts › Create Service and check the AutoPilot status (shard 6, 2 retries)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/ODCSImportExport.spec.ts › Multi-object ODCS contract - object selector shows all schema objects (shard 6, 1 retry)
  • Pages/Users.spec.ts › Permissions for table details page for Data Consumer (shard 6, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@Vishnuujain
Vishnuujain deleted the cherry-pick/29433-domain-bypass-1.13 branch June 29, 2026 04:04

This branch had an error being deployed

1 failed deployment
test — 946e756b Deployed Jun 28, 2026 by Vishnuujain via playwright-ci-postgresql (3, 6) #53491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant