Skip to content

Allow EXISTS on a dictionary with the SHOW DICTIONARIES privilege - #108084

Merged
alexey-milovidov merged 6 commits into
masterfrom
fix-exists-dictionary-show-priv
Jul 1, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
fix-exists-dictionary-show-priv

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

A dictionary created by a DDL query is registered among tables, so a plain EXISTS <name> query checks the SHOW TABLES privilege. As a result, a user granted only SHOW DICTIONARIES on a dictionary could not run EXISTS <dictionary>, even though SHOW DICTIONARIES, SHOW CREATE DICTIONARY, and EXISTS DICTIONARY <dictionary> all worked. This contradicted the documentation, which states that SHOW DICTIONARIES is enough for EXISTS <dictionary>.

This PR allows a plain EXISTS <name> referring to a dictionary when the user has SHOW DICTIONARIES on it. The change is guarded so it does not widen visibility for regular tables and does not leak whether an object is a dictionary: a user with neither SHOW TABLES nor SHOW DICTIONARIES still gets the same SHOW TABLES access error as for a regular or non-existing table.

The broader part of the linked issue — a database- or object-scoped SHOW DICTIONARIES grant not revealing dictionaries in system.dictionaries / SHOW DICTIONARIES — was already fixed by #106105. This PR resolves the remaining EXISTS <dictionary> discrepancy.

Closes: #64364
Related: #106105

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):

Allow EXISTS <dictionary> for a user that has only the SHOW DICTIONARIES privilege on the dictionary (previously it required SHOW TABLES).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

A dictionary created by a DDL query is registered among tables, so the
plain `EXISTS <name>` query (`ASTExistsTableQuery`) checked the
`SHOW TABLES` privilege. As a result a user that was granted only
`SHOW DICTIONARIES` on a dictionary could not run `EXISTS <dictionary>`,
even though `SHOW DICTIONARIES`, `SHOW CREATE DICTIONARY` and
`EXISTS DICTIONARY <dictionary>` all worked. This contradicted the
documentation, which states that `SHOW DICTIONARIES` is enough for
`EXISTS <dictionary>`.

Now a plain `EXISTS <name>` referring to a dictionary is allowed when
the user has `SHOW DICTIONARIES` on it. The change is guarded so it does
not widen visibility for regular tables and does not leak whether an
object is a dictionary: a user with neither `SHOW TABLES` nor
`SHOW DICTIONARIES` still gets the same `SHOW TABLES` access error as for
a regular or non-existing table.

Closes: #64364

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [012a29b]

Summary: ✅


AI Review

Summary

This PR fixes the EXISTS <dictionary> access path so a user with SHOW DICTIONARIES can observe a DDL dictionary without requiring SHOW TABLES, while preserving the SHOW TABLES path for regular tables. The previously raised race around a second isTableExist lookup is fixed in the current code by returning from the same isDictionaryExist observation, and the added stateless test covers the intended positive and no-access behavior.

Final Verdict

Status: ✅ Approve

alexey-milovidov and others added 4 commits June 23, 2026 21:27
…observation

A plain `EXISTS <name>` for a dictionary previously decided the
`SHOW DICTIONARIES`-only access path from `isDictionaryExist`, but then
reported existence from a second `isTableExist` lookup. If the dictionary
were concurrently dropped and a regular table created under the same name
between the two lookups, a user with only `SHOW DICTIONARIES` could get
`1` for the regular table without a `SHOW TABLES` check, widening
visibility for regular tables.

Bind the privilege decision to the same observation: when the dictionary
path is allowed, report existence directly from that observation
(`result = true`), matching `EXISTS DICTIONARY <name>` (which returns
`isDictionaryExist`); otherwise keep the `SHOW TABLES` check followed by
`isTableExist`. This is behaviour-identical in the non-racy case because a
registered DDL dictionary that satisfies `isDictionaryExist` also
satisfies `isTableExist`.

Reported by the AI review on the pull request.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Status (continue-pr review of 65fd7fda) — ready to merge.

  • All required checks are green (150 ✅ / 18 skipped): Fast test, every Build, Stateless/Integration/Unit, AST fuzzer, all flaky checks, and LLVM coverage (11/11 changed lines covered, 100%).
  • CH Inc sync: success, Mergeable Check: success, mergeable: true (state unstable only because of the non-required stress jobs below).
  • 0 unresolved review threads, AI Review: ✅ Approve.

The only red jobs are Stress test (amd_tsan) and Stress test (arm_tsan) — both Hung check failed, possible deadlock found. Their stacks are pure AST-fuzzer / QueryAnalyzer deadlock traces (resolveExpressionNodeList → resolveQuery → QueryAnalysisPass → executeASTFuzzerQueries) with no frames from InterpreterExistsQuery, ContextAccess, or any privilege code this PR touches. This is the chronic master-wide flake tracked in #107941 (CI auto-links both failures to it), not caused by this change.

The branch tip is a fresh master merge (merge-base from earlier today), so no re-merge is needed — the flake fires on master and a merge would not change it.

No code or test changes required.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Status (continue-pr, round 5 on 012a29b0) — re-merged master for a fresh CI run.

The change itself is unchanged and ready: AI Review ✅ Approve, 0 unresolved review threads, CH Inc sync SUCCESS, Mergeable Check SUCCESS, coverage 11/11 = 100%, and all required checks were green on the previous head 65fd7fda.

The only reds were Stress test (amd_tsan) and Stress test (arm_tsan), both Hung check failed, possible deadlock found. Their stacks are pure AST-fuzzer / QueryAnalyzer (executeASTFuzzerQueries → buildQueryTreeAndRunPasses → QueryTreePassManager::run), with zero frames from this PR — this is the chronic deadlock-detector flake tracked in #107941 (CI auto-links it). A 25-line privilege check in InterpreterExistsQuery.cpp cannot cause it.

A re-run of those two jobs on 65fd7fda failed a second time (the flake is persistent), and the branch had fallen 517 commits behind master, so rather than re-running the same SHA again I merged current master (clean — master never touched InterpreterExistsQuery.cpp) to get a fresh full CI run on 012a29b0, including a fresh roll of the stress jobs. PR diff is identical (3 files, +82/-2).

Ready to merge once the fresh CI run is green.

pull Bot pushed a commit to sowelswl/ClickHouse that referenced this pull request Jun 30, 2026
`test_implicit_index_upgrade_alter_replay` creates a second replica `node2`
and asserts `SELECT count() FROM test_alter_replay` equals `10001` immediately
after `wait_for_active_replica`. But `wait_for_active_replica` only waits for
`is_readonly = 0`, not for the freshly-joined replica to finish fetching parts.

So `node2` can observe only the small `VALUES` part (1 row, `key = 99999`)
before the 10000-row part is fetched, and the assertion fails with
`assert '1' == '10001'`. This raced once each on several unrelated PRs over
the last 30 days (e.g. ClickHouse#108084, ClickHouse#99280, ClickHouse#107566, ClickHouse#107442).

Add `SYSTEM SYNC REPLICA test_alter_replay` after the replica becomes active,
which blocks until all parts are fetched, before checking the row count.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108770&sha=bb760616d54e3d8e5d20968022085506c31b5f37&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%201%2F4%29

Co-Authored-By: Claude Opus 4.8 (1M context) <[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: 11/11 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@alexey-milovidov alexey-milovidov self-assigned this Jul 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 1, 2026
Merged via the queue into master with commit 7f0cfce Jul 1, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-exists-dictionary-show-priv branch July 1, 2026 08:01
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 1, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`test_implicit_index_upgrade_alter_replay` creates a second replica `node2`
and asserts `SELECT count() FROM test_alter_replay` equals `10001` immediately
after `wait_for_active_replica`. But `wait_for_active_replica` only waits for
`is_readonly = 0`, not for the freshly-joined replica to finish fetching parts.

So `node2` can observe only the small `VALUES` part (1 row, `key = 99999`)
before the 10000-row part is fetched, and the assertion fails with
`assert '1' == '10001'`. This raced once each on several unrelated PRs over
the last 30 days (e.g. ClickHouse#108084, ClickHouse#99280, ClickHouse#107566, ClickHouse#107442).

Add `SYSTEM SYNC REPLICA test_alter_replay` after the replica becomes active,
which blocks until all parts are fetched, before checking the row count.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108770&sha=bb760616d54e3d8e5d20968022085506c31b5f37&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%201%2F4%29

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…onary-show-priv

Allow `EXISTS` on a dictionary with the `SHOW DICTIONARIES` privilege
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SHOW DICTIONARIES privilege does not work as expected

2 participants