Skip to content

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

Merged
Vishnuujain merged 3 commits into
mainfrom
mcp-revoke-on-user-delete
Oct 31, 2026
Merged

Vishnuujain merged 3 commits into
mainfrom
mcp-revoke-on-user-delete

Conversation

@Vishnuujain

Copy link
Copy Markdown
Contributor

Describe your changes:

Part of a larger set of MCP and auth fixes.

  • MCP OAuth grants are stored by user name and stayed valid after the user was deleted.
  • Deleting a user, soft or hard, now ends its MCP codes, access tokens, refresh tokens and any sign-in waiting for consent, on every client; a restored user signs in to MCP again. New grants are stored under the account's own name, and names compare ignoring case for older rows.
  • A 2.1.0 post-data migration ends grants left by users deleted earlier. Decision record: ADR:2026-10-26-an-mcp-oauth-grant-ends-30-days-after-sign-in (v2 amendment).

Type of change:

  • Bug fix

Tests:

Unit tests

  • UserSSOOAuthProviderTest: an SSO sign-in stores the grant under the account's name, not the provider's casing.

Backend integration tests

  • McpOAuthIT: after a hard delete and same-name signup the old access token gets 401, the refresh 400, and the code and waiting consent are gone; after a soft delete and restore the refresh is still refused. Fails without the change (old access token 200).
  • McpGrantMigrationIT: the migration ends grants of missing and deleted users only, keeps a live user's grant under another casing, and changes nothing on a second run.
  • Both ran locally on mysql-elasticsearch and postgres-opensearch.

Manual testing performed

  • Local build: hard delete + recreate and soft delete + restore of an MCP-signed-in user, old tokens refused.

@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 30, 2026
@Vishnuujain Vishnuujain self-assigned this Oct 30, 2026
@Vishnuujain Vishnuujain added the To release Will cherry-pick this PR into the release branch label Oct 30, 2026
@gitar-bot

gitar-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🔴 High risk · Revoking MCP OAuth grants on user deletion changes token authorization; failures to match a user name could leave deleted users’ access active.

Deleting a user, soft or hard, now ends their MCP codes, access tokens, refresh tokens, and pending consents, and a 2.1.0 migration revokes grants left by previously deleted users. Resolved the finding where pending MCP consents could still issue a code after user deletion.

✅ 1 closed
✅ Bug: User delete leaves pending MCP consents, so a code can still be issued

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/OAuthDAOs.java:228-239 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java:1688 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/mcp/McpOAuthIT.java:449-463
The description says deleting a user ends "any sign-in waiting for consent", and the ADR amendment says every grant held under the name ends. But revokeAllGrantsOfUser (OAuthDAOs.java:234-239) only touches oauth_authorization_codes, oauth_refresh_tokens and oauth_access_tokens. A mcp_pending_auth_requests row whose consent_user_name belongs to the deleted user stays in place. handleConsentDecision takes the user name from that row and relayConsentDecision creates an authorization code for it without checking the user again. So if someone approves after the delete, a new code is minted for the name. If an account with the same name has been created by then, exchangeAuthorizationCode's NON_DELETED lookup succeeds and the old sign-in becomes a grant for the new account. That is the takeover this PR is meant to close. testDeletedUsersGrant_doesNotPassToANewUserWithTheSameName never seeds a waiting consent, so the claim that it checks one is untested. Fix: add a case-insensitive delete of pending consent rows to the @Transaction method, add it to the 2.1.0 migration, and assert in the IT that the consent is gone.

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 marked this pull request as ready for review October 30, 2026 13:36
@Vishnuujain
Vishnuujain requested a review from a team as a code owner October 30, 2026 13:36
@github-actions

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.

@Vishnuujain
Vishnuujain enabled auto-merge October 30, 2026 13:53
@Vishnuujain
Vishnuujain added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit f2f7351 Oct 31, 2026
123 of 124 checks passed
@Vishnuujain
Vishnuujain deleted the mcp-revoke-on-user-delete branch October 31, 2026 14:11
Vishnuujain added a commit that referenced this pull request Nov 2, 2026
* fix(mcp): access token revoke (backport 2.0 #36498)

* fix(mcp): revoke oauth grants of deleted users (backport 2.0 #36699) (#36779)
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 To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants