Repository navigation
Cherry pick #117979 to 26.3: Check table access when the analyzer resolves a table identifier - #118058
Merged
Conversation
`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
Resolve the conflict in `04510_select_access_rights_rewrite.lib`: the file does not exist on 26.3 (its test was never backported), so the hunk from #117979 touching it is dropped. All other hunks of #117979 apply cleanly; the APIs used (`getAccessRightsWithImplicit`, `TableNode::getStorageSnapshot`, `Context::checkAccess` with `StorageID`) exist on 26.3. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job