Repository navigation
fix(mcp): revoke oauth grants of deleted users (backport 2.1 #36699) - #36784
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
| 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()); | ||
| } |
There was a problem hiding this comment.
💡 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 👍 / 👎
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 💡 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
Revoke in postDelete, next to the other post-delete session cleanup, so it only runs once the delete has succeeded🤖 Prompt for agentsVerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. 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:
Backport of #36699 to
2.1; the automatic backport did not run for it.main. Only where it lands differs: the migration statements are appended to2.1's2.1.0post-data scripts, and the revoke runs inside2.1's existingbeginDeleteLifecycle.Type of change:
Tests:
Unit tests
UserSSOOAuthProviderTest: 24/24.Backend integration tests
McpOAuthIT20/20 andMcpGrantMigrationITon MySQL + Elasticsearch and Postgres + OpenSearch, run locally on this branch.