Repository navigation
URL database: do not probe the filesystem without the read source grant - #113029
Conversation
…rant `EXISTS TABLE` requires only the `SHOW TABLES` privilege, and `InterpreterExistsQuery` answers it from `DatabaseCatalog::isTableExist`, which for a `URL` database lands in `DatabaseURL::checkFileURLExists` and probes the local filesystem. A user without the read source grant could therefore tell whether a file exists under `user_files`. The same probe also runs on the resolution path, where it reports `FILE_DOESNT_EXIST` before the source access of the delegate is checked. Now the probe is performed only after the read source grant is confirmed, using the new non-throwing `ContextAccess::isGrantedWithFilter` and `ITableFunction::isSourceAccessGranted`. Without the grant the table is claimed to exist, exactly as it is for a remote URL (which is not probed either) and for a path outside of `user_files`, so an attempt to resolve it fails with the access error instead of disclosing anything. Follows up the review of #111512
|
Workflow [PR], commit [2ca961fd] Summary: ✅
AI ReviewSummaryThis PR fixes the Final VerdictStatus: ✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 25/26 (96.15%) · Uncovered code |
Build profile diff (arm_release)No arm_release build profile data for commit 2ca961f - the build was skipped, reused from cache, or predates profile upload. |
…elegate The review of #113029 pointed out that `isURLReadGranted` was not probe-free: constructing the `url` table function parses the delegate's arguments immediately, and for a `file://` URL `TableFunctionFile::parseFirstArguments` goes through `StorageFile::FileSource::parse`, which stats the path and enumerates directory contents before `READ ON FILE` is checked — a timing/resource side channel that defeats the purpose of the check. Derive the grant decision directly from the grants instead, without constructing anything: `checkFileURLExists` only ever probes `file://` URLs, and the `file` delegate reports an empty URI for source-access filtering (see `TableFunctionURL::parseArgumentsImpl`), so the delegate's own check is exactly `isGrantedWithFilter(READ, FILE, "")`, reproduced here verbatim. The now-unused `ITableFunction::isSourceAccessGranted` is removed; `ContextAccess::isGrantedWithFilter` stays as the primitive. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113029&sha=cebdc42b01538df822d2da154bb5b51f1d4538d6&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29 ( |
|
A fix is already in progress and it is mine: #112828 (open). This run is its signature. The failure here is One correction: an open tracking issue does exist, #96651, a user report against 26.1.2 where Measured breadth over the last 7 days, excluding #112828's own runs: 33 failures across 30 distinct pull requests against 13777 passes, so 0.24 percent of runs. Every failure is on #112828 has been open since 07-31 with no review yet. The |
…ore constructing the delegate The construction of the `file` delegate observes the filesystem while parsing its arguments (`StorageFile::FileSource::parse` enumerates the matching paths), and the parse errors (e.g. that the path is outside of `user_files`) were reported before the source access check of the delegate. Now `getTableImpl` fails with the access error before the delegate of a `file://` table is constructed, so `DESCRIBE` and `SELECT` without the `READ ON FILE` grant no longer touch the local filesystem. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 Both reds on commit 2c60c1c are unrelated to this PR (which only touches
|
|
Acknowledged. Investigated; STID 1611-483a is not #110338, and I will open a separate PR. That STID bucket pools two unrelated defects under one generic
So per-STID identity is not evidence of a shared root cause here. #110338 and @george-larionov's #113244 both touch only Root cause of the The existing guard at Reproduced locally on master CREATE TABLE tab_t (id UInt64, tup Tuple(UInt64, Nullable(UInt64)))
ENGINE = MergeTree ORDER BY id SETTINGS min_bytes_for_wide_part = 1, index_granularity = 64;
-- 20 batches of 5000 rows, so the threshold tracker is set before later parts are read
INSERT INTO tab_t SELECT number, tuple(number, number) FROM numbers(0, 5000);
... (x20)
SELECT tup FROM tab_t ORDER BY tup ASC NULLS LAST LIMIT 10;gives byte-for-byte the CI message ( The other three recorded carriers agree with the same rule: You are right that there is no tracking issue for this STID. I will fix the general property rather than the reported type, and link the PR here. Session id: cron:clickhouse-premium-slot-25:20260804-202200 |
|
Fix opened: #113406. It keys on the general property as promised, but not at the seam I sketched above. I had suggested excluding sort columns that structurally contain a One carrier beyond the three in my earlier comment turned up while enumerating: Session id: cron:clickhouse-review-slot-11:20260805-022300 |
|
🕵 Merged |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok. This is not very important, but good to have.
… database `DatabaseFilesystem::isTableExist` answered from the table cache and then probed the directory, neither of which checked a grant, while `EXISTS TABLE` itself requires only `SHOW TABLES`. A user with that privilege and without `READ ON FILE` could therefore tell an existing file under `user_files` from a missing one: measured on the previous head of this branch, `EXISTS TABLE` returned 1 for a cached name and 0 for a name that is not there. The resolution path was already gated, so what was left of the disclosure was an existence oracle over the same directory. Without the grant the answer is now that the table exists, which is what `DatabaseURL::checkFileURLExists` reports in the same situation: resolving such a table fails with the access error, so the state of the directory stays unobservable. The check is the entry of the method, above the cache lookup, for the reason the resolution gate is: the cache is keyed on the table name alone, so an entry filled by a grant holder must not answer for a user who does not hold it. `URL`, the sibling engine with this defect class, gated its resolution path and its existence probe in one change, ClickHouse#113029, under one test. Hence three assertions here rather than a second test file: two for the ungranted user, a cached name and a missing one, which must answer alike, and one after the grant, which keeps that pair from being a constant.
A clone of a part that passes no invalidated_columns_to_write (the untouched-part clone in a mutation, clone-instead-of-fetch of a replicated mutation, moves between disks) used to delete the invalidated_system_columns.txt it had just hardlinked or copied from the source part: writeInvalidatedSystemColumnsFileImpl unconditionally removed the existing file and wrote nothing back for an empty set. Losing the file resurrects the stale physically stored _block_number and _block_offset values that were disclaimed when the part was adopted from another table (ClickHouse#111801), so several co-active clones of one source part expose duplicate row identities. A lightweight UPDATE then captures the duplicates into a single patch part with a constant _part_data_version, and applying that patch in Join mode fails the 'current_version != existing_version' assertion in PatchJoinCache::Entry::addBlock, which aborts debug and sanitizer builds; release builds silently drop one of the duplicate rows. Fix in two places: - writeInvalidatedSystemColumnsFileImpl keeps an existing file when the caller has nothing new to invalidate; this covers the clones that copy or hardlink the whole part directory. - cloneAndLoadDataPart merges the source part's invalidated set into the clone parameters; this also covers the Packed storage, whose freeze/freezeRemote copy only the data archive, so the destination never inherits the file. Failure history: https://play.clickhouse.com/play?user=play&tab=Query%20V#U0VMRUNUIGNoZWNrX3N0YXJ0X3RpbWUsIHB1bGxfcmVxdWVzdF9udW1iZXIsIGNoZWNrX25hbWUsIHRlc3RfbmFtZSBGUk9NIGNoZWNrcwpXSEVSRSB0ZXN0X25hbWUgTElLRSAnJWN1cnJlbnRfdmVyc2lvbiAhPSBleGlzdGluZ192ZXJzaW9uJScgQU5EIGNoZWNrX3N0YXJ0X3RpbWUgPj0gbm93KCkgLSBJTlRFUlZBTCAzIE1PTlRICk9SREVSIEJZIGNoZWNrX3N0YXJ0X3RpbWU= The reproduced CI failure (the only one on a branch that already had the invalidation mechanism from ClickHouse#111801): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113029&sha=cebdc42b01538df822d2da154bb5b51f1d4538d6&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 ClickHouse#113029 Co-Authored-By: Claude Fable 5 <[email protected]>
The
URLdatabase engine (added in #111512) probes the local filesystem to answer whether afile://table exists.EXISTS TABLErequires only theSHOW TABLESprivilege —InterpreterExistsQueryanswers it fromDatabaseCatalog::isTableExist, which lands inDatabaseURL::checkFileURLExists— so a user without the read source grant could tell whether a file exists underuser_files. The same probe runs on the resolution path, where it reportsFILE_DOESNT_EXISTbefore the source access of the delegate is checked, which is another way to observe the same thing (DESCRIBE,SELECT).Now the probe is performed only after the read source grant is confirmed, using the new non-throwing
ContextAccess::isGrantedWithFilterandITableFunction::isSourceAccessGranted. Without the grant the table is claimed to exist, exactly as it is for a remote URL (which is not probed either) and for a path outside ofuser_files, so an attempt to resolve the table fails with the access error instead of disclosing anything.New test
04692_url_database_exists_no_source_probe.Related: #111512
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
A table of the
URLdatabase engine no longer discloses whether a local file exists to a user without the read source grant:EXISTS TABLE, which requires only theSHOW TABLESprivilege, and the resolution of a table no longer probe the filesystem before the grant is confirmed.