Repository navigation
Check privileges of functions when they are built, not in their creators - #127443
Conversation
`FunctionFactory::get` / `tryGet` call the creator of a function also when the caller only reads the properties of the function, for example `isDeterministic`. The creators of `demangle`, `addressToSymbol`, `addressToLine`, `addressToLineWithInlines`, `file`, `getMacro`, `getServerSetting` and `getMergeTreeSetting` checked privileges, so such a lookup could throw `ACCESS_DENIED` / `FUNCTION_NOT_ALLOWED`. For example, a user with only `SELECT` could not read any column with `apply_mutations_on_fly = 1` if a pending mutation used `demangle`, because `AlterConversions` looks up the functions of the mutation. Add the virtual method `checkAccessOnBuild` to `IFunctionOverloadResolver` and `IFunction`. `IFunctionOverloadResolver::build` calls it first. Queries build every function they use, so they fail as before. The functions do not keep the context: `FunctionAccessCheck` keeps the `ContextAccess` of the user and the `QueryPrivilegesInfo` of the query. `ContextAccess` used the context only to record the checked privileges, so a new `checkAccess` overload takes `QueryPrivilegesInfo &`, and `QueryPrivilegesInfo` moves to its own header. Related: #126939 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [ec8513c] Summary: ✅
AI ReviewSummaryMoves function privilege checks from creation to Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes946 object files changed (+468.05 KiB total), 1 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units2150 translation units recompiled, 16928 s compile time in total, 2149 of them have a recent master baseline. |
…function `QueryAnalyzer` keeps one cache of built functions for the whole query, for non-deterministic functions that are stable in the query. On a cache hit, it reused the cached `FunctionBase` and did not call `build`, so it also did not call `checkAccessOnBuild`. The access rights depend on the settings of the scope, so `addressToSymbol`, `addressToLine` and `addressToLineWithInlines` ran in a subquery with `allow_introspection_functions = 0` if another subquery with `allow_introspection_functions = 1` built them first. Call `checkAccessOnBuild` of the resolver of the current scope on a cache hit. Related: #127443 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ons-check-access-in-build
…nBuild` `checkFunctionsAsUser` authorizes the functions of a text index `preprocessor` / `postprocessor` only by resolving their names with `FunctionFactory::tryGet`, because the creators of the functions checked privileges. This PR moved these checks from the creators to `checkAccessOnBuild`, so `CREATE TABLE` and `ALTER ADD INDEX` with `preprocessor = demangle(val)` passed with `allow_introspection_functions = 0`. Call `checkAccessOnBuild` of the resolved function. It does not need the arguments, so the expression is still not built. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127443&sha=5b8ffceb65efa3a7094d883a23c481712ca456af&name_0=PR PR: #127443 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Interpreters/Context.h
|
🕵 Merged |
…ess-in-build Conflicts: `[[nodiscard]]` from `master` (`modernize-use-nodiscard`) next to `checkAccessOnBuild` and `FunctionAccessCheck` in `FunctionFile.cpp`, `addressToSymbol.cpp`, `demangle.cpp`, `getMacro.cpp`, `getMergeTreeSetting.cpp` and `getServerSetting.cpp`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed parts Whether a column with a non-deterministic `DEFAULT` is read lazily is decided before the analysis of ranges, so the defaults of the columns missing in parts that the primary key leaves out are looked at as well. Since the privileges of functions are checked in `checkAccessOnBuild` and not in their creators, looking at a default with `FunctionFactory::tryGet` does not need them. Update the comments and add a test with a user that has only `SELECT`. Related: #126939 (comment) Related: #127443 Co-Authored-By: Claude Opus 5.5 <[email protected]>
FunctionFactory::get/tryGetcall the creator of a function also when the caller only reads the properties of the function, for exampleisDeterministic. The creators ofdemangle,addressToSymbol,addressToLine,addressToLineWithInlines,file,getMacro,getServerSettingandgetMergeTreeSettingchecked privileges, so such a lookup could throwACCESS_DENIED/FUNCTION_NOT_ALLOWED. For example, a user with onlySELECTcould not read any column withapply_mutations_on_fly = 1if a pending mutation useddemangle, becauseAlterConversionslooks up the functions of the mutation.Add the virtual method
checkAccessOnBuildtoIFunctionOverloadResolverandIFunction.IFunctionOverloadResolver::buildcalls it first. Queries build every function they use, so they fail as before.The functions do not keep the context:
FunctionAccessCheckkeeps theContextAccessof the user and theQueryPrivilegesInfoof the query.ContextAccessused the context only to record the checked privileges, so a newcheckAccessoverload takesQueryPrivilegesInfo &, andQueryPrivilegesInfomoves to its own header.Related: #126939
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Workflow [PR]
Sync PR [sync-upstream/pr/127443]
Version info
26.11.1.2746-master(included in26.11and later)