Repository navigation
The URL database engine and the s3_base setting: relative URLs and uniform scheme handling - #111512
Conversation
…unctions When set, a URL without a scheme passed to the `s3` table function (or the `S3` table engine, `s3Cluster`, `gcs`, `oss`, and named collections sharing the S3 configuration) is resolved against `s3_base` per RFC 3986, reusing `StorageURL::resolveURLBase` - the same mechanism as the `url_base` setting. For the `S3` table engine, the resolved URL is materialized into the persisted DDL (like the `URL` engine does with `url_base`), so tables do not depend on the setting after creation; resolved URLs embedding credentials (`user:pass@`) are not persisted. `resolveURLBase` also gets a new rule for scheme-only bases: an authority-less base like `file://` resolves a path-relative reference by simple concatenation (`file://` + `data.csv` = `file://data.csv`, a path relative to the user_files directory), because strict RFC 3986 merging would produce an absolute path, making relative references useless with such a base. The error message for a base without a scheme now names the setting the base came from. This implements item 3 of #59617 Co-Authored-By: Claude Fable 5 <[email protected]>
A read-only database that treats table names as URLs and executes them
through the `url` table function, which dispatches by the URL scheme to the
matching engine (`file://` -> `File`, `s3://` -> `S3`, `az://` ->
`AzureBlobStorage`, `hdfs://` -> `HDFS`, everything else -> `URL`), so
files, web and object storage are handled uniformly. An optional engine
argument gives the base URL for resolving relative table names:
CREATE DATABASE web ENGINE = URL('https://example.com/data/');
SELECT * FROM web.`daily.csv`;
The default (`Overlay`) database of clickhouse-local now consists of
`Atomic` and `URL` with the `file://` base URL, replacing
`DatabaseFilesystem` in the chain: a plain table name resolves to
`file://<name>` - a path relative to the current directory, read by the
`File` engine with the same semantics as before (globs, dot segments,
absolute paths, existence checks) - while a name with a URL scheme is
dispatched to the matching engine:
clickhouse-local -q "SELECT * FROM 'https://example.com/data.csv'"
clickhouse-local -q "SELECT count() FROM 's3://bucket/data.parquet'"
For `file://`-resolved names the database checks the existence of the file
before claiming the table (mirroring `DatabaseFilesystem`), so unknown table
names keep failing with `UNKNOWN_TABLE` and `CREATE TABLE` is not shadowed.
For remote schemes the claim is syntactic, and access errors propagate from
the delegate engine.
This implements item 4 of #59617
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [764ed58] Summary: ✅
AI ReviewSummaryThis PR finishes the remaining URL-unification work by adding PR Metadata
Findings
Final Verdict
|
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
…ection `S3` engine tables When a table is created as `CREATE TABLE ... ENGINE = S3(nc)` with a relative `url` in the named collection, the resolution against `s3_base` happened only at runtime and the persisted DDL kept depending on the setting after DETACH/ATTACH or a server restart. Record the resolved URL in `StorageParsedArguments` and let `StorageObjectStorageConfiguration::initialize` materialize it back into the engine args as a `url='...'` override, with the same userinfo-suppression rule as the positional form. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111512&sha=latest&name_0=PR
…or `URL` database tables Under `parallel_replicas_for_cluster_engines`, the `url` table function executed by the `URL` database engine created `StorageURLCluster`, but a table referenced by an identifier (`db.table`) cannot be rewritten into a `urlCluster(...)` call, so `updateQueryToSendIfNeeded` threw the logical error "Expected SELECT query from table function urlCluster" (and aborted the server in the coverage build). Disable the parallel-replicas cluster auto-conversion for tables resolved through the `URL` database. Failure: 04627_url_database_engine in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111512&sha=d72583d7ed1e4f291fe4c453ed6b4445139357cd&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
|
Updated the PR:
The remaining failures are unrelated:
|
…le://` base URL A table name like `//tmp/data.csv` in a URL database with a `file://` base (the default database of clickhouse-local) took the scheme-relative branch of `StorageURL::resolveURLBase` and became `file://tmp/data.csv` -- a path relative to the user files directory -- silently reading the wrong file. A `file://` base has no meaningful authority, so such a name is a POSIX absolute path with redundant leading slashes: collapse them and resolve to an absolute local path, preserving the semantics that the `Filesystem` database had for absolute paths. Co-Authored-By: Claude Fable 5 <[email protected]>
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111512&sha=69b03b553d7e6539fc8a59af11aa2c6feef94f7a&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The failure is The other red, |
|
The Root cause (source-verified against the one master hit I traced, an azure amd_tsan no-ORDER-BY Fix status: no open fixing PR to link. The prior fix #109202 was closed WONTFIX by the coordinator owner (premise: divergent reading modes for one table should never happen, so the guard must keep throwing). That premise does not cover the Default-mode race above (there is no mode divergence there), so on 2026-07-10 I posted the falsifying master evidence plus two source-fix directions on #109202, and it is awaiting the owner's direction. I have not opened a speculative PR: I could not reproduce it locally (a single-process pseudo-cluster serializes the announce-vs-request ordering, so a real repro needs genuinely networked replicas, which only the Stress and coverage ParallelReplicas jobs provide), and the fix belongs in the coordinator once the owner confirms the direction. |
…ranch cut The Upgrade check on https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111512&sha=109acb5bbe74f3059d0e2f5f1e4048e1f935a923&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 flagged `s3_base` as a new setting not reflected in the settings changes history: master moved to version 26.8 and the 26.7 release no longer picks up this PR, so the entry must live in the 26.8 block. Co-Authored-By: Claude Fable 5 <[email protected]>
…` database table A table of a `URL` database is resolved through `ITableFunction::execute` with `is_insert_query = false`, which performs only the READ source-access check, while the returned delegate storage is writable. `INSERT INTO web.`s3://...`` then checked only the INSERT privilege on the logical table name, so a user could write to an external source without the corresponding `WRITE ON S3` / `FILE` / `URL` grant. Wrap the resolved storage in a proxy that repeats the source-access check in write mode on every write entry point (`INSERT`, async insert, a materialized view target, `TRUNCATE`). Reads are unaffected, and `INSERT INTO `file.csv`` in clickhouse-local keeps working (the default user has all grants), matching the behavior of the `Filesystem` database it replaces. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Pushed a9d76f5:
The other CI reds are unrelated to this PR:
|
…against the base URL in shared logic A relative name whose first path segment contains a colon (e.g. `report:2026.csv`) parses as an absolute URI with the scheme `report` per RFC 3986, so `StorageURL::resolveURLBase` returned it unchanged and `s3_base`/`url_base` were silently ignored, while the `URL` database patched around it locally. Now `resolveURLBase` treats only `scheme://` names as absolute and resolves such names as relative references, and the local fallback in `DatabaseURL` is removed. Also guard `TableFunctionURL::tryGetFormatFromFirstArgument` against resolved URLs that `Poco::URI` rejects (e.g. `file://report:2026.csv`, whose authority parses as a host with an invalid port): failing to detect the format from the file name is not an error. With a regression test for `url_base`, `s3_base` and the default database of clickhouse-local, and a note in the `url_base` documentation. Co-Authored-By: Claude Fable 5 <[email protected]>
…tables, logical storage ID for access checks Resolving a table of a `URL` database went through `ITableFunction::execute`, which requires the `CREATE TEMPORARY TABLE` privilege — an unrelated global grant for a table referenced by an identifier and governed by the grants on the database and the source access. `execute` takes a new `check_create_temporary_table` parameter, the `URL` database passes false, and the `url` scheme-dispatch delegate no longer repeats the check already done by the outer call. Also give `StorageURLDatabaseTable` the logical storage ID (`db`.`name`) instead of the nested `_table_function` one, so the SELECT privilege check in `InterpreterSelectQuery` (the old analyzer path) matches the user's grants. This fixes the 04642_url_database_insert_write_access failure in the old-analyzer stateless run: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111512&sha=a9d76f50c5900c6d919a4bb2558d2fa55a1e6a11&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20old%20analyzer%2C%20s3%20storage%2C%20DBReplicated%2C%20WasmEdge%2C%20parallel%2C%203%2F3%29 The test no longer grants `CREATE TEMPORARY TABLE`. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Pushed 94b61db:
Verified locally: tests 04626, 04627, 04641, 04642 and the new 04645 pass, including the RBAC scenarios under both the old and the new analyzer. |
|
The Root cause: the test relied on a read-only source grant ( The test now asserts "no source grant" vs. "the source is granted" instead, which is deterministic under both settings, and additionally covers
Verified locally on a server built from this branch: |
…; keep engine classification out of `StorageProxy` Two findings from the AI review: * The HTTP-index-page wildcard branch of `registerStorageURL` called `StorageURL::overrideURLInEngineArgs` with `skip_userinfo = false` on `args.engine_args`, which is a reference to the arguments of the `CREATE` AST. A URL resolved through `url_base` may carry `user:pass@`, so this persisted the credentials into the table metadata and exposed them via `SHOW CREATE TABLE`. The real arguments are now materialized with the same `skip_userinfo = true` policy as the other `url_base` paths, and the object storage is initialized from a scratch copy of the arguments that holds the fully resolved URL and never reaches the AST. * Forwarding `isDataLake`, `isExternalDatabase`, `isObjectStorage` and `isMessageQueue` in `StorageProxy` would make the lazy proxies (`StorageTableProxy`, `StorageTableFunctionProxy`) materialize and start up the nested storage just to answer a classification query - e.g. the `disable_insertion_and_mutation` guard in `InterpreterInsertQuery` consults them before anything else and could then report a table-load error instead of `QUERY_IS_PROHIBITED`. The overrides moved to the two eager URL wrappers that need them, `StorageURLSchemeDispatch` and `StorageURLDatabaseTable`. New test `04652_url_wildcard_index_pages_userinfo`: a userinfo-free `url_base` is still materialized into the engine arguments, while a `url_base` with credentials leaves the relative URL in the persisted DDL.
…write source grant Table resolution in DatabaseURL executed the url table function with is_insert_query = false, so the READ source-access check ran before the write-specific check of StorageURLDatabaseTable could: a user with INSERT on the database plus only WRITE ON FILE / S3 / URL was denied on INSERT INTO db.`...`, although INSERT INTO FUNCTION file(...) needs only WRITE ON FILE. The resolution now requires either of the READ / WRITE source grants (the check still gates the schema inference the table function performs on the external resource), skips the check inside ITableFunction::execute (new check_source_access parameter), and the operation-specific entry points of the proxy enforce the exact grant: read re-checks READ, and write / checkInsertIsAllowed / truncate check WRITE as before. The delegate call in TableFunctionURL::executeImpl no longer repeats the source check: the outer function reports the delegate's engine name and access URI, so the outer check covers exactly the delegate's source. Adds ContextAccess::isGrantedWithFilter, the non-throwing counterpart of checkAccessWithFilter, and ITableFunction::isSourceAccessGranted on top of it. New test: 04658_url_database_write_only_source_grant (WRITE ON FILE alone allows INSERT, SELECT still requires READ ON FILE). Co-Authored-By: Claude Fable 5 <[email protected]>
Resolution of a table of a `URL` database accepted either of the READ / WRITE source grants and left the operation-specific check to the proxy, but the structure of such a table is inferred from the data of the source and the catalog exposes it to the user without ever reaching `StorageURLDatabaseTable::read` - `DESCRIBE`, `EXPLAIN` and the analyzer read the metadata of the resolved storage. `SHOW COLUMNS` plus only `WRITE ON FILE` / `S3` / `AZURE` was therefore enough to inspect a source the user cannot read. Resolution now requires the READ source grant again (fail-close: the name of the table alone exposes the inferred structure), and the write entry points - `write`, `truncate`, and `checkInsertIsAllowed` for the initiator side of an asynchronous insert - additionally require WRITE, exactly as before. An `INSERT` into a table of a `URL` database consequently needs both source grants, while `INSERT INTO FUNCTION file(...)` keeps needing only `WRITE ON FILE`: the table form is the one that publishes the structure. The write paths no longer write through the storage resolved in read mode. The backends of the `url` table function construct different clients for reads and writes - `azureBlobStorage` creates the container only when it is not built read-only - so `INSERT INTO db.`az://...`` lost the container-creation behavior of the direct table function. The delegate of a write is now built separately, in write mode, on the first write. Reverts the now unused `ContextAccess::isGrantedWithFilter` and `ITableFunction::isSourceAccessGranted`. Test 04658 is repurposed accordingly: a user with `SHOW COLUMNS` and only `WRITE ON FILE` gets `ACCESS_DENIED` on `DESCRIBE`, `EXPLAIN`, `SELECT` and `INSERT`, and everything works after `GRANT READ ON FILE`. The full grant matrix (no source grant / read / read + write, including the asynchronous insert) stays in 04642.
…e requires the read source grant The structure of a table is inferred from the data, so `INSERT` needs the read source grant in addition to the write one.
alexey-milovidov
left a comment
There was a problem hiding this comment.
Looks amazing! Approved.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 276/313 (88.18%) · Uncovered code |
…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 ClickHouse#111512
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Implement the remaining items of the URL unification (issue #59617). The new
s3_basesetting resolves relative URLs in thes3table function and theS3table engine (and the functions sharing their configuration:s3Cluster,gcs,oss), similarly tourl_base. The newURLdatabase engine treats table names as URLs, resolves them against an optional base URL, and dispatches by the URL scheme, so files, web and object storage are handled uniformly. It replacesFilesystemin the default (Overlay) database ofclickhouse-localwith afile://base URL, so plain file names keep working, and you can also writeSELECT * FROM 'https://example.com/data.csv'.This completes #59617. Items 1 and 2 — the scheme dispatch in the
urlfunction /URLengine and theurl_basesetting — were implemented earlier (e.g. #106093); this PR implements the remaining items 3 and 4:Item 3: the
s3_basesetting. When set, a URL without a scheme passed to thes3table function (or theS3engine,s3Cluster,gcs,oss, and named collections) is resolved against it per RFC 3986, reusingStorageURL::resolveURLBase. For theS3table engine the resolved URL is materialized into the persisted DDL (like theURLengine does withurl_base), so tables do not depend on the setting after creation; resolved URLs embedding credentials (user:pass@) are not persisted.Item 4: the
URLdatabase engine. A database that treats table names as URLs and executes them through theurltable function, which dispatches by scheme (file://->File,s3://->S3,az://->AzureBlobStorage,hdfs://->HDFS, everything else ->URL). An optional engine argument gives the base URL for resolving relative table names. Reading requires the corresponding read source grant, andINSERTrequires the corresponding write source grant.The default (
Overlay) database ofclickhouse-localnow consists ofAtomicandURLwith thefile://base URL, replacingFilesystemin the chain: a plain table name resolves tofile://<name>— a path relative to the current directory, read by theFileengine with the same semantics as before (globs, dot segments, absolute paths, existence checks,UNKNOWN_TABLEfor missing names) — while a name with a URL scheme is dispatched to the matching engine. Forfile://-resolved names the database checks the existence of the file before claiming the table, soCREATE TABLEis not shadowed; for remote schemes the claim is syntactic and access errors propagate from the delegate engine.To support the
file://base,resolveURLBasegets a rule for scheme-only bases: an authority-less base resolves a path-relative reference by simple concatenation (file://+data.csv=file://data.csv, a path relative to the user_files directory / the current directory inclickhouse-local), because strict RFC 3986 merging would produce an absolute path, making relative references useless with such a base.Closes: #59617
Documentation entry for user-facing changes
Version info
26.8.1.645(included in26.8and later)