Repository navigation
fix: enforce session ownership for KILL and processlist - #30299
mergify[bot] merged 4 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
2337bef to
078cea1
Compare
078cea1 to
c8c9651
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
|
mo-bot review · Commit: "interrupted" |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: b5aefbba5641c4d50bc58e07ea9237627c27f8e0
Assessment: approve
Reviewed the complete delta and affected callers; no actionable findings remain. The design keeps authorization in the frontend, reuses the existing lifecycle guard, and separates trusted disconnect cleanup from SQL identity. Obsolete proxy impersonation paths are removed.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1
Validation:
-
Full race runs passed for frontend, proxy, queryservice/client, cnservice, and table_function: 3,085 top-level test passes.
-
Generation-boundary, disconnect-publication, and authenticated-tunnel tests each passed 100 repetitions under the race detector.
-
The supplied public regression passed through two real CNs and the production proxy under race detection, covering visibility, remote denial without target effects, role/user changes, self-KILL, and disconnect cancellation.
-
Protocol tests covered version 119→120→119 and message round trips. Descriptor comparison confirmed published fields and messages remain unchanged.
-
Verified native provenance, isolated execution, command receipts, frozen-source fingerprints, and retained logs. Evidence index: /home/xupeng/.local/state/mo-bot/jobs/a48067a0a45ff5cc188dea65/attempt-1/validation-audit.json. Source remains unchanged.
Limitations:
-
Performance was assessed through caller and allocation analysis; no production-scale benchmark was run.
-
Linked-issue bodies and detailed CI logs were not supplied. Changed-path behavior was independently validated.
-
The documented security guarantee requires upgrading all serving CNs and proxies; rollback restores the previous vulnerability.
Merge Queue Status
This pull request spent 1 hour 1 minute 5 seconds in the queue, including 1 hour 33 seconds running CI. Required conditions to merge
|
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
The new head ac7cbe0 is a clean merge of current main into the PR branch: the incremental delta from the previously reviewed b5aefbb consists entirely of two upstream main commits (MEDIUMINT reporting in INFORMATION_SCHEMA.COLUMNS, and GROUP BY or HAVING in recursive CTE scalar subqueries), and every file owned by this PR is byte-identical to the version already reviewed (verified zero diff across all 28 PR files, and the full origin/main...HEAD diff still totals 3068 insertions and 588 deletions over those same 28 files). The merged upstream commits do not interact with the session-authorization change. The prior conclusion therefore stands: the PR correctly closes the KILL and PROCESSLIST authorization gaps from issues #30276 and #30278. Established prior behavior remains that frontend KILL executed with no authorization and the proxy re-executed KILL on a temporary connection authenticated by replaying the original handshake, making SET ROLE and COM_CHANGE_USER downgrades exploitable and legitimate identity changes broken, while processlist exposed all rows to any sys-account user. The fix authorizes against the authenticated current-session identity through one shared predicate, pins the target generation under the migrateController lock from authorization through cancellation, forwards KILL through the existing tunnel, probes remote CNs sequentially with one outstanding RPC and a 10-second total bound, gates both new query-service methods at protocol version 120 on sender and receiver including 119 to 120 to 119 rollback, filters processlist rows pre-materialization with fail-closed identity, and replaces impersonating disconnect cleanup with a bounded trusted DisconnectSession RPC. I verified there is no mc and rt.mu lock cycle, mc.closed sealing preserves lifecycle admission, the added tunnel Close before backend capture is safe on that path since the only reqC sender pipe is already dead, release accounting matches on all paths, uint64 IDs are rejected before uint32 conversion, and pkg/pb/query still vets clean at the new head. Review state was reloaded: the only review remains the mo-bot approval and there are no inline comments; the mergify queue comment and superseded bot status are workflow states, not findings. One non-blocking cleanup persists and is restated below. Focused package tests for frontend, proxy, cnservice, queryservice/client, and table_function still cannot run in this checkout because thirdparties/install native headers (CRoaring, xxhash, usearch, jemalloc) are absent and cgo-only transitive dependencies block compilation even with CGO_ENABLED=0; this is an environment limitation not attributable to the PR.
P2 - Removing the proxy killEvent consumer leaves SelectByConnID and GetCNServerByConnID as dead production code (pkg/proxy/router.go:253)
After deleting the proxy kill event and handleKill dispatch, Router.SelectByConnID (pkg/proxy/router.go:253) no longer has any production caller at the new head ac7cbe0; it only forwards to SQLWorker.GetCNServerByConnID (pkg/proxy/sql_worker.go:120), which likewise becomes reachable only through this dead path, and connManager.GetCNServerByConnID (pkg/proxy/conn_manager.go:408) also has no callers. Behavior is unaffected, since KILL routing now happens through the frontend killSession local-plus-remote-RPC path, but retaining the unused impersonation-era connection-ID lookup chain invites confusion about which routing path is authoritative. Consider removing these methods and their implementations in a follow-up cleanup; keeping the security diff minimal here is a reasonable tradeoff.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: #30276 #30278 ## What this PR does / why we need it: PR #30299 fixed the authorization contracts for KILL and processlist visibility. When the returned two-CN plus Proxy acceptance script was rerun, those checks passed, but force-closing a client during a running `SELECT SLEEP(60)` left the backend session in processlist beyond the ten-second acceptance window. This PR closes the captured backend generation before sending the existing bounded best-effort `DisconnectSession` notification. It also treats plain EOF/connection-end errors with an in-flight client request as client disconnects, while preserving the explicit server-disconnect boundary. That closes the path missed by PR #30299 without changing its authorization behavior. ## Validation - Native CGo focused proxy tests and race tests for close-before-notify, migration sealing, plain in-flight EOF, and idle EOF. - Native frontend KILL authorization/generation/self-disconnect tests. - Native table-function processlist visibility test. - Real two-CN plus MatrixOne Proxy PyMySQL acceptance, including cross-user KILL/processlist checks and changed-user force-close cancellation. - `make cgo NATIVE_BUILD_JOBS=4` and `make build NATIVE_BUILD_JOBS=4`. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Related to #30276 and #30278; leave open for reporter verification.
What this PR does / why we need it:
Authorize SQL KILL against the authenticated current-session identity and pin the target generation through the action. Ordinary users can affect their own sessions, account administrators their account, and sys/moadmin the cluster. Filter processlist rows before materialization using the same current statement identity.
Forward original SQL through the existing proxy backend, preserving role/user changes. Keep trusted disconnect cleanup separate from SQL authorization: complete terminal tunnel close before capturing its backend, use a bounded cleanup context, and never retry uncertain effects or fall back to re-authenticating the original login. Remote KILL has one outstanding RPC and a 10-second total bound.
Rebase preserves main's SQL-mode/warning setup and samples account/user/role under the existing TenantInfo lock. Merge the authoritative query.proto additively and regenerate query.pb.go with the repository-pinned tooling. Published main methods and field tags remain unchanged. Preserve main capability 119; these new methods require 120 at sender and receiver, including 119→120→119 rollback.
Fix fixture ownership: release the blocked disconnect waiter even on assertion failure, restore the test QueryClient, include partial manual-fixture initialization in teardown, and update protocol error assertions.
No catalog or persisted data format changes. Upgrade all serving CNs and proxies before relying on the new behavior. Capability 120 must be recalculated if another capability PR merges first.
Validation
Current local validation: canonical native build and pinned query.proto generation; full owning race packages (queryservice/client, proxy, table_function, frontend, cnservice), including the exact prior CI TestViewDescriptionSubscription; current protocol admission/codec and cleanup regressions. Formatting, vet, incremental molint (zero introduced findings) and golangci-lint (0 issues, successful exit) pass. The existing public PyMySQL regression passes through two real CNs and a real proxy: SHOW/function/view/prepared visibility; remote KILL denial without target effect; single/multi-statement and prepared role changes; COM_CHANGE_USER and failed identity switches; self KILL and changed-user disconnect cancellation. The isolated harness enables the real CN proxy framing and verifies both CNs are published in each process topology cache before assertions. No historical body-only BVT counts are claimed.
Rebased onto official main
2508ce7029b03e6bb3ac0bd8e66a994d12593664. Independent design and complete source review:gpt-6.1-sol / xhigh. Remote CI for the updated head is pending.