Skip to content

Cherry pick #117979 to 26.6: Check table access when the analyzer resolves a table identifier - #118059

Merged
robot-clickhouse-ci-1 merged 4 commits into
backport/26.6/117979from
cherrypick/26.6/117979
Sep 4, 2026
Merged

robot-clickhouse-ci-1 merged 4 commits into
backport/26.6/117979from
cherrypick/26.6/117979

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #117979

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 3 commits September 3, 2026 19:25
`EXPLAIN QUERY TREE` and `EXPLAIN SYNTAX` resolve the query and dump table
metadata (column names and types) without building a query plan, so the
`SELECT` access check the planner performs when the table is read was never
reached, and a user with no privileges could see the structure of any table.

Check access at the moment the analyzer obtains the table metadata, in
`IdentifierResolver::tryResolveTableIdentifierFromDatabaseCatalog`: the user
must be allowed to see at least one column of the table. Any grant on a column
implies `SHOW_COLUMNS` on it, so the check is weaker than every check the
planner performs later for the columns the query actually reads, and a query
that can be executed can always be analyzed. Table expressions constructed
programmatically (e.g. by `MutationsInterpreter`) do not pass through the
identifier resolution and keep their own access semantics.

A simpler reimplementation of #110180, as requested in
#110180 (comment)

Closes #78938

Co-Authored-By: Claude Fable 5 <[email protected]>
Probe the visibility of the table's columns on the raw access rights, so the
probing does not pollute `used_privileges` of the query log, and `SELECT` is
checked in addition to `SHOW_COLUMNS` because the implicit `SELECT` on the
`system` and `information_schema` databases is granted after implications are
derived. When not a single column is visible, report the denial through the
standard `Context::checkAccess`: the user gets the same sanitized message a
plain `SELECT` produces (`grant SELECT ON db.table`, no column names), and
`missing_privileges` of the query log is populated - without naming columns
the user may not see (they leaked there before).

Co-Authored-By: Claude Fable 5 <[email protected]>
Check table access when the analyzer resolves a table identifier
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-critical-bugfix labels Sep 4, 2026
Conflict resolution: `tests/queries/0_stateless/04510_select_access_rights_rewrite.lib` does not exist on 26.6 (the test it belongs to was never backported), so the PR's change to it is dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants