Skip to content

Add user_files_policy server setting for custom disks in user_files directory - #100173

Open
alexey-milovidov wants to merge 277 commits into
masterfrom
user-files-policy
Open

alexey-milovidov wants to merge 277 commits into
masterfrom
user-files-policy

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 20, 2026 •

Copy link
Copy Markdown
Member

Add a new user_files_policy server configuration parameter, similar to tmp_policy, that lets the user_files directory live on a custom storage volume, including S3-backed disks. The policy must have exactly one volume containing exactly one disk; when configured, that disk provides the storage for user files, and user_files_path is interpreted as a directory inside that disk (/ is the disk root; the disk root is used if user_files_path is not configured).

file(), the File table engine, FunctionFile and DatabaseFilesystem route globbing, reads, writes, schema inference and truncation through the IDisk interface when a volume is configured, so a remote backend such as s3_plain works end to end.

Features that fundamentally need a local POSIX path fail closed instead of silently operating on a metadata or ciphertext path: ATTACH ... FROM, SQLite, the filesystem() table function, the static HTTP file:// handler, FileLog, EmbeddedRocksDB with an explicit rocksdb_dir, several dictionary sources, catboostEvaluate, InputFormatErrorsLogger, the local data lakes, rename_files_after_processing, the lazy Parquet materialization pass and the Distributed format all reject a policy disk that is not plain local. Archive syntax and partitioned writes are rejected under user_files_policy on any disk type.

Key changes:

  • user_files_policy in ServerSettings, with an XML example and the list of limitations
  • Context stores the VolumePtr and exposes getUserFilesVolume, getUserFilesPaths, isUserFilesPath and setUserFilesPolicy
  • SubdirectoryDiskWrapper confines the policy disk to the directory named by user_files_path
  • StorageFile gains disk-based glob matching (listFilesWithRegexpMatchingOnDisk), disk-based reads (disk->readFile) and writes (disk->writeFile), disk-aware existence probes, and symlink-escape checks on the disk-relative path
  • every getUserFilesPath caller updated for the disk-backed root
  • helper overloads pathStartsWith(path, vector) and fileOrSymlinkPathStartsWith(path, vector)
  • integration test test_user_files_policy covering a local multi-disk, an s3_plain and a DiskEncrypted policy

This allows customers to have a "scratch area" for files in ClickHouse Cloud, shared among all replicas.

Changelog category (leave one):

  • New Feature

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

Add a user_files_policy server setting to store user_files on a custom disk, including S3-backed disks.


Note

Medium Risk
Introduces a new storage-policy-backed path for user_files and rewires many read/write and path-validation code paths (including remote disks), which could affect file access semantics and security boundaries if edge cases are missed.

Overview
Adds a new server setting user_files_policy that binds the user_files directory to a storage policy (enforced to exactly one volume with one disk) and stores the resolved VolumePtr in Context, with server startup applying it via setUserFilesPolicy.

Updates user-files consumers to become disk-aware when a policy is configured: file()/StorageFile switch to IDisk-based globbing, reads, writes, schema inference and truncation (plus new helpers like splitUserFilesAbsolutePath, userFilesPathExists, and symlink-escape checks), while features that require local POSIX paths (ATTACH ... FROM, SQLite, filesystem table function, static HTTP file://, FileLog, several dictionary sources, error logger, etc.) now explicitly reject remote user_files_policy disks.

Adds integration coverage for local-disk and s3_plain configurations, including globbing, absolute paths, traversal/symlink-escape hardening, write/append/truncate behavior, schema inference, and expected rejections (e.g. partitioned inserts under user_files_policy).

Reviewed by Cursor Bugbot for commit 04b03ad. Bugbot is set up for automated code reviews on this repo. Configure here.


Workflow [PR]
Sync PR [sync-upstream/pr/100173]

@alexey-milovidov
alexey-milovidov marked this pull request as draft March 20, 2026 08:33
@clickhouse-gh

clickhouse-gh Bot commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cd05184]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, targeted) FAIL
test_user_files_policy/test.py::test_url_database_file_scheme[local] FAIL cidb
test_user_files_policy/test.py::test_url_database_file_scheme[s3] FAIL cidb
test_user_files_policy/test.py::test_url_database_file_scheme_does_not_probe_without_file_grant[local] FAIL cidb
test_user_files_policy/test.py::test_url_database_file_scheme_does_not_probe_without_file_grant[s3] FAIL cidb
test_user_files_policy/test.py::test_parquet_lazy_materialization_only_on_plain_local_disk[local] FAIL cidb
test_user_files_policy/test.py::test_parquet_lazy_materialization_only_on_plain_local_disk[s3] FAIL cidb
test_user_files_policy/test.py::test_snappy_mode_round_trip_through_disk[basic-local] FAIL cidb
test_user_files_policy/test.py::test_snappy_mode_round_trip_through_disk[basic-s3] FAIL cidb
test_user_files_policy/test.py::test_snappy_mode_round_trip_through_disk[framed-local] FAIL cidb
test_user_files_policy/test.py::test_snappy_mode_round_trip_through_disk[framed-s3] FAIL cidb
12 more test cases not shown
Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted) FAIL
Server died FAIL cidb
UndefinedBehaviorSanitizer: undefined behavior (STID: 3175-3f65) FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

The PR adds user_files_policy so user files can reside on a custom disk, including S3, and routes file operations through IDisk while rejecting unsupported local-only consumers. Approval is blocked by partial-content results after a scalar file read failure and the previously reported source-access and shared-write risks. The current CI merge also exposes a filesystem-isolation startup failure. Two new findings are posted inline; three earlier concerns remain below with the author's deferral recorded.

The new path representation was traced through scalar file, StorageFile reads/writes/schema inference/truncation, TableFunctionFile array sources and Hive columns, StorageFileCluster task paths, DatabaseFilesystem delegates and metadata serialization, and DatabaseURL existence checks. Local-only filesystem/data-lake consumers reject unsupported disk forms; the remaining mixed-cluster representation gap is listed below.

Missing context / blind spots
  • ⚠️ Runtime validation was unavailable in this review job. The current-head Praktika report has a successful Fast test, but the targeted integration job is pending and most of the full suite is skipped by the review-threads gate. Passing test_user_files_policy on the final merge would close this validation gap.
  • ⚠️ The isolation finding concerns the checked-out CI merge 2de4eaa41f77: current master adds FilesystemIsolationPaths.cpp, which is absent at PR head cd05184e0dcf. Its inline location is the corresponding changed startup guard in the PR.
Findings

❌ Blockers

  • src/Functions/FunctionFile.cpp:235 — A failed scalar read returns partial data followed by the default. If a policy-backed read produces abc and then throws on the next fetch, AutoFinalizedWriteBuffer preserves those copied bytes during unwinding. The catch appends fallback, so file(path, 'fallback') returns abcfallback; an empty default silently returns truncated contents. Save the row's starting character offset and restore it before handling the default. Apply the same correction to the legacy loop, which shares the omission.
  • src/Storages/StorageFile.cpp:4697 — Concurrent creates on shared write-once storage can lose a successful insert. [dismissed by author -- https://github.com/Add user_files_policy server setting for custom disks in user_files directory #100173#discussion_r4408832959] Two servers can both observe a missing or empty s3_plain object and publish with WriteMode::Rewrite; the later publication replaces the earlier insert. The local atomic-append fix and process-local write registry do not protect replicas. Conditional creation/publication or an enforced restriction on concurrent shared writes remains necessary; the author deferred the required IDisk API change.
  • src/Storages/StorageFile.cpp:1998 — File parsing derives protected filesystem state before source authorization. [dismissed by author -- https://github.com/Add user_files_policy server setting for custom disks in user_files directory #100173#discussion_r4655522346] TableFunctionFile::parseFirstArguments reaches disk probes and glob expansion before READ ON FILE is checked. A user without that grant can distinguish an absent path from an outside-target symlink through different exceptions, and wildcard inputs enumerate the backend before denial. The author deliberately deferred this ordering issue because the legacy branch also has it. Defer resolution until each caller's appropriate access check, or link a concrete follow-up tracking every affected entrypoint, including array sources, fileCluster, and the file:// delegate.

⚠️ Majors

  • programs/server/Server.cpp:2218 — Disk-relative user_files_path is still treated as a host mount by filesystem isolation. In the current CI merge, Collector::addDataPaths unconditionally adds that setting as a host path. The documented policy configuration with user_files_path = '/' therefore reaches planMounts with host / and throws BAD_ARGUMENTS, preventing startup with filesystem_isolation = 'enforce' or 'best_effort' on a host supporting namespaces. Skip this collector entry when a policy is configured; addDisks already collects the actual disk paths.
  • src/Storages/StorageFileCluster.cpp:209 — A legacy initiator cannot dispatch to a non-plain-local policy worker. [dismissed by author -- https://github.com/Add user_files_policy server setting for custom disks in user_files directory #100173#discussion_r4278656537] Only a policy-enabled initiator sends logical relative task names. A legacy initiator sends its host-absolute path, which a remote-policy worker validates against its unrelated disk root and rejects. The author explicitly deferred protocol negotiation to preserve rolling-upgrade compatibility. This still prevents incremental policy rollout; document the initiator requirement and track the negotiated task-format extension.
Tests
  • ⚠️ Add a focused scalar file regression where reading fails after a nonempty chunk, and assert that a string default replaces the entire partial result. The existing missing-file fallback case fails before copying any bytes.
  • ⚠️ Add a collector-level regression combining user_files_policy with user_files_path = '/' and filesystem isolation. It can verify the collected paths without starting another integration cluster.
Final Verdict

Status: ❌ Block

Correct partial-read rollback and the isolation collector, settle or explicitly track the deferred source-access/shared-write issues, document the mixed-cluster requirement, and obtain the targeted integration result on the final merge.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Mar 20, 2026
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Functions/FunctionFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Functions/FunctionFile.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Functions/FunctionFile.cpp Resolved
alexey-milovidov added a commit that referenced this pull request Apr 25, 2026
When multiple disks in the `user_files_policy` volume have overlapping
roots (for example `/mnt/user_files/` and `/mnt/user_files/archive/`),
absolute-path resolution previously bound to the first disk that matched
the path prefix. With first-match semantics that depends on disk order
in config, an absolute path under the nested root gets captured by the
parent disk and reads/writes are routed to the wrong backend.

Pick the disk with the longest matching prefix in both
`splitUserFilesAbsolutePath` (used by `StorageFile` for read/write/exists)
and the `file()` function so the more specific disk wins.

Address review:
#100173 (comment)
#100173 (comment)
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Databases/SQLite/SQLiteUtils.cpp Resolved
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review April 26, 2026 11:22
Comment thread src/Functions/FunctionFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Functions/FunctionFile.cpp Resolved
Comment thread src/Server/StaticRequestHandler.cpp Resolved
Comment thread src/Server/StaticRequestHandler.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, fix "Logical error: Primary key type mismatch, expected A, got B. (STID: 3436-4175)" and send a separate PR.

Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Functions/FunctionFile.cpp Resolved
alexey-milovidov and others added 3 commits November 11, 2026 15:57
Resolve the conflict in `StorageFile.cpp` with the single-file parallel read
(`split_file`) from master: keep the disk-aware read branch for
`user_files_policy` and apply master's split-file version checks to the plain
local branch. Splitting a single file is disabled under `user_files_policy`,
because it `stat`s and reads the file by its local path instead of through
`IDisk`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ar `file` without a policy

The legacy branch of `FunctionFile` (no `user_files_policy`) had switched the
root used for the access check from `fs::canonical(user_files_path)` to its
lexical spelling as a side effect of an earlier refactoring. Under a symlinked
`user_files_path` this rejected physical absolute paths that were accepted
before. Restore the code from master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ptor

`ReadSettings::disableCaches` does not disable `OpenedFileCache`, which the
`pread`, `pread_threadpool` and `io_uring` local read methods use and which
is keyed by the path alone. After a file is replaced under the same name, a new
read could reuse the descriptor of the old inode kept open by a concurrent
reader. `getUserFilesDiskReadSettings` now always selects
`LocalFSReadMethod::read`, which opens a fresh descriptor, as the reader of a
plain `user_files_path` does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 I merged current master. There was one conflict in StorageFile.cpp with the single-file parallel read of Parquet (#125738): I kept the disk-aware read branch of user_files_policy and applied master's split-file version checks to the plain local branch. Splitting a single file is disabled under user_files_policy (trySplitSingleFile), because it stats and reads the file by its local path instead of through IDisk. I also addressed the two new review threads: OpenedFileCache reuse for policy files (4a22f9d) and the canonical root in the legacy scalar file (bff4ff2). The binary builds locally, and 05394_parquet_single_file_parallel_read passes. The only CI failure was the review-threads gate. Two older threads are still open because they need a human decision: the fileCluster task format between a legacy initiator and a worker with a non-local policy, and the publish race on write-once object storage.

Comment thread src/Storages/FileLog/StorageFileLog.cpp Resolved
alexey-milovidov and others added 4 commits November 13, 2026 03:47
Resolve the conflict in `StorageFileSource::generate`: master keeps the read buffer of a split file
between its buckets (`if (!read_buf || split_file)` and `else if (!read_buf)` around `createReadBuffer`);
apply that to the plain `user_files_path` branch. A file is never split with a `user_files_policy` volume.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ser_files_policy` files

`LocalObjectStorage::patchSettings` replaced every local read method with `pread`, which shares
descriptors by path through `OpenedFileCache`, so a `local_blob_storage` disk with plain metadata
undid `getUserFilesDiskReadSettings`, and a read after the file was replaced under the same name
could reuse the descriptor of the old inode. `read` is synchronous like `pread`, so keep it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`loadFiles` normalized the path with `lexically_normal` after the containment check had validated
the original spelling. Removing `..` before resolving a symlink can select a different file, so
`a/../b/file.log` with `a` pointing inside and `b` pointing outside the `user_files_policy` disk
passed the check and then probed the outside file. Normalize the path once in the constructor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 All review threads are resolved. I merged current master (no conflicts), and clickhouse builds locally. The last CI run had only skipped the full suite because of the unresolved-threads gate, so this push starts a complete run.

@alexey-milovidov

alexey-milovidov commented Nov 16, 2026 •

Copy link
Copy Markdown
Member Author

🕵 Status: the last CI run skipped the full suite only because of the review-threads gate. Two threads are open again, and each needs a human decision rather than a code change in this PR:

Please decide whether these should be handled in follow-up PRs (then the threads can be resolved) or in this one.

Resolve a conflict in `YAMLRegExpTreeDictionarySource.h`: keep master's `[[nodiscard]]` on `getLastModification` and this PR's `checkFilePath`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 I merged current master (dfdda07). There was one conflict, in YAMLRegExpTreeDictionarySource.h: I kept master's [[nodiscard]] on getLastModification and this PR's checkFilePath. clickhouse builds locally. The full CI suite will still be skipped until the two review threads mentioned above are resolved.

alexey-milovidov and others added 7 commits November 19, 2026 09:02
Resolve conflicts in `StorageFile`: keep both the new `format_settings_`
argument of `FilesIterator` from master and the `user_files_volume_`
argument of this PR; pass `std::nullopt` format settings in
`StorageFileCluster` as master does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…include

`cachesObjectMetadata` and the overrides in `SubdirectoryDiskWrapperDirectoryIterator`
trip `modernize-use-nodiscard`; after merging master `Disks/IDisk.h` was included twice
in `Storages/ObjectStorage/Local/Configuration.cpp`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `FileLog` files

Discovery and watcher updates called `is_regular_file` on a found file before
`isDataFileAllowed`, so a child symlink pointing outside the policy root could
disclose whether its target exists, or fail `CREATE TABLE` with
`Too many levels of symbolic links` for an outside loop. Check the boundary first.
The child-symlink regression now also covers a missing and a looping outside target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…edRocksDB` without a policy

Without `user_files_policy`, an explicit `rocksdb_dir` was resolved against and
checked against `fs::canonical(user_files_path)`. The lexical check against the
configured spelling rejected a physical path beneath a symlinked `user_files_path`,
so an existing table could fail to attach after an upgrade. Restore the canonical
root in the constructor, `truncate` and `create` (the configured spelling is accepted
too); the policy branch is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The description used a `:::note` admonition, which
`05621_documentation_no_docusaurus_syntax` rejects, and links to the old
`/sql-reference/table-functions/...` routes.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=100173&sha=8a97d6414f8f3b8993e4ca4612924723d4b32e73&name_0=PR&name_1=Fast%20test
#100173

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Fixed the two CI failures of the last run and merged current master (a2126db, no conflicts):

  • Build (arm_tidy, 2/4) and Build (arm_tidy, 4/4): modernize-use-nodiscard on cachesObjectMetadata in MetadataStorageWithPathWrapper — marked that override and the three other overrides [[nodiscard]] (103e46c).
  • Fast test, 05621_documentation_no_docusaurus_syntax: the user_files_policy description used a :::note admonition — replaced it with <Note> and updated the two links to the current /reference/functions/table-functions/... routes (66b5a36).

The Finish Workflow failure was the review-threads gate; all review threads are resolved now, so this push should start the full CI suite. Locally I compiled only the 29 translation units changed by this PR (plus DiskEncrypted.cpp and DiskObjectStorage.cpp) on the merged tree; I did not complete a full build or run tests.

if (!path_to_archive.empty())
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Archive syntax is not supported with user_files_policy");

res.paths = getPathsListOnDisk(filename, user_files_volume, res.total_bytes_to_read);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Blocker] Check source access before resolving policy file paths

This runs during TableFunctionFile::parseFirstArguments, before ITableFunction::execute or getActualTableStructureWithAccess checks READ ON FILE. As a user with CREATE TEMPORARY TABLE but no file grant, run SELECT * FROM file('probe/data.csv', 'CSV', 'x UInt64'): an absent probe reaches the normal ACCESS_DENIED, while probe -> /outside throws DATABASE_ACCESS_DENIED from validateDiskRelativePathBoundary during parsing. The same query therefore reveals protected filesystem state without the source privilege. Wildcard inputs also enumerate the policy backend before denial.

The same parsing path is reachable through array sources, fileCluster, and the url delegate for file://. Defer filesystem-dependent resolution and glob expansion until the appropriate source check has succeeded, and add denied-user SELECT/DESCRIBE coverage. An unconditional READ check in FileSource::parse would incorrectly reject write-only inserts and engine-authorized creation, so those callers need to retain their respective access contracts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 I am not changing this in this PR, and I am leaving the thread open for a human decision.

The ordering is not introduced here: on master, StorageFile::FileSource::parse already calls getPathsList from TableFunctionFile::parseFirstArguments, before ITableFunction::execute or getActualTableStructureWithAccess checks the source grant. That function stats the path, expands globs on the filesystem, and throws DATABASE_ACCESS_DENIED from checkCreationIsAllowed for a symlink leading outside user_files_path, while an absent path reaches the later ACCESS_DENIED. The policy branch (getPathsListOnDisk with validateDiskRelativePathBoundary) reproduces the same behaviour for a disk; it does not add a new way to observe the filesystem.

A fix has to cover both branches, and it cannot be a check inside parse or parseFirstArguments: the same parsing serves INSERT (which needs WRITE, not READ), DatabaseFilesystem (a read is authorized by the grants on the database, and only a write checks the source grant), the url delegate for file:// (the outer function does the check), and ENGINE = File (authorized by TABLE ENGINE). Deferring the path resolution and the glob expansion until after the caller's own check means making FileSource lazy for every one of these callers, which changes the access behaviour of file without user_files_policy too. That belongs in a separate PR against master.

alexey-milovidov and others added 3 commits November 24, 2026 18:43
Conflicts:
- `programs/docker-init/docker-init.cpp`: master reads the paths with `getEffectiveConfigValue` (server arguments win over the configuration file); kept that and kept skipping `user_files_path` when `user_files_policy` is configured, reading the policy name the same way.
- `src/Storages/StorageFileCluster.cpp`: master added a `const std::atomic_bool &` argument to the task callback; kept the `user_files_policy`-aware iterator and adopted the new signature.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
`master` removed the unused `chmod` and `supportsChmod` from `IDisk`, so the forwarding overrides in `SubdirectoryDiskWrapper` no longer compile after the merge.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…sDB` directory

For a `read_only` table over an explicit `rocksdb_dir`, the factory probed the directory with `fs::exists` before the `FILE` access check, and the required grants depended on the result: `READ` for an existing directory, `READ, WRITE` for a missing one. A user without any `FILE` grant could tell from the access-denied message whether a directory under `user_files` exists.

Require the baseline `READ ON FILE` first, and `WRITE` in addition only when the statement could create the directory.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 I merged current master (c2937c8). There were two conflicts:

  • programs/docker-init/docker-init.cpp: master now reads the paths with getEffectiveConfigValue; I kept that and kept skipping user_files_path when user_files_policy is configured.
  • src/Storages/StorageFileCluster.cpp: master added a const std::atomic_bool & argument to the task callback; I kept the policy-aware iterator with the new signature.

master also removed chmod and supportsChmod from IDisk, so I dropped the forwarding overrides from SubdirectoryDiskWrapper (c3e819d).

Review threads:

  • EmbeddedRocksDB directory probe before the FILE check: fixed in cd05184, with the new test 05874_embedded_rocksdb_no_file_grant_does_not_probe_dir. Resolved.
  • Path resolution in FileSource::parse before the source access check (Add user_files_policy server setting for custom disks in user_files directory #100173 (comment)): not changed. The same ordering exists on master for plain user_files_path, and a fix has to rework all callers of FileSource::parse, so it needs a human decision whether to do it in a separate PR.

clickhouse builds locally on the merged tree, and 05874_embedded_rocksdb_no_file_grant_does_not_probe_dir and 05054_embedded_rocksdb_explicit_dir_file_grant pass on a local server. I did not run the test_user_files_policy integration tests locally.

Three threads are open and wait for a human decision: the one above, the fileCluster task format between a legacy initiator and a worker on a non-local policy, and the publish race on write-once object storage. The review-threads gate will keep skipping the full CI suite until they are resolved.

if (vec_null_map_to)
(*vec_null_map_to)[row] = true;
else
res_chars.insert(default_result.data(), default_result.data() + default_result.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Blocker] Discard partial output before applying the default

A remote read can return one buffer and then throw while fetching the next. copyData has already appended those bytes to res_chars, and AutoFinalizedWriteBuffer finalizes during unwinding, preserving that prefix. This catch then appends default_result without undoing the partial copy: if the first buffer was abc, file(path, 'fallback') returns abcfallback, and an empty default silently returns the truncated file.

Save the row's initial character offset and restore it before handling the exception/default. The legacy loop has the same omission, so share or apply the rollback there too. Please cover a read that fails after a nonempty chunk; missing-file coverage does not reach this case.

/// With `user_files_policy`, `user_files_path` is a directory inside the disk of the policy
/// (possibly on remote storage such as `s3_plain`), installed below via `setUserFilesPolicy`.
/// In that case it is not a local path, so do not canonicalize or create it here.
if (server_settings[ServerSetting::user_files_policy].value.empty())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Apply the policy-path distinction to filesystem isolation

The current CI merge also runs Collector::addDataPaths in programs/server/FilesystemIsolationPaths.cpp, which unconditionally calls addCanonicalPathKey("user_files_path") before this part of startup. With the documented user_files_policy configuration and user_files_path = '/', that collector requests host /, although the value now means the policy disk root. On a Linux host with namespace support, both filesystem_isolation = 'enforce' and 'best_effort' reach planMounts, which rejects host / with BAD_ARGUMENTS, preventing startup.

Skip the host user_files_path entry in that collector when the policy is configured as well; addDisks already collects the disk's host paths. A focused collector regression using a policy and user_files_path = '/' would cover this integration with current master.

This branch was successfully deployed

1 active deployment
staging - docs — cd05184e Deployed Nov 24, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants