Repository navigation
Store all asked privileges for better RBAC auditing - #104693
Conversation
|
Workflow [PR], commit [4964544] Summary: ❌
AI ReviewSummaryThis PR updates Findings❌ Blockers
Tests
Final VerdictStatus:
|
| { | ||
| /// Record every granted access, regardless of whether the caller is the throwing entry point | ||
| /// (`checkAccess` / `checkGrantOption`) or the non-throwing one (`isGranted`, used internally by | ||
| /// `checkAccessWithFilter`). Without this, an `isGranted`-driven success leaves no trace in |
There was a problem hiding this comment.
The new logic/comments here state that every granted access is now recorded, but checkAccessWithFilter still has a second successful path (filter match) that returns without calling Context::addQueryPrivilegesInfo.
Concrete case: GRANT READ ON S3('s3://foo.*') can authorize s3://foo/bar.csv via the filter branch, yet system.query_log.used_privileges still misses READ ON S3 for that query.
Could we also record before the filter-branch return (for example with AccessRightsElement{flags, parameter}.toStringWithoutOptions()) so filtered grants are audited too?
The QueryPrivilegesInfoUpdates and QueryPrivilegesInfoUpdatesLegacy counters were added only to measure the perf impact of always recording granted accesses in `addQueryPrivilegesInfo` (see PR #104693 discussion). The numbers came back well within noise (~2x more recordings, ~1 extra `unordered_set` insert per query on average, no planner-loop pathology), so the counters are no longer needed and are removed here. The functional change (dropping the `if constexpr (throw_if_denied)` gate on the granted-side write) is kept. Co-Authored-By: Claude Opus 4.7 <[email protected]>
PR #80785 added a second app under /pg_testapp to the `clickhouse/mysql_dotnet_client` image, making /pg_testapp the last WORKDIR. `dotnet run` (no project arg) then launched the Npgsql client against the MySQL port, producing "Received unknown response X for SSLRequest (expecting S or N)". The PR was reverted (#105615) but the cached `:latest` image on integration runners still has /pg_testapp as the last WORKDIR. Anchor the command to /testapp so the test passes regardless of the image's working directory, matching what test_dotnet_client in test_postgresql_protocol/test.py already does. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| /// (`checkAccess` / `checkGrantOption`) or the non-throwing one (`isGranted`, used internally by | ||
| /// `checkAccessWithFilter`). Without this, an `isGranted`-driven success leaves no trace in | ||
| /// system.query_log.used_privileges even though the privilege was effectively required by the query. | ||
| context->addQueryPrivilegesInfo(AccessRightsElement{flags, args...}.toStringWithoutOptions(), true); |
There was a problem hiding this comment.
This change alters the audit contract for granted checks, but there is still no focused regression test proving used_privileges is populated for the checkAccessWithFilter filter-match path (for example GRANT READ ON S3('<pattern>') authorizing a specific URL).
Could we add one stateless/integration test that exercises that path and asserts the corresponding privilege appears in system.query_log.used_privileges?
LLVM Coverage Report
Changed lines: 100.00% (3/3) · Uncovered code |
|
Hi @alexbakharew @pufit — a couple of suggestions to make this PR easier for reviewers and the changelog reader. Description (currently
Ignore this if the current title/body is intentional. |
The QueryPrivilegesInfoUpdates and QueryPrivilegesInfoUpdatesLegacy counters were added only to measure the perf impact of always recording granted accesses in `addQueryPrivilegesInfo` (see PR ClickHouse#104693 discussion). The numbers came back well within noise (~2x more recordings, ~1 extra `unordered_set` insert per query on average, no planner-loop pathology), so the counters are no longer needed and are removed here. The functional change (dropping the `if constexpr (throw_if_denied)` gate on the granted-side write) is kept. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…audit-record-isgranted Store all asked privileges for better RBAC auditing
Expand
system.query_log.used_privilegescoverage to also record privileges that are confirmed via the non-throwingisGrantedpath, so thatREAD ON FILE/READ ON S3/READ ON AZURE/READ ON URL(and any other privilege checked throughContextAccess::checkAccessWithFilter) are visible in the audit trail.Background
#99122 centralized source-access checks for
file()/s3()/azure()/url()table functions and routed them throughContextAccess::checkAccessWithFilter, which usesisGrantedfor the granted path:isGrantedischeckAccessImpl<throw_if_denied=false, ...>. InContextAccess::checkAccessImplHelper, the call toContext::addQueryPrivilegesInfo(..., granted=true)was gated onthrow_if_denied, so the granted branch on non-throwing entry points never recorded. Net effect:DESCRIBE file('…'),CREATE TABLE AS file('…'), and similar queries no longer reportedREAD ON FILEinsystem.query_log.used_privileges. The privilege check itself still ran — unauthorized users still getCode: 497 ACCESS_DENIEDon the new branch — so enforcement was unchanged, only the audit trail was incomplete.Change
Drop the
if constexpr (throw_if_denied)gate around the granted-sideaddQueryPrivilegesInfocall incheckAccessImplHelperso every successful access check records, regardless of which public API (checkAccess/checkGrantOption/isGranted/checkAccessWithFilter) reached the helper. The denied-side gate is preserved so predicate-styleisGrantedcallers do not pollutemissing_privilegeswith speculative misses.Measurement
Two
ProfileEvents are added to allow the impact to be quantified directly fromsystem.query_log:QueryPrivilegesInfoUpdates— total recordings intoused_privileges/missing_privilegesafter the change.QueryPrivilegesInfoUpdatesLegacy— only the recordings from throwing call paths (checkAccess/checkGrantOption), matching the historical pre-change behavior.Results
Full stateless asan run on this PR's commit
8e6cab260702ec24961ce1c48f36fab083fbcc35(Stateless tests (amd_asan…), 282,702QueryFinishrows):legacy_baseline(old behavior)new_total(this PR)audit_gap_closedaudit_gap_pctnew_calls_per_querylegacy_calls_per_queryAbout one additional
std::unordered_set<String>::emplaceper query on average, distributed across the suite.Tail check
Top queries by additional recordings:
SYSTEM START VIEWSSYSTEM START VIEWSSYSTEM PAUSE VIEWSSYSTEM PAUSE VIEWSSELECT count() FROM test.visits(×7)SELECT count() FROM test.hits(×7)kill mutation where …All concentrated on legitimate "iterate over N objects and check each" patterns — view fan-out for
SYSTEMDDL, per-columnSELECTresolution on wide tables, per-mutation checks forKILL MUTATION— exactly the cases where granular per-object audit signal is useful. The worst-case query adds 614 set inserts on a 6 ms query (microseconds of extra work), and nothing in the distribution looks like a planner loop over millions of items.Aggregation query used to produce the numbers above (works against the CI logs cluster's
default.query_log_*tables):Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Record privileges in
system.query_log.used_privilegesfor all granted access checks, including those that go through the non-throwingisGrantedpath (checkAccessWithFilter). Previously only privileges checked via throwing entry points (checkAccess/checkGrantOption) were recorded, which madeREAD ON FILE/READ ON S3/READ ON AZURE/READ ON URLinvisible in the audit log forDESCRIBE,CREATE TABLE AS, and similar queries that usefile()/s3()/azure()/url()table functions. Access enforcement is unchanged.Documentation entry for user-facing changes
Version info
26.6.1.109