Repository navigation
Fixes #32052: reject revoked bot tokens and PATs on every pod - #32872
Conversation
Bot tokens and personal access tokens are validated against per-JVM caches (BotTokenCache, UserTokenCache) that only the revoking pod invalidated, so a revoked or rotated credential stayed accepted on every other pod until the 2-minute cache TTL. The caches now publish a revocation on the existing Redis cache-invalidation channel and register as Invalidatables, so peers evict the entry immediately while the request path still pays no database round trip. Deleting a user now also drops the PAT cache (only the bot cache was cleared), so a deleted user's personal access tokens stop working on the deleting pod right away instead of at the cache TTL. Tests: JwtFilterTest (bot token revoked/rotated/current), BotTokenCacheTest and UserTokenCacheTest (publish + peer eviction), UserResourceIT revoke-then-call for bot revoke/rotate/delete and PAT revoke/revoke-all/user delete, and TokenRevocationRedisMultiNodeIT (two nodes sharing Redis) in the multi-node lane. Co-Authored-By: Claude Fable 5.1 <[email protected]>
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
There was a problem hiding this comment.
🟡 Changes recommended
CacheInvalidationPubSub.isEntityType should be made null-safe to avoid avoidable handler exceptions on malformed/partial pub/sub messages.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes a multi-pod consistency gap in credential revocation by propagating bot token and user PAT cache invalidations across pods via the existing Redis cache-invalidation pub/sub channel, ensuring revoked/rotated tokens are rejected immediately without adding DB lookups to the request path.
Changes:
- Publish bot-token and user-PAT revocation events on
CacheInvalidationPubSuband register both caches asInvalidatables so peer pods evict immediately. - Ensure non-entity invalidation signals (persona context + token revocations) do not bump entity write epochs.
- Expand unit + integration coverage, including a new Redis multi-node integration test to verify cross-node immediate rejection.
File summaries
| File | Description |
|---|---|
| openmetadata-service/src/test/java/org/openmetadata/service/security/JwtFilterTest.java | Adds JwtFilter unit coverage for bot-token acceptance vs rejection after revoke/rotation. |
| openmetadata-service/src/test/java/org/openmetadata/service/security/auth/UserTokenCacheTest.java | New unit tests validating PAT cache publishes revocations and evicts on peer signals. |
| openmetadata-service/src/test/java/org/openmetadata/service/security/auth/BotTokenCacheTest.java | New unit tests validating bot-token cache publishes revocations and evicts on peer signals. |
| openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java | Publishes PAT revocation events and exposes an Invalidatable to evict local cache on peer revocations. |
| openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BotTokenCache.java | Publishes bot-token revocation events and exposes an Invalidatable to evict local cache on peer revocations. |
| openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java | Ensures deleting users invalidates the appropriate credential cache (bot token vs PATs). |
| openmetadata-service/src/main/java/org/openmetadata/service/cache/CacheInvalidationPubSub.java | Introduces token-revocation signal types and an isEntityType helper to distinguish out-of-band signals. |
| openmetadata-service/src/main/java/org/openmetadata/service/cache/CacheBundle.java | Registers the new invalidators and prevents non-entity signals from triggering entity epoch bumps. |
| openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/UserResourceIT.java | Adds revoke/rotate/delete regression coverage for bot tokens and PATs at the API level. |
| openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/TokenRevocationRedisMultiNodeIT.java | New Redis-gated multi-node IT proving immediate cross-node rejection after revoke/rotate. |
| openmetadata-integration-tests/pom.xml | Wires the new multi-node IT into the relevant multi-node/redis include lists. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /** Whether {@code type} names an entity type, as opposed to one of the out-of-band signals. */ | ||
| public static boolean isEntityType(String type) { | ||
| return !NON_ENTITY_TYPES.contains(type); | ||
| } |
There was a problem hiding this comment.
Good catch, fixed in a2a8afc88b.
Confirmed the regression is real: Set.of(...).contains(null) throws, whereas the TYPE_PERSONA_CONTEXT.equals(msg.type()) it replaced was null-safe. It matters more than a stray log line, because isEntityType runs ahead of the Invalidatable fan-out, so a typeless message would abort the whole handler inside the outer catch and silently skip every eviction it carried, including the token caches this PR adds.
isEntityType now returns false for null, on the reasoning that a message naming no entity is not an entity type. Pinned by the new CacheInvalidationPubSubTest.
There was a problem hiding this comment.
🟡 Changes recommended
There are a couple of small but concrete correctness/stability issues in the new helper/test code that should be fixed before merge (null-safety in isEntityType, and static-state leakage in UserTokenCacheTest).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
openmetadata-service/src/main/java/org/openmetadata/service/cache/CacheInvalidationPubSub.java:198
isEntityTypewill throw a NullPointerException iftypeis null becauseSet.of(...).contains(null)NPEs. The previousTYPE_PERSONA_CONTEXT.equals(msg.type())check was null-safe, so this is a regression for malformed/partial pubsub messages and it can short-circuit the whole remote-invalidation handler.
/** Whether {@code type} names an entity type, as opposed to one of the out-of-band signals. */
public static boolean isEntityType(String type) {
return !NON_ENTITY_TYPES.contains(type);
}
- Files reviewed: 11/11 changed files
- Comments generated: 1
- Review effort level: Lite
✅ Playwright Results — workflow succeededValidated commit ✅ 4535 passed · ❌ 0 failed · 🟡 10 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 1h 11m 34s ⏱️ Max setup 4m 36s · max shard execution 22m 18s · max shard-job elapsed before upload 25m 28s · reporting 16s 🌐 224.86 requests/attempt · 2.23 app boots/UI scenario · 34.08% common-shard skew Optimization targets still in progress:
🟡 10 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 |
| // that). A re-entered cascade where this level is already restored must still | ||
| // reconcile HAS-related children (e.g., dashboard charts) of nested descendants. | ||
| restoreAdditionalChildren(id, updatedBy); | ||
| postRestore(restoredEntity); |
There was a problem hiding this comment.
Credentials Published Before Commit
Restoring a user publishes the bot or PAT credential snapshot before the database transaction returns. If that transaction later fails during commit, Redis retains credentials for an account that remains deleted, allowing those credentials to authenticate until the snapshot expires or is replaced. Defer this shared-state update until the restore commits successfully.
How this was verified: restoreEntity invokes postRestore before its transactional method returns, and postRestore synchronously reloads the user's credentials into shared state.
Knowledge Base Used:
Comments Outside DiffThese findings sit on lines the diff does not cover, so they could not be posted inline. Each one leaves this list once its file changes.
|
🚦 Removed from the merge queue —
|
Code Review ✅ No issues found 2 closed / 2 findings🔴 High risk Fixes multi-pod token revocation by publishing bot token and PAT revocations to Redis, ensuring immediate rejection across all pods instead of relying on per-JVM cache TTL. User deletion now clears both bot and PAT caches. No open issues. ✅ 2 closed✅ Edge Case: updateTeams validates all teams, blocking edits to legacy members
✅ Quality: Test asserts on exact exception message string
OptionsDisplay: compact → Counting what did not apply, without listing it. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|



Describe your changes:
Fixes #32052
Bot tokens and personal access tokens were already checked against
BotTokenCache/UserTokenCacheon every request, but both are per-JVM Guava caches (2-minute TTL) and a revoke only invalidated the pod that handled it. On a multi-pod deployment a revoked or rotated bot token / PAT kept working on every other pod until the TTL expired. Deleting a user cleared only the bot cache, so a deleted user's PATs kept working on that pod for up to 2 minutes as well.Changes:
BotTokenCache/UserTokenCachepublish abotToken/userTokenrevocation on the existingCacheInvalidationPubSubchannel and register asInvalidatables inCacheBundle, so every pod evicts its entry immediately. No database round trip is added to the request path. Without Redis the behaviour is unchanged: local invalidation, TTL fallback on peer pods.CacheInvalidationPubSub.isEntityTypekeeps these out-of-band signals from bumping entity write epochs, the same treatmentpersonaContextalready gets.UserRepository.postDeletedrops the PAT cache for non-bot users.Checked and left alone: MCP already runs the full revocation check at its door (
SocketAddressFilter.validatePrefixedTokenRequest), and session-bound user tokens are already re-read from the session store per request. The Collate-minted support-access token is fixed separately in open-metadata/openmetadata-collate#6422.Type of change:
High-level design:
Reuses the Redis pub/sub channel and the
Invalidatableregistry that the entity caches already use (CacheBundle.run).invalidateToken()is the single funnel every revoke / rotate / generate / delete site already calls, so publishing from inside it fixes all callers at once; the registered invalidator is the receiving side.Alternatives considered: a per-request DB lookup (ruled out by the issue), a shorter cache TTL (still a window), a DB-polled revocation epoch (extra machinery for the no-Redis case, not needed for the immediate-on-Redis guarantee).
Rollout: no schema, config, or API change. Deployments without Redis keep today's TTL-bounded behaviour on peer pods.
Tests:
Use cases covered
Unit tests
JwtFilterTest:botTokenIsRejectedOnceRevokedOrRotated,botTokenIsAcceptedWhileItIsTheCurrentOneBotTokenCacheTest,UserTokenCacheTest(new): revocation is published to peers, a peer revocation evicts the local entry and forces a reload, foreign signal types are ignored, no-op without pub/subBackend integration tests
UserResourceIT: six revoke-then-call tests (bot revoke / regenerate / delete, PAT revoke / revoke-all / user delete)TokenRevocationRedisMultiNodeIT(new, gated to the Redis profiles, registered in the multi-node lane and the isolated/parallel include lists): revoke or rotate on node A, immediate 401 on node B for bot tokens and PATsIngestion integration tests
Playwright (UI) tests
Manual testing performed
mvn -pl openmetadata-service test -Dtest=JwtFilterTest,BotTokenCacheTest,UserTokenCacheTest→ 26 tests passmvn -pl openmetadata-integration-tests test -Dtest='UserResourceIT#test_revoke*+test_regenerate*+test_deleteBotUser_rejectsBotToken+test_deleteUser_rejectsPersonalAccessToken'(mysql-elasticsearch) → 6 passmvn verify -pl openmetadata-integration-tests -Pmysql-elasticsearch-redis -DintegrationTests.lane=multi-node -Dit.test=TokenRevocationRedisMultiNodeIT→ 3 pass withCache provider: redisUI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.🤖 Generated with Claude Code
The PR appears safe to merge; the prior transaction, deletion-lifecycle, storage-load, and synchronization concerns are addressed without introducing a new actionable failure.
Findings
Summary
This PR makes bot-token and personal-access-token validation use coordinated credential snapshots so revocation, rotation, deletion, and restoration are immediately visible across Redis-backed service nodes.
Diagram
Reviews (5) · Last reviewed commit: "fix: preserve legacy user team membershi..."