Skip to content

Fixes #32052: reject revoked bot tokens and PATs on every pod - #32872

Merged
harshach merged 10 commits into
mainfrom
fix/32052-revoked-tokens
Sep 21, 2026
Merged

harshach merged 10 commits into
mainfrom
fix/32052-revoked-tokens

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #32052

Bot tokens and personal access tokens were already checked against BotTokenCache / UserTokenCache on 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 / UserTokenCache publish a botToken / userToken revocation on the existing CacheInvalidationPubSub channel and register as Invalidatables in CacheBundle, 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.isEntityType keeps these out-of-band signals from bumping entity write epochs, the same treatment personaContext already gets.
  • UserRepository.postDelete drops 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:

  • Bug fix

High-level design:

Reuses the Redis pub/sub channel and the Invalidatable registry 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

  • Admin revokes a bot token: the bot's next request is 401, on the same pod and on a peer pod
  • Admin regenerates a bot token: the previous token is 401, the new one works
  • Bot user deleted: its token is 401
  • User revokes one PAT / all PATs: each revoked PAT is 401 on the next request, same pod and peer pod
  • User soft-deleted: their PAT is 401

Unit tests

  • JwtFilterTest: botTokenIsRejectedOnceRevokedOrRotated, botTokenIsAcceptedWhileItIsTheCurrentOne
  • BotTokenCacheTest, 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/sub

Backend 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 PATs

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. mvn -pl openmetadata-service test -Dtest=JwtFilterTest,BotTokenCacheTest,UserTokenCacheTest → 26 tests pass
  2. mvn -pl openmetadata-integration-tests test -Dtest='UserResourceIT#test_revoke*+test_regenerate*+test_deleteBotUser_rejectsBotToken+test_deleteUser_rejectsPersonalAccessToken' (mysql-elasticsearch) → 6 pass
  3. mvn verify -pl openmetadata-integration-tests -Pmysql-elasticsearch-redis -DintegrationTests.lane=multi-node -Dit.test=TokenRevocationRedisMultiNodeIT → 3 pass with Cache provider: redis

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable, no schema changes.
  • For UI changes: not applicable.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

🤖 Generated with Claude Code

RetriggerConfidence Score: 5/5

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

  1. P1 Security Credentials Published Before Commit ▶
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.

  • Adds bounded local credential state for non-Redis deployments and shared, fail-closed mutation coordination when Redis is configured.
  • Wraps bot and PAT mutations in synchronization and integrates user deletion/restoration with credential lifecycle handling.
  • Adds single-node and Redis multi-node coverage for revocation, rotation, deletion, and restoration.
  • Preserves existing legacy direct Department memberships while continuing to reject newly added invalid memberships.
Diagram
sequenceDiagram
  participant Client
  participant NodeA as Service node A
  participant Redis
  participant DB
  participant NodeB as Service node B

  Client->>NodeB: Request with current token
  NodeB->>Redis: Read credential snapshot
  Redis-->>NodeB: Ready snapshot
  NodeB-->>Client: Authorized

  Client->>NodeA: Revoke or rotate token
  NodeA->>Redis: Acquire mutation lease
  NodeA->>Redis: Publish fail-closed mutating state
  NodeA->>DB: Persist credential mutation
  DB-->>NodeA: Commit
  NodeA->>Redis: Publish replacement snapshot
  NodeA->>Redis: Release mutation lease
  NodeA-->>Client: Mutation completed

  Client->>NodeB: Reuse revoked token
  NodeB->>Redis: Read replacement snapshot
  Redis-->>NodeB: Token absent
  NodeB-->>Client: 401 Unauthorized
Loading

Reviews (5) · Last reviewed commit: "fix: preserve legacy user team membershi..."

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]>
Copilot AI lite review requested due to automatic review settings September 7, 2026 13:53
@mohityadav766
mohityadav766 requested a review from a team as a code owner September 7, 2026 13:53
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 7, 2026

Copilot AI left a comment

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.

🟡 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 CacheInvalidationPubSub and register both caches as Invalidatables 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.

Comment on lines +195 to +198
/** 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);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copilot AI review requested due to automatic review settings September 7, 2026 14:19

Copilot AI left a comment

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.

🟡 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

  • isEntityType will throw a NullPointerException if type is null because Set.of(...).contains(null) NPEs. The previous TYPE_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

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 6080a4f36ddea9e7cdb386b9ea4edd4ac5829c30 in Playwright run 35547922955, attempt 2.

✅ 4535 passed · ❌ 0 failed · 🟡 10 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking 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:

  • Common shard skew was 34.08% (convergence target: at most 15%).
  • Browser traffic was 224.86 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.23 per UI scenario (10776 boots / 4835 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 130 0 0 0 0 0
✅ Shard chromium-01 143 0 0 1 0 0
✅ Shard chromium-02 140 0 0 0 0 0
✅ Shard chromium-03 178 0 0 0 0 0
✅ Shard chromium-04 187 0 0 0 0 0
✅ Shard chromium-05 166 0 0 0 0 0
🟡 Shard chromium-06 162 0 1 0 0 0
✅ Shard chromium-07 174 0 0 0 0 0
✅ Shard chromium-08 192 0 0 0 0 0
✅ Shard chromium-09 154 0 0 0 0 0
✅ Shard chromium-10 170 0 0 0 0 0
🟡 Shard chromium-11 159 0 1 0 0 0
🟡 Shard chromium-12 190 0 1 0 0 0
🟡 Shard chromium-13 168 0 1 0 0 0
✅ Shard chromium-14 185 0 0 0 0 0
🟡 Shard chromium-15 161 0 1 0 0 0
✅ Shard chromium-16 208 0 0 0 0 0
🟡 Shard chromium-17 176 0 2 0 0 0
✅ Shard chromium-18 178 0 0 0 0 0
✅ Shard chromium-19 166 0 0 0 0 0
🟡 Shard chromium-20 176 0 2 0 0 0
✅ Shard chromium-21 167 0 0 0 0 0
🟡 Shard chromium-22 164 0 1 0 0 0
✅ Shard chromium-23 196 0 0 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 80 0 0 0 0 0
✅ Shard import-export-02 70 0 0 0 0 0
✅ Shard ingestion-01 46 0 0 0 0 0
✅ Shard ingestion-02 53 0 0 0 0 0
✅ Shard reindex-01 40 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 10 flaky test(s) (passed on retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify LineageSearchSelect in lineage mode (shard chromium-06, 1 retry)
  • Features/Glossary/GlossaryMutualExclusivityDataProductTree.spec.ts › ME-S02: Can select multiple children under non-ME parent (shard chromium-11, 1 retry)
  • Features/Glossary/GlossaryHierarchy.spec.ts › should move nested term to root level of same glossary (shard chromium-12, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Article card metadata, widgets, and listing search update from UI edits (shard chromium-13, 1 retry)
  • Features/AccessControlSettings.spec.ts › should show all 4 landing cards and navigate to each panel (shard chromium-15, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Related assets, activity feed, user mentions, and article mentions work (shard chromium-17, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-17, 1 retry)
  • Features/AIMode/CustomPropertiesPanel.spec.ts › adds a Date custom property with format config (shard chromium-20, 1 retry)
  • Features/PersonaAIContext.spec.ts › configures every entity type, behavior, section, filter, and setting (shard chromium-20, 1 retry)
  • Pages/DescriptionVisibility.spec.ts › Customized Table detail page Description widget shows long description (shard chromium-22, 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

@mohityadav766 mohityadav766 self-assigned this Sep 7, 2026
// 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);

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.

P1 security 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:

@greptile-apps

greptile-apps Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

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

  • P1 Bot Creation Skips Synchronization openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java:721 ▶

    The POST user-creation path generates and persists a bot JWT without using BotTokenCache.mutateToken. When a hard-deleted bot name is reused while its shared snapshot still contains the prior empty state, the new token is rejected across the deployment until the snapshot's two-minute TTL expires. Wrap bot creation in the same credential mutation protocol used by the PUT and token-generation paths.

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-09-21T00:30:20Z)

No failing check on merge-queue commit 32dcbbf — invalidated by an entry ahead in the queue, or a required check timed out.

@gitar-bot

gitar-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
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

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java:1736-1743
On the PUT/update path, validateGroupTeams(requestedTeams) is run against the full set of teams on the request (which for a PUT or a non-team PATCH equals the user's current teams), not just the teams being newly added. If a user was assigned to a non-GROUP team by an older version before this check existed, every subsequent PUT to that user will now throw invalidTeamDirectUserAssignment and become unmodifiable, even for unrelated field changes. Validate only the teams being added (the difference between requestedTeams and origTeams) so pre-existing memberships don't block unrelated updates.

✅ Quality: Test asserts on exact exception message string

📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/UserResourceIT.java:373-382
test_putCreateUserRejectsDepartmentTeam asserts exception.getMessage() equals the exact DIRECT_USER_ASSIGNMENT_ERROR string. This couples the test to the wire/exception formatting of the SDK client and to the exact wording in CatalogExceptionMessage; a rewording or a wrapping change in the client will break it without a real behavior change. Prefer asserting on the HTTP status (400) or a substring/message-key match.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Revoked tokens stay revoked — reject bot tokens and user PATs after revocation

3 participants