Skip to content

fix(mcp): revoke oauth grants of deleted users (backport 2.1 #36699) - #36784

Merged
Vishnuujain merged 1 commit into
2.1from
mcp-revoke-on-user-delete-2.1
Nov 2, 2026
Merged

Vishnuujain merged 1 commit into
2.1from
mcp-revoke-on-user-delete-2.1

Conversation

@Vishnuujain

Copy link
Copy Markdown
Contributor

Describe your changes:

Backport of #36699 to 2.1; the automatic backport did not run for it.

  • Same change as on main. Only where it lands differs: the migration statements are appended to 2.1's 2.1.0 post-data scripts, and the revoke runs inside 2.1's existing beginDeleteLifecycle.

Type of change:

  • Bug fix

Tests:

Unit tests

  • UserSSOOAuthProviderTest: 24/24.

Backend integration tests

  • McpOAuthIT 20/20 and McpGrantMigrationIT on MySQL + Elasticsearch and Postgres + OpenSearch, run locally on this branch.

@Vishnuujain
Vishnuujain requested a review from a team as a code owner November 1, 2026 10:52
@Vishnuujain
Vishnuujain requested review from sonika-shah and removed request for a team November 1, 2026 10:52
@github-actions

github-actions Bot commented Nov 1, 2026

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 Nov 1, 2026
Comment on lines 1663 to 1669
return () -> {
try (parentLifecycle) {
finishCredentialDelete.run();
// MCP grants are keyed by user name, so a later account with the same name would take
// them over.
daoCollection.oauthRefreshTokenDAO().revokeAllGrantsOfUser(entity.getName());
}

@gitar-bot gitar-bot Bot Nov 1, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: MCP grants are revoked even when the user delete fails

revokeAllGrantsOfUser runs in the DeleteLifecycle.close() lambda. deleteContents and the bulk soft/hard-delete paths call that lambda from try-with-resources, so it runs whether the delete succeeds or throws. The existing finishCredentialDelete is safe to run on failure because it only reloads the token cache from the DB. The new call is different: it deletes codes, waiting consents and access tokens, and revokes refresh tokens. So if the delete aborts partway (deletion-lock conflict, a cascade error or a transaction failure), the user still exists but every MCP client they use is signed out. This fails in the safe direction, but a failed admin action still has a side effect users can see. Track whether the delete completed (for example, a flag set after the delete body returns) and revoke only then. Alternatively, move the revoke into postDelete, which runs only after a successful soft or hard delete and already holds revokeLiveSessions.

Revoke in postDelete, next to the other post-delete session cleanup, so it only runs once the delete has succeeded:

@Override
protected void postDelete(User entity, boolean hardDelete) {
  super.postDelete(entity, hardDelete);
  JwtFilter.invalidateResolvedEmailIdentity(entity.getEmail());
  revokeLiveSessions(entity);
  // MCP grants are keyed by user name, so a later account with the same name would take them over.
  daoCollection.oauthRefreshTokenDAO().revokeAllGrantsOfUser(entity.getName());

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 closed / 1 findings

🔴 High risk · User deletion now revokes MCP OAuth grants and migration clears orphaned grants, which could abruptly interrupt clients relying on those tokens.

Backports the MCP OAuth grant revocation for deleted users to 2.1, so access and refresh tokens are cleared when a user is removed. Approved with suggestions: the revoke runs in the DeleteLifecycle.close() path, so it can fire even when the user delete fails partway. Consider tracking delete completion and revoking only on success, or moving the revoke into postDelete in UserRepository.java.

💡 Edge Case: MCP grants are revoked even when the user delete fails

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java:1663-1669

revokeAllGrantsOfUser runs in the DeleteLifecycle.close() lambda. deleteContents and the bulk soft/hard-delete paths call that lambda from try-with-resources, so it runs whether the delete succeeds or throws. The existing finishCredentialDelete is safe to run on failure because it only reloads the token cache from the DB. The new call is different: it deletes codes, waiting consents and access tokens, and revokes refresh tokens. So if the delete aborts partway (deletion-lock conflict, a cascade error or a transaction failure), the user still exists but every MCP client they use is signed out. This fails in the safe direction, but a failed admin action still has a side effect users can see. Track whether the delete completed (for example, a flag set after the delete body returns) and revoke only then. Alternatively, move the revoke into postDelete, which runs only after a successful soft or hard delete and already holds revokeLiveSessions.

Revoke in postDelete, next to the other post-delete session cleanup, so it only runs once the delete has succeeded
@Override
protected void postDelete(User entity, boolean hardDelete) {
  super.postDelete(entity, hardDelete);
  JwtFilter.invalidateResolvedEmailIdentity(entity.getEmail());
  revokeLiveSessions(entity);
  // MCP grants are keyed by user name, so a later account with the same name would take them over.
  daoCollection.oauthRefreshTokenDAO().revokeAllGrantsOfUser(entity.getName());
🤖 Prompt for agents
Code Review: Backports the MCP OAuth grant revocation for deleted users to `2.1`, so access and refresh tokens are cleared when a user is removed. Approved with suggestions: the revoke runs in the `DeleteLifecycle.close()` path, so it can fire even when the user delete fails partway. Consider tracking delete completion and revoking only on success, or moving the revoke into `postDelete` in `UserRepository.java`.

1. 💡 Edge Case: MCP grants are revoked even when the user delete fails
   Files: openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java:1663-1669

   `revokeAllGrantsOfUser` runs in the `DeleteLifecycle.close()` lambda. `deleteContents` and the bulk soft/hard-delete paths call that lambda from try-with-resources, so it runs whether the delete succeeds or throws. The existing `finishCredentialDelete` is safe to run on failure because it only reloads the token cache from the DB. The new call is different: it deletes codes, waiting consents and access tokens, and revokes refresh tokens. So if the delete aborts partway (deletion-lock conflict, a cascade error or a transaction failure), the user still exists but every MCP client they use is signed out. This fails in the safe direction, but a failed admin action still has a side effect users can see. Track whether the delete completed (for example, a flag set after the delete body returns) and revoke only then. Alternatively, move the revoke into `postDelete`, which runs only after a successful soft or hard delete and already holds `revokeLiveSessions`.

   Fix (Revoke in postDelete, next to the other post-delete session cleanup, so it only runs once the delete has succeeded):
   @Override
   protected void postDelete(User entity, boolean hardDelete) {
     super.postDelete(entity, hardDelete);
     JwtFilter.invalidateResolvedEmailIdentity(entity.getEmail());
     revokeLiveSessions(entity);
     // MCP grants are keyed by user name, so a later account with the same name would take them over.
     daoCollection.oauthRefreshTokenDAO().revokeAllGrantsOfUser(entity.getName());

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@Vishnuujain
Vishnuujain merged commit 4c2a4b1 into 2.1 Nov 2, 2026
62 of 63 checks passed
@Vishnuujain
Vishnuujain deleted the mcp-revoke-on-user-delete-2.1 branch November 2, 2026 09:06
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant