OpenMetadata icon indicating copy to clipboard operation
OpenMetadata copied to clipboard

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

Open Vishnuujain opened this issue 5 months ago • 4 comments

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: https://github.com/open-metadata/openmetadata-collate/issues/4696

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.

Changes

  • JwtFilter: gate validateDomainEnforcement with isInternallyIssuedToken; add isInternallyIssuedToken and extractKeyId helpers
  • SecurityUtil: add isOpenMetadataIssuedToken (static, testable in isolation); add ISSUER_CLAIM constant
  • JWTTokenGenerator: expose issuer and kid via @Getter (were private, no accessor)

Tests

  • openMetadataIssuedTokenBypassesDomainEnforcement — OM token with bare sub=asmith passes a domain-enforcing filter
  • externalTokenStillEnforcedWhenServerHasNoSigningIdentity — fallback to enforcement when JWTTokenGenerator has no signing identity
  • spoofedOpenMetadataKeyIdWithoutMatchingSignatureIsRejected — attacker key with spoofed kid is rejected at signature verification before bypass logic runs
  • testIsOpenMetadataIssuedTokenRequiresMatchingIssuerAndKeyId — unit tests for the static helper
  • testIsOpenMetadataIssuedTokenFalseWhenServerHasNoSigningIdentity — null/empty server identity always returns false

Greptile Summary

This PR fixes a bug where enforcePrincipalDomain=true incorrectly blocked OM-internally-issued tokens (PATs, session tokens, bot tokens) because their preferred_username claim carries a bare username without an @domain suffix, causing getFirstMatchJwtClaim-based domain extraction to produce an empty string.

  • JwtFilter: gates validateDomainEnforcement behind a new isInternallyIssuedToken helper that matches the token's kid header and iss claim against JWTTokenGenerator's configured values; domain enforcement is skipped only when both match, preserving enforcement for all external IdP tokens.
  • SecurityUtil: adds the static isOpenMetadataIssuedToken method (testable in isolation) and the ISSUER_CLAIM constant; when either server-side identity field is absent or empty, the method always returns false, keeping the safe-fail fallback intact.
  • JWTTokenGenerator: exposes issuer and kid via Lombok @Getter; three new integration tests and two unit tests cover the bypass, the fallback, and a spoofed-kid rejection scenario.

Confidence Score: 5/5

Safe to merge. The bypass is narrowly scoped to tokens whose kid and iss both match JWTTokenGenerator's own values, and signature verification already ran before this check — an external IdP cannot forge a matching token.

The fix correctly gates domain enforcement on a two-factor identity check (kid + iss), falls back to enforcement when JWTTokenGenerator has no signing identity, and does not change any other validation step. The test suite covers the bypass, the fallback, and the spoofed-kid rejection, confirming the trust boundary is intact.

No files require special attention.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java Adds isInternallyIssuedToken gate around validateDomainEnforcement; logic is correct and fails safe when JWTTokenGenerator has no signing identity.
openmetadata-service/src/main/java/org/openmetadata/service/security/SecurityUtil.java Adds isOpenMetadataIssuedToken static helper; correctly handles null/empty server identity, missing iss claim, and null tokenKeyId without NPE.
openmetadata-service/src/main/java/org/openmetadata/service/security/jwt/JWTTokenGenerator.java Minimal change: adds @Getter to issuer and kid fields. Fields are written once at startup and effectively immutable thereafter.
openmetadata-service/src/test/java/org/openmetadata/service/security/JwtFilterTest.java Three new integration tests cover the bypass, fallback, and attacker-spoofed kid rejection end-to-end.
openmetadata-service/src/test/java/org/openmetadata/service/security/SecurityUtilTest.java Two new unit tests cover isOpenMetadataIssuedToken comprehensively including null/empty server identity cases.

Reviews (2): Last reviewed commit: "review: fix comment accuracy and short-c..." | Re-trigger Greptile

Vishnuujain avatar Jun 24 '26 14:06 Vishnuujain

❌ 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[bot] avatar Jun 24 '26 14:06 github-actions[bot]

🟡 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

github-actions[bot] avatar Jun 24 '26 18:06 github-actions[bot]

Jest test Coverage

UI tests summary

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

github-actions[bot] avatar Jun 25 '26 18:06 github-actions[bot]

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

github-actions[bot] avatar Jun 26 '26 15:06 github-actions[bot]

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

github-actions[bot] avatar Jun 26 '26 15:06 github-actions[bot]

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

gitar-bot avatar Jun 26 '26 15:06 gitar-bot