Repository navigation
Require the local privilege for KILL and SYSTEM statements over ON CLUSTER - #118360
Algunenano merged 4 commits into
Conversation
…USTER Five statements required no privilege at all when spelled ON CLUSTER, while their local spellings refused the same user: KILL TRANSACTION KILL PART_MOVE_TO_SHARD SYSTEM STOP THREAD FUZZER SYSTEM START THREAD FUZZER SYSTEM RESET COVERAGE For an ON CLUSTER statement, getRequiredAccessForDDLOnCluster is the only authorization boundary: executeDDLQueryOnCluster runs context->checkAccess(access_to_check), which is a no-op on an empty list, and the worker that then runs the statement on each host re-executes with no user unless the server setting distributed_ddl_use_initial_user_and_roles is on, which defaults to false. So a holder of CLUSTER alone could roll back other users' transactions cluster-wide, cancel part moves between shards, and flip the thread fuzzer and the coverage counters on every node. Two chains left the list empty for a reachable statement. The KILL chain was an if/else if with no terminal else covering 2 of the 4 ASTKillQueryQuery::Type enumerators, while ParserKillQueryQuery parses the ON CLUSTER clause uniformly for all four. In InterpreterSystemQuery a grouped arm opted eight types into an empty break, and three of them are reachable because they have no explicit parser case and so fall into a default: arm that calls parseQueryWithOnCluster. The recurring cause is that the parser makes ON CLUSTER the default for a SYSTEM type with no explicit case while the authorization mapper's default is an empty list. Each statement now requires exactly what its own local path checks, in the order the local path checks it, so the message an ON CLUSTER refusal prints is the one the local spelling prints. The KILL chain became a switch with no default:, so a future enumerator is a compile error at the mapping site rather than a silent bypass. KILL PART_MOVE_TO_SHARD is the one place where the initiator cannot reproduce the local check exactly: the local path checks ALTER MOVE PARTITION and MOVE PARTITION BETWEEN SHARDS per matched row, and the WHERE clause is arbitrary, so the initiator cannot know the target tables and requires both flags globally instead. That is stronger in scope than the local check, never weaker, and it is the shape the neighbouring Type::Mutation arm has always used. The failpoint statements and SYSTEM SET COVERAGE TEST stay on the empty arm: their parser cases never read an ON CLUSTER clause, so those cluster spellings do not parse.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus my own cold pass on the
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260906-003300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260905-224400 |
|
Workflow [PR], commit [6e89d67] Summary: ✅
AI ReviewSummaryThis PR closes the empty Findings
Final VerdictStatus:
LLVM Coverage ReportMeasured on commit 6e89d67.
Changed lines: Changed C/C++ lines covered: 22/40 (55.00%) · Uncovered code |
|
cc @pufit @tavplubix, could you review this? Five |
Build profile diff (arm_release)Commit See the job log for details. |
`KILL TRANSACTION ... WHERE tid = (1, 1, '000...')` only has to match no live transaction; comparing `tid` was an incidental way to spell that. The tuple has four elements in the ClickHouse Inc. build and three here, so the comparison fails type analysis there before the access check the test is about is even reached, and `CH Inc sync` reported: ``` Code: 43. DB::Exception: Illegal types of arguments (`Tuple(UInt64, UInt64, UUID, Int64)`, `Tuple(UInt8, UInt8, String)`) of function `equals` ``` Match on `tid_hash` instead, which is a `UInt64` in both and is never 0 for a live transaction, so every allowed arm stays the no-op it was. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: Release-transition baseline: compared against the most recent available 26.9 masters at or before the trusted base-commit anchor because no 26.10 master baseline exists there. no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
CI finish ledger - a3be654Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260910-050126 |
|
@groeneai please merge master into this PR |
…-system-required-access
|
Merged master into the branch, head is now |
| # Match no live transaction and no live part move, so every allowed arm below is a no-op. The | ||
| # transaction predicate deliberately does not compare `tid`: its tuple shape is not the same in | ||
| # every build, so a literal tuple fails type analysis before the access check this test is about. | ||
| txn_predicate="tid_hash = 0" |
There was a problem hiding this comment.
This test now relies on tid_hash = 0 being impossible for a live transaction, but the code does not guarantee that. TransactionID::getHash is just SipHash64 over (start_csn, local_tid, host_id) (src/Common/TransactionID.cpp:9-15), and TransactionLog::beginTransaction accepts whatever 64-bit value it gets as the running_list key (src/Interpreters/TransactionLog.cpp:405-408). Zero is a legal hash value, so this "no-op" predicate can still hit a real transaction and roll it back on a busy shared server.
Please use a deterministic impossible predicate from the actual column domain instead, e.g. is_readonly = 2.
There was a problem hiding this comment.
Both halves of this check out. TransactionID::getHash is a SipHash64 over (start_csn, local_tid, host_id) (src/Common/TransactionID.cpp:9-15), so 0 is inside the domain, and is_readonly genuinely cannot be matched at 2: it is UInt8 filled from MergeTreeTransaction::isReadOnly (src/Storages/System/StorageSystemTransactions.cpp:34,49). A live row, measured: tid_hash = 8737450004602111196, is_readonly = 1. The swap is also oracle-preserving, which I checked rather than assumed: for a user holding the full privilege set, tid_hash = 0 and is_readonly = 2 both return empty output locally and over ON CLUSTER.
I am still not making the edit, for a reason that outweighs it. That line is a3be65474ad2, "Do not compare tid to a literal tuple in 05082", written by a maintainer so the predicate stays type-checkable in a tree where the tid tuple has a different arity, and it is green there. I cannot read that tree, so I cannot show that a different column survives it, and re-breaking the check that commit exists to fix costs more than what the change removes: system.transactions is empty unless a transaction is open in another session, and the collision is one SipHash64 value out of 2^64.
If a maintainer prefers the deterministic predicate, it is a one-token change and I will push it on request.
CI finish ledger - de9a6e8Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260917-030022 |
|
@groeneai merge master and resolve conflicts. |
…-system-required-access # Conflicts: # src/Interpreters/InterpreterSystemQuery.cpp
|
Merged master, no rebase and no force-push. New head One conflict, in Nothing of this PR's own diff changed. In the two touched files the only delta against the previously validated head is master's |
Cherry pick #118360 to 26.3: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
…STEM statements over ON CLUSTER
Cherry pick #118360 to 26.7: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
…STEM statements over ON CLUSTER
Cherry pick #118360 to 26.8: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
…STEM statements over ON CLUSTER
Cherry pick #118360 to 26.9: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
…STEM statements over ON CLUSTER
Backport #118360 to 26.9: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
Backport #118360 to 26.8: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
Backport #118360 to 26.7: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
Backport #118360 to 26.3: Require the local privilege for KILL and SYSTEM statements over ON CLUSTER
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
KILL TRANSACTION ... ON CLUSTER,KILL PART_MOVE_TO_SHARD ... ON CLUSTER,SYSTEM STOP THREAD FUZZER ON CLUSTER,SYSTEM START THREAD FUZZER ON CLUSTERandSYSTEM RESET COVERAGE ON CLUSTERran without checking any privilege, so a user holding onlyCLUSTERcould roll back other users' transactions, cancel part moves between shards, and flip the thread fuzzer and the coverage counters on every host. Each now requires what its non-ON CLUSTERspelling has always required:KILL TRANSACTIONandSELECTonsystem.transactions;SELECTonsystem.part_moves_between_shards,ALTER MOVE PARTITIONandMOVE PARTITION BETWEEN SHARDS;SYSTEM THREAD FUZZER; andSYSTEM.Description
Related: #118155
The five statements #118155 named as skipping the same check.
getRequiredAccessForDDLOnClusteris the only authorization boundary here:executeDDLQueryOnClustercallscheckAccess(access_to_check), a no-op on an empty list, and the worker then runs on each host with no user unlessdistributed_ddl_use_initial_user_and_rolesis on (default off).InterpreterKillQueryQuery's chain covered 2 of the 4ASTKillQueryQuery::Typeenumerators with no terminalelse, whileParserKillQueryQueryparses the clause for all four. InInterpreterSystemQuerya grouped arm gave eight types an empty list, three reachable through the parser'sdefault:arm.Each statement now requires exactly the privileges its own local path checks, so an
ON CLUSTERrefusal prints the message the local spelling prints. TheKILLchain became aswitchwith nodefault:, so a future enumerator is a compile error at the mapping site.SYSTEM RESET COVERAGErequires theSYSTEMgroup because its local path requires that same group, the opposite of the #114011 defect.A query that succeeds today starts failing, and that is the fix: the local spelling has always refused the same user.
Residuals left open. The initiator cannot evaluate what a host will need, so each privilege is required in its coarsest sufficient form: the move flags globally where the local path checks them per matched row, and table-wide
SELECTwhere it reads named columns. Stronger than local (no matched row,TEST, column-scoped grants), never weaker. The pre-existingQueryandMutationarms still omit their own system-tableSELECT(Queryis #117999, which removes that requirement). An arbitraryWHEREis still evaluated on each host by the no-user worker, which this narrows rather than closes; converging needs the worker to run as the initiator.Workflow [PR]
Sync PR [sync-upstream/pr/118360]
Version info
26.10.1.610-master(included in26.10and later)26.9.2.31,26.8.11.37,26.7.14.43,26.3.33.155