Repository navigation
Conversation
|
Workflow [PR], commit [4c40b2a] Summary: ❌
AI ReviewSummaryThis PR adds Findings
Final Verdict
|
ea9e2d4 to
bca687e
Compare
|
This PR is ready for review, could you please help? Thanks. |
|
The |
… query logs safely.
Introduce a security barrier mode that prevents view inlining and outer filter pushdown, and exposes barrier view columns without wrappers. Use it so user-supplied predicates cannot evaluate against filtered-out values.
Expose `attachSystemUserQueryLog` so `clickhouse-local` can create `system.user_query_log` after `initializeSystemLogs` creates `system.query_log`.
Add the required `current_database = currentDatabase()` predicate to `system.query_log` and `system.user_query_log` queries in the stateless test, so the query log style check accepts the test and concurrent test logs are ignored. Issue: ClickHouse#82539
…g is configured in a non system database.
01c8e4d to
a6045a2
Compare
|
@alexey-milovidov Thanks for the guidance. I've updated the branch with the latest master. |
460b718 to
ffd3010
Compare
|
Pushed a follow-up (0dd9b82) addressing the AI Review verdict. Major — Instead of rejecting the whole query, I now strip The regression test Nit — stale doc. Updated the The only red CI check, |
The test starts its own `clickhouse server` to exercise `system.user_query_log`
over a `Null`-engine query log. It derived five listen ports (TCP, HTTP, MySQL,
PostgreSQL, interserver) from `$$ % 20000`, i.e. the range 20000..40000, which
overlaps the Linux ephemeral port range. In the highly parallel stateless test
run another server (or an ephemeral socket) could already hold one of them, so
the server aborted on startup with `Address already in use` and the readiness
loop timed out. CI observed this on the unused `postgresql_port`, and the
randomized-settings diagnosis reran the test 44 times without a single failure,
confirming a transient port clash rather than a real regression.
Fix: the test only connects over the native TCP protocol, so configure just
`tcp_port` (dropping the four unused ports), obtain it from the OS with a
`bind(('127.0.0.1', 0))` probe instead of the PID, and wrap startup in a small
retry loop that picks a fresh port if the server still races another process
for the port and exits before becoming ready.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed Flaky Fix: the test only connects over native TCP, so it now configures just Unrelated CI failure — AST fuzzer @groeneai, please investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104462&sha=0dd9b82adc98005d1c9b47e1c0836e336256cf68&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 and provide a fix in a separate PR. If a fix or tracking issue already exists, please link it here. |
|
Thanks. This is the known chronic trunk bug, STID 2508-2ef2 ( Root cause: a backquoted identifier that contains or ends in a dot (e.g. Existing fix: #108735 ("Fix logical error when a lambda argument is a backquoted dotted identifier"), approved by @vdimir, open and awaiting merge. It fixes the lambda-argument path in Caveat, and why #108735 alone likely does not close this instance: your failing query does not use a dotted lambda argument. The empty-part identifier here is a qualified-asterisk qualifier / compound backtick identifier inside Plan: once #108735 is on master (or applied to a local debug build) I will re-run your exact |
Explain that an existing object using the newly reserved name must be renamed or dropped before upgrading, and document the related `query_log` configuration change.
|
Dear @jkartseva, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
|
||
| ## Columns {#columns} | ||
|
|
||
| The columns match the configured query log table, which uses the same structure as [`system.query_log`](query_log.md), except `LowCardinality` wrappers are removed from exposed column types. |
There was a problem hiding this comment.
except
LowCardinalitywrappers are removed from exposed column types.
Why?
There was a problem hiding this comment.
The wrapper removal is what keeps the barrier view from exposing the underlying LowCardinality encoding to outer expressions. Without materializing to the dictionary type, the visible schema can still carry storage-level dictionary state from rows the barrier filtered out, which breaks the point of treating the view output as an already-sanitized row set.
| "functions", /// Can contain user-defined functions | ||
|
|
||
| /// View over `system.query_log` filtered by the current user. | ||
| "user_query_log", |
There was a problem hiding this comment.
Why don't we require an explicit grant?
So the user will need a grant to the user_query_log view, but not to the query_log.
At least an explicit grant will allow us not to give access to this table, as the queries can be resource-intensive.
Also, why do we use SQL_SECURITY NONE instead of DEFINER? As the view is created by the server, it should be equivalent, shouldn't it?
There was a problem hiding this comment.
The current implementation follows the feature contract this PR documents: ordinary users can inspect their own rows without needing either direct access to system.query_log or a separate rollout of grants on the filtered view. If the product decision is that access should be opt-in instead, that is a compatible policy change, but it is separate from the barrier-isolation mechanism itself.
| bool supportsTruncate() const override { return false; } | ||
| bool isParameterizedView() const { return is_parameterized_view; } | ||
| bool isSecurityBarrier() const { return security_barrier; } | ||
| bool allowsViewInlining() const { return !security_barrier; } |
There was a problem hiding this comment.
allowsViewInlining is the guard that keeps both analyzers from rewriting a barrier view back into a transparent subquery. Once the view is inlined, outer predicates and setting-derived filters can be planned directly against the inner source, which is exactly the leak this flag is preventing.
|
|
||
| protected: | ||
| bool is_parameterized_view; | ||
| bool security_barrier; |
There was a problem hiding this comment.
Why do we have all those complications?
There was a problem hiding this comment.
The extra state is there because a barrier view has to diverge from an ordinary StorageView in several later code paths: it must not be inlined, it must strip inner additional_table_filters, and it must reject additional_result_filter. After the AST is parsed those call sites only see a StorageView, so they need a persistent flag to choose the fail-closed path.
| const size_t /*max_block_size*/, | ||
| const size_t /*num_streams*/) | ||
| { | ||
| if (security_barrier) |
There was a problem hiding this comment.
additional_result_filter is query-wide rather than table-scoped, so there is no safe way to keep only the dangerous part out of the barrier. Unlike additional_table_filters, it cannot be neutralized per inner source table, so the fail-closed behavior here is to reject it when a security-barrier view participates in the query.
| /// predicate. Strip the setting from the inner query context so it can never be applied there, | ||
| /// while filters targeting unrelated tables in the outer query keep working - those are applied | ||
| /// in the outer context, which is left untouched. | ||
| if (view->isSecurityBarrier()) |
There was a problem hiding this comment.
I'm sure we should approach it differently.
For example, all SQL SECURITY (other than INVOKER) views can't use additional_table_filters.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 226/257 (87.94%) · Uncovered code |
`SystemLog` creates its backing table lazily, on the first flush, but the
`system.user_query_log` view is exposed as soon as it is attached at startup.
On a freshly started server the very first read from the view therefore failed
with `UNKNOWN_TABLE`, because the inner `SELECT` targets a table that does not
exist yet:
Code: 60. DB::Exception: Unknown table expression identifier 'system.query_log'
in scope SELECT * FROM system.query_log WHERE if(initial_user != '', initial_user, user) = currentUser().
Prepare the configured query log table in `attachSystemUserQueryLog` right
before attaching the view, so that the view is readable (and empty) from the
moment it appears. A system log does not create its own database, so this is
only done when the configured database has already been loaded - which is
always the case for the default `system` database, as it is loaded before
system tables are attached.
Also refresh the stale `enable_user_query_log` comment in the shipped
`config.xml`: the view reads the configured query log table, which is not
necessarily `system.query_log`, and it filters by the initiating user.
Addresses the AI review findings on
ClickHouse#104462
|
Merged current `master` and addressed the AI review findings (commit 4c40b2a):
The 7 open threads from @alexey-milovidov (explicit grant vs. implicit access, |
|
|
||
| ## Description {#description} | ||
|
|
||
| The `system.user_query_log` table is a view over the query log table configured by the `query_log.database` and `query_log.table` server configuration parameters. By default, this is `system.query_log`. The view returns only rows where the initiating user is equal to the result of `currentUser()`. For distributed query log rows, the initiating user is stored in `initial_user`; otherwise, `user` is used. |
There was a problem hiding this comment.
query_log.database is still not honored here. createSystemLog rewrites any non-system database back to system in src/Interpreters/SystemLog.cpp:150-163, so this wording currently promises behavior the server does not implement: a user can set query_log.database = my_logs, read this page, and expect system.user_query_log to read my_logs.<table>, but the runtime still uses system.<table>.
Either lift that SystemLog restriction in the same PR, or narrow the docs/comments to say that the view follows the configured query_log.table in the system database.
|
🕵 Closing this PR: the feature has been merged into master via #110156, a simplified reimplementation ( The idea and the original implementation belong to @niyue, as credited in the changelog entry of #110156 — the integration test for the distributed Related: #110156 |
Changelog category (leave one):
Changelog entry:
system.user_query_logsystem table that allows users to read only their own query log records without direct access tosystem.query_log.Documentation entry for user-facing changes
This PR will address #82539