Skip to content

fix: bypass domain enforcement for OM-internally-issued tokens - #29433

Merged
Vishnuujain merged 8 commits into
mainfrom
fix/mcp-domain-enforcement-internal-token-bypass
Jun 26, 2026
Merged

Vishnuujain merged 8 commits into
mainfrom
fix/mcp-domain-enforcement-internal-token-bypass

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause

When enforcePrincipalDomain = true, validateDomainEnforcement calls getFirstMatchJwtClaim to extract the domain from the token. OpenMetadata-issued tokens (PATs, session tokens, bot tokens) set preferred_username = userName (bare, no @domain suffix). If preferred_username appears before email in jwtPrincipalClaims order, 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 validateDomainEnforcement with an isInternallyIssuedToken check in JwtFilter.checkValidationsForToken. A token is considered internally issued when:

  1. Its kid (key id header) matches JWTTokenGenerator's signing key id
  2. Its iss claim matches JWTTokenGenerator's configured issuer

The kid is the trust anchor: signature verification against the JWK provider already ran before this check, so a matching kid proves OM's private key produced the signature — an external IdP cannot forge it. The iss check 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 JWTTokenGenerator is uninitialized (null issuer/kid), so deployments without a configured signing key are unaffected.

Tradeoff / Known Behavior

⚠️ This bypass applies to all OM-issued tokens, including those for users whose email doesn't match principalDomain (e.g., an admin-created account for an out-of-domain user). This is the same behavior bot tokens already have — validateDomainEnforcement has an early return for isBot = true tokens (line 380), so bots have always bypassed domain enforcement. This fix makes all OM-minted tokens consistent with that existing behavior.

Greptile Summary

This PR fixes a bug where OM-internally-issued tokens (PATs, session tokens, bot tokens) fail domain enforcement when preferred_username appears before email in the JWT claims order, causing getFirstMatchJwtClaim to resolve an empty domain. The fix bypasses validateDomainEnforcement for tokens verifiably minted by OpenMetadata, identified by matching both kid and iss against JWTTokenGenerator's configured values.

  • JwtFilter is refactored to split validateJwtAndGetClaims into decodeAndVerify and extractClaims, eliminating a redundant decode in the main request path and threading tokenKeyId through to checkValidationsForToken.
  • SecurityUtil.isOpenMetadataIssuedToken is added as the detection predicate, returning false (enforce) when JWTTokenGenerator is uninitialized.
  • Three new integration tests in JwtFilterTest cover 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

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java Core filter refactored to thread DecodedJWT through the pipeline and gate validateDomainEnforcement behind isInternallyIssuedToken; logic is sound and both paths are covered by tests.
openmetadata-service/src/main/java/org/openmetadata/service/security/SecurityUtil.java New isOpenMetadataIssuedToken predicate correctly requires both kid and iss match and is null-safe; getClaimOrObject on a missing iss claim returns empty string which correctly evaluates to false.
openmetadata-service/src/main/java/org/openmetadata/service/security/jwt/JWTTokenGenerator.java Minimal change adding @Getter to issuer and kid fields without breaking the singleton pattern or init contract.
openmetadata-service/src/test/java/org/openmetadata/service/security/JwtFilterTest.java Three new tests cover: bypass for a genuine OM token, fail-closed when generator is uninitialized, and signature-mismatch rejection for a spoofed kid.
openmetadata-service/src/test/java/org/openmetadata/service/security/SecurityUtilTest.java Unit tests for isOpenMetadataIssuedToken cover all four permutations of key-id and issuer mismatch, plus the null/empty uninitialized-generator cases.

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
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 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
Loading

Reviews (7): Last reviewed commit: "Merge branch 'main' into fix/mcp-domain-..." | Re-trigger Greptile

@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 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (20 flaky)

✅ 4456 passed · ❌ 0 failed · 🟡 20 flaky · ⏭️ 38 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 322 0 3 4
🟡 Shard 2 822 0 7 9
🟡 Shard 3 828 0 1 7
🟡 Shard 4 830 0 1 10
🟡 Shard 5 872 0 2 0
🟡 Shard 6 782 0 6 8
🟡 20 flaky test(s) (passed on retry)
  • Flow/SearchRBAC.spec.ts › User without permission (shard 1, 1 retry)
  • Flow/SearchRBAC.spec.ts › User without permission (shard 1, 1 retry)
  • Flow/SearchRBAC.spec.ts › the browse tree only shows the asset-type categories a user can access (shard 1, 2 retries)
  • Features/BulkEditEntity.spec.ts › Glossary (shard 2, 1 retry)
  • Features/BulkEditOperationBadges.spec.ts › Glossary bulk edit search filters rows and clear restores them (shard 2, 1 retry)
  • Features/BulkImport.spec.ts › Database service (shard 2, 1 retry)
  • Features/BulkImport.spec.ts › Database Schema (shard 2, 1 retry)
  • Features/BulkImportWithDotInName.spec.ts › CSV with quoted FQN loads correctly in import grid (shard 2, 1 retry)
  • Features/ContextCenter.spec.ts › clicking a memory row opens the view-only modal (shard 2, 1 retry)
  • Features/DataQuality/TestCaseImportExportE2eFlow.spec.ts › Admin: Complete export-import-validate flow (shard 2, 2 retries)
  • Features/Tasks/TaskNavigation.spec.ts › navigating to /table/TASK-XXXXX should show 404 (invalid URL pattern) (shard 3, 1 retry)
  • Flow/NotificationAlerts.spec.ts › destination should work properly (shard 4, 1 retry)
  • Pages/Domains.spec.ts › Verify domain and subdomain asset count accuracy (shard 5, 1 retry)
  • Pages/EntityDataConsumer.spec.ts › Tier Add, Update and Remove (shard 5, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should allow Data Steward to edit glossary terms for searchIndex (shard 6, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Glossary Bulk Import Export (shard 6, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Import partial success - some terms pass, some fail (shard 6, 1 retry)
  • Pages/InputOutputPorts.spec.ts › Output ports section collapse/expand (shard 6, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • VersionPages/ServiceEntityVersionPage.spec.ts › SearchIndex Service (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 added the To release Will cherry-pick this PR into the release branch label Jun 25, 2026
@Vishnuujain Vishnuujain self-assigned this Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 63%
63.42% (70688/111446) 45.9% (40625/88504) 47.81% (12369/25866)

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@Vishnuujain
Vishnuujain merged commit a0c306b into main Jun 26, 2026
62 of 64 checks passed
@Vishnuujain
Vishnuujain deleted the fix/mcp-domain-enforcement-internal-token-bypass branch June 26, 2026 15:25
@github-actions

Copy link
Copy Markdown
Contributor

Failed to cherry-pick changes to the 1.13 branch.
Please cherry-pick the changes manually.
You can find more details here.

@github-actions

Copy link
Copy Markdown
Contributor

Failed to cherry-pick changes to the 1.12.13 branch.
Please cherry-pick the changes manually.
You can find more details here.

@gitar-bot

gitar-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Bypasses 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

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java:234-248
isInternallyIssuedToken is now invoked unconditionally for every authenticated request in checkValidationsForToken. It performs an extra full JWT.decode(tokenFromHeader) (in extractKeyId) plus a singleton lookup, even when enforcePrincipalDomain is false (in which case validateDomainEnforcement would have been a no-op anyway). On the per-request auth hot path this adds avoidable work.

Suggested fix: short-circuit when domain enforcement is disabled before computing the internal-token check, e.g. only call isInternallyIssuedToken when enforcePrincipalDomain is true. This preserves behavior since validateDomainEnforcement only throws when enforcement is enabled.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Vishnuujain added a commit that referenced this pull request Jun 29, 2026
* 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

This branch was previously deployed

1 inactive deployment
test — 7d3e341f Deployed Jun 26, 2026 by Vishnuujain via playwright-ci-postgresql (6, 6) #53393
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 To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants