Skip to content

Support Remote and RemoteSecure storage engines - #106189

Merged
alexey-milovidov merged 40 commits into
masterfrom
remote-storage-engine
Jul 19, 2026
Merged

alexey-milovidov merged 40 commits into
masterfrom
remote-storage-engine

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented May 31, 2026 •

Copy link
Copy Markdown
Member

Implements #93138.

Previously, a table over a remote server built from an ad-hoc set of addresses could only be created via CREATE TABLE ... AS remote(...), reusing the remote/remoteSecure table functions. This PR adds the persistent counterparts as storage engines:

CREATE TABLE t ENGINE = Remote('addresses', db, table[, user[, password], sharding_key]);
CREATE TABLE t ENGINE = RemoteSecure(...);

This restores the symmetry between the table functions and the storage engines: Distributed uses a configured cluster, while Remote/RemoteSecure build a cluster on the fly from the supplied addresses, exactly like the remote/remoteSecure table functions. The table structure may be omitted, in which case it is inferred from the remote table.

The complex argument parsing previously living inside TableFunctionRemote::parseArguments is extracted into a reusable free function parseRemoteFunctionArguments, shared between the table functions and the new engines, so they accept exactly the same signatures with no duplicated logic. The engines construct a StorageDistributed over the resulting owned cluster.

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Added the Remote and RemoteSecure table engines, the persistent counterparts of the remote and remoteSecure table functions. CREATE TABLE ... ENGINE = Remote('addresses', db, table, ...) now works in addition to CREATE TABLE ... AS remote(...).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

  • Merged into: 26.7.1.1174 (included in 26.7 and later)

Implements #93138.

Previously, a table over a remote server built from an ad-hoc set of
addresses could only be created via `CREATE TABLE ... AS remote(...)`,
i.e. by reusing the `remote` and `remoteSecure` table functions. This
adds the persistent counterparts as storage engines, so that

    CREATE TABLE t ENGINE = Remote('addresses', db, table[, user[, password], sharding_key])
    CREATE TABLE t ENGINE = RemoteSecure(...)

work as well. This restores the symmetry between the table functions and
the storage engines: `Distributed` uses a configured cluster, while
`Remote`/`RemoteSecure` build a cluster on the fly from the addresses,
exactly like the `remote`/`remoteSecure` table functions.

The complex argument parsing previously living inside
`TableFunctionRemote::parseArguments` is extracted into a reusable free
function `parseRemoteFunctionArguments`, which is shared between the
table functions and the new engines. The engines construct a
`StorageDistributed` over the resulting owned cluster, so they accept
exactly the same signatures as the table functions, and the table
structure may be omitted (it is then inferred from the remote table).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ef7bb68]

Summary: ✅


AI Review

Summary

This PR adds persistent Remote and RemoteSecure table engines by reusing the remote argument parser and wrapping StorageDistributed, and it already fixes a substantial set of follow-up issues around settings validation, secret masking, local-target checks, attach/restore behavior, and docs. I would still request changes because two local-target access-control gaps remain on the persisted-engine path, and the older persistent AS remote(...) constructor still bypasses the same safeguards entirely.

Findings

❌ Blockers

  • [src/Storages/StorageDistributed.cpp:2578] [dismissed by author -- https://github.com/Support Remote and RemoteSecure storage engines #106189#discussion_r3510960485] RESTORE still accepts a local table-function target when validation fails for any non-ACCESS_DENIED reason. That is not fail-closed for a fresh restore: restoring Remote('127.0.0.1', merge(db, '^protected$'), 'default') with explicit columns while the matched table is absent succeeds, and the stored engine credentials start reading it as soon as a matching local table reappears later. Logging the swallowed exception makes this auditable, but it does not re-establish the CREATE-time access invariant.
    Suggested fix: reject the restore unless access to the local target can actually be proven, or gate the fallback behind an explicitly trusted/internal restore mode instead of the default user-facing path.
  • [src/Storages/StorageDistributed.cpp:2582] [dismissed by author -- https://github.com/Support Remote and RemoteSecure storage engines #106189#discussion_r3362203807] Local table-function targets are still validated only through structure discovery. For merge(db, '^secret$'), that path goes through getStructureOfRemoteTable and StorageMerge::getColumnsDescriptionFromSourceTablesImpl, which check SHOW_TABLES/SHOW_COLUMNS, not the SELECT privilege that is later used to read through the stored engine credentials. A user with schema visibility but without SELECT can still persist ENGINE = Remote('127.0.0.1', merge(...), 'default') and then force the remote path with prefer_localhost_replica = 0 to read the local table as the engine user.
    Suggested fix: reject persistent local-shard table-function targets whose read access cannot be proven at CREATE/RESTORE, or add a dedicated object-level access check for the subset of table functions (merge, view, etc.) whose underlying local tables can be enumerated.

⚠️ Majors

  • [src/Interpreters/InterpreterCreateQuery.cpp:2222, src/TableFunctions/ITableFunction.cpp:80] [dismissed by author -- https://github.com/Support Remote and RemoteSecure storage engines #106189#discussion_r3585857330] The older persistent constructor CREATE TABLE ... AS remote(...) still bypasses the new persistence-time safeguards. With explicit columns it is materialized lazily through StorageTableFunctionProxy, so it still skips the Remote engine’s local-target validation and still does not register named-collection dependencies. That leaves two persistent constructors for the same feature area with different security and lifecycle behavior.
    Suggested fix: route persistent AS remote(...) creation through the same registerStorageRemote path, or thread the persistence mode and dependent StorageID through the table-function path so it applies the same checks.
Final Verdict

Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label May 31, 2026
Comment thread src/Storages/StorageDistributed.cpp Resolved
alexey-milovidov and others added 3 commits June 1, 2026 09:01
`registerStorageRemote` in `StorageDistributed.cpp` (part of the `dbms`
library) called `parseRemoteFunctionArguments`, which was defined in
`TableFunctionRemote.cpp` in `clickhouse_table_functions`. That library is
not linked into every target that uses `dbms` (e.g. `unit_tests_dbms`),
so the build failed with an undefined symbol:

    ld.lld-21: error: undefined symbol: DB::parseRemoteFunctionArguments(...)

Move `parseRemoteFunctionArguments` and the `ParsedRemoteFunctionArguments`
struct into a new file `Storages/Distributed/parseRemoteFunctionArguments.{h,cpp}`,
which is part of `dbms`, so the symbol is available wherever `dbms` is.
`TableFunctionRemote` keeps calling it through the new header (table
functions already depend on storages).

Also add the missing local forward declaration of `registerStorageRemote`
required by `-Wmissing-prototypes`.

CI: #106189

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When a `Remote`/`RemoteSecure` table is created without an explicit
structure, the structure is inferred from the remote table. Previously the
inference was left to the `StorageDistributed` constructor, which uses the
storage's global context. For a local target such as
`Remote('127.0.0.1', db, table)` that bypassed the user-context
`SHOW_COLUMNS` access check in `getStructureOfRemoteTableInShard`, so a user
allowed to create a `Remote` table could infer the schema of a local table
they are not allowed to describe.

Infer the columns in `registerStorageRemote` under `args.getLocalContext()`
(the user's context) and pass them to `StorageDistributed`, so the access
check is enforced.

CI: #106189

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Storages/StorageDistributed.cpp Resolved
Comment thread src/Storages/StorageDistributed.cpp Resolved
alexey-milovidov and others added 5 commits June 3, 2026 00:39
The new `Remote` and `RemoteSecure` storage engines were not present in the
`engine_to_type` map used by the ArrowFlight SQL server, so
`test_arrowflight_interface/test_sql_server.py::test_get_table_types` failed
with `Some engine(s) in system.table_engines are not mapped`. Map them to
`REMOTE TABLE`, like `Distributed`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…gines

`Remote` and `RemoteSecure` accept a positional `password`, but were not
registered in `FunctionSecretArgumentsFinder::findTableEngineSecretArguments`,
so `SHOW CREATE TABLE` / `system.tables.engine_full` printed the password
instead of `[HIDDEN]`. Reuse `findRemoteFunctionSecretArguments`, which handles
both the positional and the named-collection forms, since the engines accept
exactly the same arguments as the `remote`/`remoteSecure` table functions.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Setting `is_remote_function_` only adjusts the distributed client info; it does
not reproduce the local-shard access checks that `TableFunctionRemote::executeImpl`
performs. A user allowed to create `ENGINE = Remote('127.0.0.1:9000', secret_db,
secret_table, 'default')` could otherwise force the remote path (e.g. with
`prefer_localhost_replica = 0`), sending the query back to this server under the
stored credentials without checking the caller's access on the local target.

Mirror the table-function check in `registerStorageRemote`: when the built
cluster contains a local shard, require the creating user to hold both `SELECT`
and `INSERT` on the local target table (a persistent table can be used for both),
under the user's context.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When a persistent `Remote`/`RemoteSecure` table is created from a named
collection (`ENGINE = Remote(my_collection, ...)`), the shared parser never
passed the table's `StorageID` to `tryGetNamedCollectionWithOverrides`, so the
table was not registered as a dependent of the collection. As a result,
`DROP NAMED COLLECTION` was not blocked while the table existed and the
dependency was not rebuilt on reload, which could leave a stored `Remote` table
broken after reload or next use.

Thread an optional `dependent_table_id` through `parseRemoteFunctionArguments`
and pass `&args.table_id` from `registerStorageRemote`. Table-function callers
leave it null, since their lifetime is bound to the query.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The failures of 00175_obfuscator_schema_inference and 00096_obfuscator_save_load in Stateless tests (amd_tsan, parallel) are NOT caused by this PR.

They were introduced by #104690 ("Add UntrackedMemory asynchronous metric"), which made clickhouse-obfuscator abort (SIGABRT) on process teardown: the query results are correct, but the Aborted line on stderr fails the test. #104690 has now been reverted (#106365).

#104690 was merged in violation of the ClickHouse team rules: its own CI already showed these two tests failing (10 times between May 12 and June 1) before it was merged.

Please update your branch to pick up the revert; the tests should pass again.

Comment thread src/Storages/StorageDistributed.cpp Resolved
alexey-milovidov and others added 2 commits June 5, 2026 10:15
For the persistent `Remote`/`RemoteSecure` engines, the local-shard access
check applied `SELECT`/`INSERT` to `parsed.remote_table_id`. When the target
is a table function (e.g. `numbers(...)`, `merge(...)`), that field is left at
the parser default `system.one`, so the check validated the wrong object: it
both spuriously required privileges on `system.one` and, with explicit columns,
never analyzed the table function under the creating user's context. A query
against such a persisted table could then be routed back to this server under
the engine credentials, reading local data the creator was never checked for.

Now, when the cluster contains a local shard and the target is a table
function, the function is analyzed under the user's context even when the
columns are given explicitly (`getStructureOfRemoteTableInShard` runs it through
`getActualTableStructureWithAccess`, which performs the access check). The
`SELECT`/`INSERT` check on `remote_table_id` is applied only for a plain table
target.

Added `04318_remote_storage_engine_access`, covering the persistent-engine
security and lifecycle invariants: the local-shard `SELECT`/`INSERT` check with
explicit columns, schema inference under the creating user's context, and the
named-collection dependency that blocks `DROP NAMED COLLECTION` while the table
exists.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Updated in c3e41a8 (pushed onto the existing branch, no rebase):

  • Merged current master (the branch was ~543 commits behind), which picks up the revert of Add UntrackedMemory asynchronous metric #104690 — the 00175_obfuscator_schema_inference / 00096_obfuscator_save_load failures were caused by that PR and are unrelated here. Latest CI for the previous commit was already green.
  • Fixed the remaining AI-review blocker: for a table-function target on a local shard, the access check no longer validates the parser default system.one; the function is now analyzed under the creating user's context even when columns are explicit (getActualTableStructureWithAccess), and the SELECT/INSERT check on remote_table_id applies only to plain table targets. Harmless targets like numbers(...) are no longer rejected spuriously. (The view(SELECT ...) example specifically is unreachable via the engine — a nested SELECT in a table-function argument is a SYNTAX_ERROR in the storage-definition grammar.)
  • Added 04318_remote_storage_engine_access covering the persistent-engine security/lifecycle invariants: the local-shard SELECT/INSERT check with explicit columns, schema inference under the creating user's context, and the named-collection dependency blocking DROP NAMED COLLECTION.

Built and verified locally: both 04308_remote_storage_engine and the new 04318_remote_storage_engine_access pass, and the merge(db, '^secret$') table-function path is correctly rejected at CREATE without SELECT on the underlying table.

Comment thread src/Storages/StorageDistributed.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Fast test (arm_darwin) failure is the known macOS shard-test infrastructure issue, not caused by this PR.

04308_remote_storage_engine failed only on the case

CREATE TABLE t_remote_engine (dummy UInt8) ENGINE = Remote('127.0.0.{1,2}', system, one);
SELECT count() FROM t_remote_engine;

with Code: 209. DB::NetException: Timeout: connect timed out: 127.0.0.2:9000 ... (ALL_CONNECTION_TRIES_FAILED).

This is the standard shard-tag mechanism in clickhouse-test: shard tests are enabled only when the server's listen_host contains 127.0.0.2, but on the arm_darwin runner 127.0.0.2 is not actually reachable, so any shard test that connects to the second shard times out. Over the last 14 days, shard-tagged tests have 0 passes on arm_darwin — they are either skipped (when listen_host lacks 127.0.0.2) or fail (when it is configured but unroutable). Affected on dozens of unrelated PRs, e.g. 04336_parallel_blocks_marshalling_low_cardinality_native_format (86 fails across ~85 PRs) and 04327_rewrite_aggregate_function_with_if_distributed (45 fails). 04308 uses the identical 127.0.0.{1,2} pattern and shard tag as those accepted master tests, so no test change is warranted here.

I re-ran the failed job (workflow run 27483260206) — it passes when the runner skips the shard tests.

@groeneai, could you investigate / track the arm_darwin shard-test infrastructure failure (the runner advertises 127.0.0.2 in listen_host but 127.0.0.2:9000 is unroutable, so all shard-tagged tests fail when they actually connect to the second shard)? I could not find a dedicated tracking issue — #103235 covers a different arm_darwin problem (server crashes/hangs for 01404/04068). The fix likely belongs on the runner side (set up the 127.0.0.2/127.0.0.3 loopback aliases, or keep listen_host to 127.0.0.1/::1 so these tests skip consistently).

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov Confirmed: same root cause as the wider arm_darwin class. macOS binds only 127.0.0.1 on lo0 and does not auto-route the rest of 127.0.0.0/8, so 127.0.0.2:9000 is unroutable. The shard tag enables 04308's Remote('127.0.0.{1,2}', ...) case only when listen_host advertises 127.0.0.2, but that address is then unreachable, hence the Code 209 ALL_CONNECTION_TRIES_FAILED.

Scope over the last 7 days (Fast test arm_darwin, 127.0.0.2:9000 / ALL_CONNECTION_TRIES_FAILED): 15 distinct tests, 90 PRs, 165 failures, 0 on master.

Fix is in flight: PR #107435 adds a macOS Fast-test pre-hook aliasing 127.0.0.2..127.0.0.16 on lo0 (the server already listens on 0.0.0.0), so these tests run instead of skip. It also un-skips 5 parallel-replica remote() tests as proof. The same aliasing makes the shard-tag tests both satisfied and reachable, so 04308 is covered by it too. Open and mergeable, awaiting review.

On the tracking issue: a dedicated tracker is not strictly needed since #107435 fixes the whole class at once. If you would prefer one, I can open an issue enumerating the remaining darwin.skip / shard-tag tail to un-skip incrementally after the aliases land. 04327/04336 are already skipped on master via #107376.

`04308_remote_storage_engine` exercises the multi-shard case
`Remote('127.0.0.{1,2}', system, one)`, which connects to the second
loopback shard `127.0.0.2:9000`. On the `arm_darwin` Fast test runner,
macOS binds only `127.0.0.1` on `lo0` and does not auto-route the rest
of `127.0.0.0/8`, so `127.0.0.2` is unroutable and the query fails with
`ALL_CONNECTION_TRIES_FAILED`.

This is the same macOS shard-test infrastructure issue already handled
for the sibling tests `04327_rewrite_aggregate_function_with_if_distributed`
and `04336_parallel_blocks_marshalling_low_cardinality_native_format`,
which were added to `ci/defs/darwin.skip` in #107376. `04308` is a new
test introduced by this pull request, so it was not covered there. Add
it to `ci/defs/darwin.skip` for consistency until the runner-side fix
(#107435) aliases the additional loopback addresses and these tests can
run on macOS again.

The test itself is unchanged and keeps full coverage on Linux.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106189&sha=dbc0fc28753abffe3096e1064be57a6c440263b6&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29
Related: #107376
Related: #107435

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Storages/StorageDistributed.cpp Resolved
alexey-milovidov and others added 2 commits June 16, 2026 08:31
…rom metadata

The `Remote`/`RemoteSecure` storage-engine creator analyzes a local-shard
table-function target under the user's context to validate the creator's
access to the function's underlying tables, even when the columns are given
explicitly. This is a `CREATE`-time check, but the creator also runs when the
table is loaded from already-validated metadata on server startup
(`FORCE_ATTACH`) or `RESTORE` (`FORCE_RESTORE`). In that case re-running it is
unnecessary and harmful: analyzing the target can throw if its underlying
tables have changed since creation (e.g. the table matched by `merge(...)` was
dropped), making a valid persisted table impossible to load.

Guard the table-function inference and the local-shard `SELECT`/`INSERT`
checks with `isLoadingFromExistingMetadata`, so they run for fresh definitions
(`CREATE` and user `ATTACH`) but are skipped when loading from existing
metadata. The structure is still inferred unconditionally when it was omitted,
because then it is the table's only source of columns.

Add an integration test that creates a `Remote` table over a local `view(...)`
target, drops the table the view reads from, restarts the server, and checks
that the `Remote` table still attaches.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Every integration test directory must contain an `__init__.py`; its absence
made the `Style check` fail with:

    ./tests/integration/test_remote_storage_engine_attach/__init__.py should exist for every integration test

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
harikrishnan94 pushed a commit to harikrishnan94/ClickHouse that referenced this pull request Jul 17, 2026
A leftover `txn_version.txt.tmp` on a part is an artifact of an interrupted
write, so not only its content but even the disk-level metadata describing it
can be broken. On an object storage disk with local metadata, a raw or
partially written metadata file for it made `getFileSize` throw
`CANNOT_PARSE_INPUT_ASSERTION_FAILED` from
`DiskObjectStorageMetadata::deserialize` inside
`VersionMetadataOnDisk::removeTmpMetadataFile`, failing the part load, the
table load, and with it the server startup ("Cannot start clickhouse-server").

The read there is purely diagnostic (the content is dumped to the log before
the file is removed), so make it best-effort: on failure, log the exception
and proceed with the removal, which is already tolerant to such files
(`UnlinkFileOperation` reads the disk-level metadata with
`tryReadMetadataFile`).

Seen in stress tests when the harness kills the server inside the window in
which `04492_attach_as_replicated_clears_tmp_txn_version` keeps a raw
`txn_version.txt.tmp` on a part, e.g.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106189&sha=73e731bf28d09bb59fa7e7921f58be9d812cf201&name_0=PR&name_1=Stress%20test%20%28arm_debug%29
on ClickHouse#106189, and the same
signature on at least three other PRs within the last 30 days.

Add `test_broken_tmp_txn_version_startup`: a transactional insert on a local
object storage disk, a raw overwrite of the `txn_version.txt.tmp` metadata
file, and a hard restart. Without the fix the server fails to load the table
with the exact `Cannot parse input` error from the report; with the fix it
starts, the committed part survives, and the leftover file is cleaned up.
The AI review noted that the docs contrast was false: a `remote(...)` table
function with a table-function target (e.g. `remote('127.0.0.1', numbers(10))`)
is rejected by `StorageDistributed::write` for the same reason as the
`Remote`/`RemoteSecure` engines, because `TableFunctionRemote::executeImpl`
forwards `remote_table_function_ptr` to `StorageDistributed`. So `INSERT` is
`NOT_IMPLEMENTED` for both the table functions and the engines when the target
is itself a table function.

Reword the `Remote`/`RemoteSecure` engine paragraph in
`docs/en/engines/table-engines/special/distributed.md` to state the read-only
limitation applies equally to the table functions, and add the same caveat to
`docs/en/sql-reference/table-functions/remote.md`, which previously claimed
`INSERT` is always supported.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.10% 86.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 78.20% 78.20% +0.00%

Changed lines: Changed C/C++ lines covered: 306/312 (98.08%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator

Both fixes for #110133 are already open and in review:

No separate/competing PR needed here; tracking both against #110133.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 19, 2026
Merged via the queue into master with commit 6583179 Jul 19, 2026
350 of 351 checks passed
@alexey-milovidov
alexey-milovidov deleted the remote-storage-engine branch July 19, 2026 01:48
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 19, 2026
alexey-milovidov added a commit that referenced this pull request Jul 19, 2026
Resolve conflicts with the `Remote`/`RemoteSecure` engine work (#106189) that
landed on master, which touched the same areas as this PR:

- `StorageDistributed::write`: both branches added the same
  `remote_table_function_ptr` guard rejecting `INSERT` into a table-function
  target with `NOT_IMPLEMENTED`; kept a single copy with a comment covering the
  `remote()`/`cluster()` table functions, the `Remote`/`RemoteSecure` engines,
  and the `Distributed` engine over a table function.
- Anonymous-namespace helpers before `registerStorageDistributed`: kept both
  this PR's `bindTableFunctionTargetsToCurrentDatabase` family and master's
  `finalizeDistributedSettings`; the call sites to `finalizeDistributedSettings`
  auto-merged into the registration bodies.
- `docs/.../distributed.md`: kept both the "From a table function" section and
  master's "Remote and RemoteSecure engines" section.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai likewise you did in this PR: #108507 can you check if these engines respect the remote_url_allow_hosts setting?

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I'll verify whether the new Remote/RemoteSecure storage engines route through the remote_url_allow_hosts host filter (as the remote/remoteSecure table functions do), and follow up here with my findings plus a fix PR if there is a gap.

@groeneai

Copy link
Copy Markdown
Collaborator

@PedroTadim yes, both engines respect remote_url_allow_hosts.

registerStorageRemote and the remote/remoteSecure table functions share parseRemoteFunctionArguments (parseRemoteFunctionArguments.cpp#L322-L336), whose ad-hoc-cluster branch calls getRemoteHostFilter().checkHostAndPort(...) for every parsed host. For the engines this runs during CREATE, so a host outside the allow-list is rejected with UNACCEPTABLE_URL before the table is created (the config-cluster path is intentionally skipped for both, same as the table functions).

Verified locally with a restrictive <remote_url_allow_hosts>: CREATE TABLE ... ENGINE = Remote('disallowed-host', ...) (and RemoteSecure, and a glob expanding to a disallowed host, and a disallowed port) all fail with code 491; an allowed host creates a Distributed table. With no allow-list configured the same disallowed host is accepted, confirming the filter is the gate.

There was no test covering this, so I added one: #111140 (test_allowed_url_from_config::test_storage_engine_remote).

pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Jul 21, 2026
…allow_hosts

Follow-up to ClickHouse#106189. The Remote/RemoteSecure storage engines build a cluster
on the fly from user-supplied addresses via the same parseRemoteFunctionArguments
as the remote/remoteSecure table functions, which calls
RemoteHostFilter::checkHostAndPort for every parsed host. For the engines this
runs during CREATE, so a host outside <remote_url_allow_hosts> is rejected with
UNACCEPTABLE_URL before the table is created. This adds a regression test that
locks in that behavior for both Remote and RemoteSecure (disallowed bare host,
glob expanding to a disallowed host, disallowed port; allowed host succeeds).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
A leftover `txn_version.txt.tmp` on a part is an artifact of an interrupted
write, so not only its content but even the disk-level metadata describing it
can be broken. On an object storage disk with local metadata, a raw or
partially written metadata file for it made `getFileSize` throw
`CANNOT_PARSE_INPUT_ASSERTION_FAILED` from
`DiskObjectStorageMetadata::deserialize` inside
`VersionMetadataOnDisk::removeTmpMetadataFile`, failing the part load, the
table load, and with it the server startup ("Cannot start clickhouse-server").

The read there is purely diagnostic (the content is dumped to the log before
the file is removed), so make it best-effort: on failure, log the exception
and proceed with the removal, which is already tolerant to such files
(`UnlinkFileOperation` reads the disk-level metadata with
`tryReadMetadataFile`).

Seen in stress tests when the harness kills the server inside the window in
which `04492_attach_as_replicated_clears_tmp_txn_version` keeps a raw
`txn_version.txt.tmp` on a part, e.g.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106189&sha=73e731bf28d09bb59fa7e7921f58be9d812cf201&name_0=PR&name_1=Stress%20test%20%28arm_debug%29
on ClickHouse#106189, and the same
signature on at least three other PRs within the last 30 days.

Add `test_broken_tmp_txn_version_startup`: a transactional insert on a local
object storage disk, a raw overwrite of the `txn_version.txt.tmp` metadata
file, and a hard restart. Without the fix the server fails to load the table
with the exact `Cannot parse input` error from the report; with the fix it
starts, the committed part survives, and the leftover file is cleaned up.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`registerStorageRemote` in `StorageDistributed.cpp` (part of the `dbms`
library) called `parseRemoteFunctionArguments`, which was defined in
`TableFunctionRemote.cpp` in `clickhouse_table_functions`. That library is
not linked into every target that uses `dbms` (e.g. `unit_tests_dbms`),
so the build failed with an undefined symbol:

    ld.lld-21: error: undefined symbol: DB::parseRemoteFunctionArguments(...)

Move `parseRemoteFunctionArguments` and the `ParsedRemoteFunctionArguments`
struct into a new file `Storages/Distributed/parseRemoteFunctionArguments.{h,cpp}`,
which is part of `dbms`, so the symbol is available wherever `dbms` is.
`TableFunctionRemote` keeps calling it through the new header (table
functions already depend on storages).

Also add the missing local forward declaration of `registerStorageRemote`
required by `-Wmissing-prototypes`.

CI: ClickHouse#106189

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
When a `Remote`/`RemoteSecure` table is created without an explicit
structure, the structure is inferred from the remote table. Previously the
inference was left to the `StorageDistributed` constructor, which uses the
storage's global context. For a local target such as
`Remote('127.0.0.1', db, table)` that bypassed the user-context
`SHOW_COLUMNS` access check in `getStructureOfRemoteTableInShard`, so a user
allowed to create a `Remote` table could infer the schema of a local table
they are not allowed to describe.

Infer the columns in `registerStorageRemote` under `args.getLocalContext()`
(the user's context) and pass them to `StorageDistributed`, so the access
check is enforced.

CI: ClickHouse#106189

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Address two AI-review findings on PR ClickHouse#106189
(ClickHouse#106189):

- The `Remote`/`RemoteSecure` registrations loaded `DistributedSettings`
  via `loadFromQuery` but skipped the validation and default propagation
  that `Distributed` runs immediately after. The background `INSERT` queue
  reads these table settings directly, so `ENGINE = Remote(...)` ignored the
  global `distributed_background_insert_*` defaults and accepted invalid
  combinations such as `max_delay_to_insert = 0` or
  `bytes_to_throw_insert <= bytes_to_delay_insert` that
  `ENGINE = Distributed(...)` rejects. The shared logic is extracted into
  `finalizeDistributedSettings` and called from both registrations.

- The `Remote`/`RemoteSecure` registrations passed no `Documentation`
  object, so `system.table_engines` listed them with empty `description`
  and `syntax`. Both now carry source-level documentation, with
  `RemoteSecure` noting the secure TCP default port.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Address review feedback (ClickHouse#106189 (comment)):
when analyzing a `Remote`/`RemoteSecure` table-function target on a backup
`RESTORE` fails for a reason other than access control, the failure is
tolerated (the target may be legitimately absent in the restore environment,
e.g. the table matched by `merge(...)` was dropped since the backup was taken)
and the restore proceeds with the columns carried in the backup metadata.

Previously the exception was swallowed silently. Log it at `WARNING` level with
the table name and the full exception (including stack trace) so a genuine
problem is surfaced rather than hidden, and the tolerated acceptance is
auditable. `ACCESS_DENIED` is still fatal and rethrown as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The named-collection branch of `parseRemoteFunctionArguments` discarded the
collection's own `db`/`table` values as soon as any complex (non-literal)
override was present: `remote(nc, sharding_key = rand())` recorded only the
sharding key and left the database at the hard-coded `system`, routing the
query to `system.<table>`. It also unconditionally required a `table` key,
so the documented table-function form `remote(nc, database = merge(...))`
was rejected unless the collection carried a dummy `table` key. Since the
`Remote`/`RemoteSecure` engines reuse this parser, both misparses carried
into the engines too.

Now the collection's own values are loaded first (simple literal overrides
are already merged into the collection by `tryGetNamedCollectionWithOverrides`)
and the complex overrides are applied on top, and `table` is required only
when the target is not a table function. With a table-function target the
parsed table id stays at the parser default (`system.one`), matching the
positional `remote('addr', table_function())` form, which the callers rely on.

Addresses ClickHouse#106189 (comment)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ngine

Support Remote and RemoteSecure storage engines
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…allow_hosts

Follow-up to ClickHouse#106189. The Remote/RemoteSecure storage engines build a cluster
on the fly from user-supplied addresses via the same parseRemoteFunctionArguments
as the remote/remoteSecure table functions, which calls
RemoteHostFilter::checkHostAndPort for every parsed host. For the engines this
runs during CREATE, so a host outside <remote_url_allow_hosts> is rejected with
UNACCEPTABLE_URL before the table is created. This adds a regression test that
locks in that behavior for both Remote and RemoteSecure (disallowed bare host,
glob expanding to a disallowed host, disallowed port; allowed host succeeds).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature 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