Skip to content

Fix wrong access type for SYSTEM PREWARM PRIMARY INDEX CACHE ON CLUSTER - #108963

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-prewarm-primary-index-cache-on-cluster-grant-108956
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-prewarm-primary-index-cache-on-cluster-grant-108956

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed SYSTEM PREWARM PRIMARY INDEX CACHE ON CLUSTER requiring the SYSTEM PREWARM MARK CACHE privilege instead of SYSTEM PREWARM PRIMARY INDEX CACHE. A user granted only SYSTEM PREWARM PRIMARY INDEX CACHE can now run the ON CLUSTER form, matching local execution.

Description

The PREWARM_PRIMARY_INDEX_CACHE case in getRequiredAccessForDDLOnCluster() was a copy of the PREWARM_MARK_CACHE case and was never updated to its own AccessType, so the ON CLUSTER access check diverged from the local-execution check in prewarmPrimaryIndexCache() (which correctly uses SYSTEM_PREWARM_PRIMARY_INDEX_CACHE). Reported in #108956 (found while documenting SYSTEM cache statements in #108546).

Reproduced locally in both directions (added stateless test 03801_prewarm_primary_index_cache_on_cluster_grant): with the buggy mapping a user holding only SYSTEM PREWARM PRIMARY INDEX CACHE is denied the ON CLUSTER form asking for SYSTEM PREWARM MARK CACHE; with the fix both the local and ON CLUSTER forms succeed.

The ON CLUSTER form of SYSTEM PREWARM PRIMARY INDEX CACHE required
SYSTEM PREWARM MARK CACHE instead of SYSTEM PREWARM PRIMARY INDEX CACHE.
The PREWARM_PRIMARY_INDEX_CACHE case in getRequiredAccessForDDLOnCluster()
was a copy of the PREWARM_MARK_CACHE case and was never updated to its own
AccessType, so it diverged from the local-execution check in
prewarmPrimaryIndexCache(). A user granted only SYSTEM PREWARM PRIMARY INDEX
CACHE could run the command locally but was denied the ON CLUSTER form.

Closes: ClickHouse#108956

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With ONLY GRANT CLUSTER, SYSTEM PREWARM PRIMARY INDEX CACHE ON *.*, SYSTEM PREWARM PRIMARY INDEX CACHE ON CLUSTER test_shard_localhost db.t is denied 100% of the time, asking for SYSTEM PREWARM MARK CACHE.
b Root cause explained? The Type::PREWARM_PRIMARY_INDEX_CACHE case in getRequiredAccessForDDLOnCluster() was copy-pasted from the PREWARM_MARK_CACHE case directly above it and never updated, so it pushed SYSTEM_PREWARM_MARK_CACHE into required_access. The ON CLUSTER access check (executeDDLQueryOnCluster → checkAccess(access_to_check)) then required the wrong grant, diverging from the local-execution check prewarmPrimaryIndexCache() which correctly uses SYSTEM_PREWARM_PRIMARY_INDEX_CACHE.
c Fix matches root cause? Yes. The DDL access element is changed from SYSTEM_PREWARM_MARK_CACHE to SYSTEM_PREWARM_PRIMARY_INDEX_CACHE, directly aligning the cluster path with the local path. No symptom-masking.
d Test intent preserved / new tests added? New stateless test 03801_prewarm_primary_index_cache_on_cluster_grant added: a user with only SYSTEM PREWARM PRIMARY INDEX CACHE can run both the local and ON CLUSTER forms, and a user without it is denied with an error naming the correct grant.
e Both directions demonstrated? Yes. On the buggy binary the test FAILS (on cluster → ACCESS_DENIED; negative control names MARK CACHE); on the fixed binary it PASSES (3/3 runs).
f Fix is general across code paths? Audited every case in getRequiredAccessForDDLOnCluster() against its local-path checkAccess. PREWARM_PRIMARY_INDEX_CACHE was the only clear copy-paste mismatch of a distinct dedicated grant. Two other cases (STOP/START_CLEANUP, STOP/START_VIRTUAL_PARTS_UPDATE) use SYSTEM_PULLING_REPLICATION_LOG while dedicated grants SYSTEM_CLEANUP / SYSTEM_VIRTUAL_PARTS_UPDATE exist — these are ambiguous (possibly intentional) and a backward-incompatible change, so they are surfaced to maintainers separately rather than changed here.
g Fix generalizes across inputs? N/A — this is an access-type mapping, not data-dependent. The grant is GLOBAL (ON *.*); table/db arguments are passed through unchanged and behave identically for the local and cluster paths.
h Backward compatible? Behavior change is the intended fix: the ON CLUSTER form now requires the same grant as local execution (SYSTEM PREWARM PRIMARY INDEX CACHE) instead of SYSTEM PREWARM MARK CACHE. Both grants share the SYSTEM DROP CACHE parent, so users holding the SYSTEM DROP CACHE/SYSTEM umbrella are unaffected. No setting/format change → no SettingsChangesHistory.cpp entry needed.
i Invariants and contracts preserved? Yes. The invariant being restored is "ON CLUSTER access requirement == local access requirement" for this command. required_access semantics, the GLOBAL scope of the grant, and the surrounding switch are unchanged.

Session id: cron:clickhouse-worker-slot-7:20260630-160000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @vitlibar @pufit — could you review? One-line RBAC fix: the ON CLUSTER form of SYSTEM PREWARM PRIMARY INDEX CACHE required SYSTEM PREWARM MARK CACHE (copy-paste in getRequiredAccessForDDLOnCluster()); now it requires SYSTEM PREWARM PRIMARY INDEX CACHE, matching local execution. Includes a regression test.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bfb5d7c]

Summary: ❌

job_name test_name status info comment
Fast test (arm_darwin) FAIL
03988_keeper_client_autocomplete FAIL cidb
AST fuzzer (amd_msan) FAIL
Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-2cc2) FAIL cidb, issue

AI Review

Summary

This PR fixes the SYSTEM PREWARM PRIMARY INDEX CACHE ON CLUSTER access check to require SYSTEM PREWARM PRIMARY INDEX CACHE instead of SYSTEM PREWARM MARK CACHE, matching the local execution path. The regression test now checks zero exit for both positive commands and verifies the denied case reports the primary-index privilege, so I did not find a current code issue.

Missing context / blind spots
  • ⚠️ I could not run the stateless test locally because this checkout has no build* directory or installed clickhouse / clickhouse-client binary. The CI report helper returned no failed checks for the available report; a completed stateless run would close local execution validation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 30, 2026
The positive assertions grepped stderr for ACCESS_DENIED and printed ok on a
grep non-match, so any other failure (CLUSTER_DOESNT_EXIST, UNKNOWN_TABLE,
Primary index cache is not configured) would also produce ok without the
granted user actually executing the command. Assert zero exit for the local
and ON CLUSTER forms; keep the error-text grep on the negative path only.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.50% +0.10%
Functions 92.60% 92.70% +0.10%
Branches 77.70% 77.70% +0.00%

Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — bfb5d7c

Every failure below has an owner (a fixing PR). This PR's diff is a 1-line RBAC access-type change (getRequiredAccessForDDLOnCluster) plus its stateless RBAC test, so it cannot cause an arm_darwin keeper-client socket error or an amd_msan set-operation fuzzer logical error. PR-caused gate: zero.

Check / test Reason Owner / fixing PR
Fast test (arm_darwin) / 03988_keeper_client_autocomplete flaky: benign ENOTCONN "Socket is not connected" on keeper-client ZooKeeper finalize written to stderr (chronic, 12 unrelated PRs/30d, arm_darwin only; unrelated to this RBAC diff). report #107438 (ours, open)
AST fuzzer (amd_msan) / Block structure mismatch in IntersectOrExceptStep (STID 0993-2cc2) LOGICAL_ERROR (exception; aborts only in msan/debug): chronic trunk AST-fuzzer finding on INTERSECT/EXCEPT when a branch constant-folds; 30+ hits across unrelated PRs + 4 on master; unrelated to this RBAC diff. report #107719 (ours, open)
Mergeable Check / PR derivative aggregators fail only due to the two rows above
CH Inc sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260701-013000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Superseded by #110289, which fixes all required permission mismatches per @azat. The PRIMARY INDEX CACHE fix already landed via 2c0a4c0.

@groeneai groeneai closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants