Skip to content

Check privileges of functions when they are built, not in their creators - #127443

Merged
KochetovNicolai merged 7 commits into
masterfrom
functions-check-access-in-build
Nov 18, 2026
Merged

KochetovNicolai merged 7 commits into
masterfrom
functions-check-access-in-build

Conversation

@KochetovNicolai

@KochetovNicolai KochetovNicolai commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

  • Merged into: 26.11.1.2746-master (included in 26.11 and later)

`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]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ec8513c]

Summary: ✅


AI Review

Summary

Moves function privilege checks from creation to IFunctionOverloadResolver::build, preserving enforcement for cached functions and text-index transforms while allowing property-only lookups. Reviewed the current diff and prior discussion at ec8513cfe59d2bad866564ff68c0d182234b70d3. The earlier cache-bypass finding is fixed; no remaining actionable findings.

Missing context / blind spots
  • ⚠️ Local runtime verification was unavailable because the checkout has no ClickHouse binary or build directory. Regression coverage is present in 05443_function_privileges_checked_on_build and existing text-index access tests, but the fetched CI reports did not expose results for the new test. Its functional CI result would close this execution gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 22, 2026
Comment thread src/Functions/IFunction.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Oct 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ec8513cfe with master 2a4942ac1 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

946 object files changed (+468.05 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Access/ContextAccess.cpp.o 1.10 MiB 1.13 MiB +35.86 KiB (+3.19%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

2150 translation units recompiled, 16928 s compile time in total, 2149 of them have a recent master baseline.

Job report

KochetovNicolai and others added 2 commits October 30, 2026 13:26
…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]>
@pufit pufit self-assigned this Nov 3, 2026

@pufit pufit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@KochetovNicolai
KochetovNicolai added this pull request to the merge queue Nov 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 12, 2026
KochetovNicolai and others added 3 commits November 12, 2026 18:03
…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
@nickitat

Copy link
Copy Markdown
Member

🕵 Merged master into this branch and resolved the conflicts caused by #129617 (the switch to the -WithMemoryTracking containers). This update was made automatically.

…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]>

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@KochetovNicolai
KochetovNicolai added this pull request to the merge queue Nov 18, 2026
Merged via the queue into master with commit 43415f1 Nov 18, 2026
193 checks passed
@KochetovNicolai
KochetovNicolai deleted the functions-check-access-in-build branch November 18, 2026 17:12
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 18, 2026
KochetovNicolai added a commit that referenced this pull request Nov 19, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-not-for-changelog This PR should not be mentioned in the changelog 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.

4 participants