fix: bypass domain enforcement for OM-internally-issued tokens
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:
- Its
kid(key id header) matchesJWTTokenGenerator's signing key id - Its
issclaim matchesJWTTokenGenerator'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 —validateDomainEnforcementhas an earlyreturnforisBot = truetokens (line 380), so bots have always bypassed domain enforcement. This fix makes all OM-minted tokens consistent with that existing behavior.
Changes
JwtFilter: gatevalidateDomainEnforcementwithisInternallyIssuedToken; addisInternallyIssuedTokenandextractKeyIdhelpersSecurityUtil: addisOpenMetadataIssuedToken(static, testable in isolation); addISSUER_CLAIMconstantJWTTokenGenerator: exposeissuerandkidvia@Getter(were private, no accessor)
Tests
openMetadataIssuedTokenBypassesDomainEnforcement— OM token with baresub=asmithpasses a domain-enforcing filterexternalTokenStillEnforcedWhenServerHasNoSigningIdentity— fallback to enforcement when JWTTokenGenerator has no signing identityspoofedOpenMetadataKeyIdWithoutMatchingSignatureIsRejected— attacker key with spoofedkidis rejected at signature verification before bypass logic runstestIsOpenMetadataIssuedTokenRequiresMatchingIssuerAndKeyId— unit tests for the static helpertestIsOpenMetadataIssuedTokenFalseWhenServerHasNoSigningIdentity— 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: gatesvalidateDomainEnforcementbehind a newisInternallyIssuedTokenhelper that matches the token'skidheader andissclaim againstJWTTokenGenerator's configured values; domain enforcement is skipped only when both match, preserving enforcement for all external IdP tokens.SecurityUtil: adds the staticisOpenMetadataIssuedTokenmethod (testable in isolation) and theISSUER_CLAIMconstant; when either server-side identity field is absent or empty, the method always returnsfalse, keeping the safe-fail fallback intact.JWTTokenGenerator: exposesissuerandkidvia Lombok@Getter; three new integration tests and two unit tests cover the bypass, the fallback, and a spoofed-kidrejection 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
❌ 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 #12345to the description). For a same-org cross-repo issue, addFixes open-metadata/<repo>#123to 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.
🟡 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)
How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace
Jest test Coverage
UI tests summary
| Lines | Statements | Branches | Functions |
|---|---|---|---|
| 63.42% (70688/111446) | 45.9% (40625/88504) | 47.81% (12369/25866) |
Quality Gate passed for 'open-metadata-ui'
Issues
1241 New issues
0 Accepted issues
Measures
13 Security Hotspots
0.0% Coverage on New Code
3.4% Duplication on New Code
Quality Gate passed for 'open-metadata-ingestion'
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Failed to cherry-pick changes to the 1.13 branch. Please cherry-pick the changes manually. You can find more details here.
Failed to cherry-pick changes to the 1.12.13 branch. Please cherry-pick the changes manually. You can find more details here.
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. 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java:234-248
Suggested fix: short-circuit when domain enforcement is disabled before computing the internal-token check, e.g. only call Display: compact → Showing less information. Comment with these commands to change:Code Review ✅ Approved 1 resolved / 1 findings
✅ 1 resolved
✅ Performance: Token re-decoded on every request even when enforcement off
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.isInternallyIssuedToken when enforcePrincipalDomain is true. This preserves behavior since validateDomainEnforcement only throws when enforcement is enabled.Options
Compact
gitar display:verbose
Was this helpful? React with 👍 / 👎 | Gitar