Skip to content

Restrict local object access only for user files path - #111483

Merged
scanhex12 merged 12 commits into
masterfrom
iceberg_local_fix
Jul 28, 2026
Merged

scanhex12 merged 12 commits into
masterfrom
iceberg_local_fix

Conversation

@scanhex12

@scanhex12 scanhex12 commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Restrict local object access only for user files path. Continuation of #99405

Version info

  • Backported to: 26.7.2.27, 26.6.6.7, 26.3.33.55

@clickhouse-gh

clickhouse-gh Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c946946]

Summary: ⏳

job_name test_name status info comment
Stateless tests (arm_binary, parallel) FAIL
00084_external_aggregation FAIL cidb
Stress test (arm_debug) FAIL
Logical error: Inconsistent KeyCondition behavior (STID: 5182-684a) FAIL cidb

AI Review

Summary

This PR tightens local-path validation for IcebergLocal/DeltaLakeLocal/PaimonLocal and adds focused Iceberg traversal tests, but the current implementation still breaks supported Local path semantics and leaves two previously reported data-loss paths unfixed. I would block on the compatibility regressions in DataLakeConfiguration and the still-incomplete plain-metadata delete semantics.

PR Metadata
  • Changelog category is plausible for an access-control fix.
  • Changelog entry is required, but the current text is too implementation-oriented and includes a raw PR reference instead of the user-visible effect. Suggested replacement: Fixes \IcebergLocal`, `DeltaLakeLocal`, and `PaimonLocal` to reject manifest and data paths that escape the allowed local table root via `..` components or symlinks.`
Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h:418] The new guard hard-codes user_files_path for every ObjectStorageType::Local, even though StorageLocalConfiguration::createObjectStorage still uses / in clickhouse-local and fromDisk resolves table roots against the selected disk. That turns supported clickhouse-local queries like deltaLakeLocal('$TMP_DIR/dl'), icebergLocal('$TMP_DIR/ice'), and paimonLocal('$TMP_DIR/pm') into immediate PATH_ACCESS_DENIED failures before the existing parser/reader logic runs, and it also rejects allowed local disks rooted outside user_files_path.
    Suggested fix: validate against the actual allowed root for the current Local configuration: / for ApplicationType::LOCAL, the selected disk root for SETTINGS disk = ..., and user_files_path only for the plain server-side local path case.

  • [src/Storages/ObjectStorage/DataLakes/DataLakeConfiguration.h:418] [dismissed by author -- https://github.com/Restrict local object access only for user files path #111483#discussion_r3658964667] The same check still runs on getPathForRead().path before Local path resolution, so raw relative paths like icebergLocal('table_dir') / deltaLakeLocal('table_dir') now fail even though LocalObjectStorage intentionally resolves them under user_files_path.
    Why this is still real: the current code still compares the unresolved string at line 417-418 instead of reusing resolvePathRelativelyToBase, so relative local table roots never reach the normal Local resolution path.

  • [src/Disks/DiskObjectStorage/ObjectStorages/Local/LocalObjectStorage.cpp:67] [dismissed by author -- https://github.com/Restrict local object access only for user files path #111483#discussion_r3639580247] resolvePathRelativelyToBase still returns the original absolute spelling unchanged once containment passes. For an Iceberg manifest path like /.../table/../table/data.parquet, the reachable set keeps the alias verbatim while listObjects reports /.../table/data.parquet, so remove_orphan_files can still treat a live file as orphaned and delete it.
    Suggested fix: return at least fs::path(path).lexically_normal().string() for already-inside paths, or normalize both reachable and listed paths before any string comparison.

  • [src/Disks/DiskObjectStorage/MetadataStorages/Plain/MetadataStorageFromPlainObjectStorage.cpp:213-230] [dismissed by author -- https://github.com/Restrict local object access only for user files path #111483#discussion_r3658964659] unlinkFile and removeRecursive still ignore should_remove_objects: recursive deletes always pass true, and unlinkFile always removes the blob. That means the plain-metadata backend still cannot honor metadata-only/shared-blob deletions, so callers that expect the MetadataLocalDiskTest.RemoveRecursiveSelectiveBlobDelete contract will delete shared blobs instead of keeping them.
    Suggested fix: guard the empty predicate, evaluate it on the path relative to the original recursive root, and make unlinkFile skip blob removal when should_remove_objects is false.

Tests
  • ⚠️ Add a clickhouse-local regression covering deltaLakeLocal('$TMP_DIR/dl'), icebergLocal('$TMP_DIR/ice'), and paimonLocal('$TMP_DIR/pm') so the Local root validation is forced to preserve current local-mode behavior.
  • ⚠️ Add a Local data-lake test for a raw relative table path (for example icebergLocal('table_dir')) to prove the guard validates the resolved path, not the unresolved argument string.
  • ⚠️ Add a plain-metadata unit test mirroring MetadataLocalDiskTest selective recursive deletion so should_remove_objects is exercised on MetadataStorageFromPlainObjectStorage.
  • ⚠️ Add an Iceberg orphan-removal test where a manifest uses an absolute lexical alias under the table root (for example .../table/../table/data.parquet) and verify remove_orphan_files does not delete the live file.
Final Verdict
  • Status: ❌ Block

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Jul 22, 2026
@scanhex12 scanhex12 self-assigned this Jul 22, 2026
@scanhex12 scanhex12 removed their assignment Jul 23, 2026
scanhex12 and others added 3 commits July 23, 2026 13:39
`resolvePathRelativelyToBase` was joining the incoming path onto
`key_prefix` (`norm_base / path`) and returning the canonicalized result.
This was wrong on two counts:

- `remote_path` produced by `MetadataStorageFromPlainObjectStorage`
  already contains `key_prefix` (it is `ObjectStorageKey::createAsRelative`
  serialized), so joining it again doubled the prefix.
- Returning the canonical absolute path changed the string form that
  `listObjects` reports as `relative_path`. `listDirectory` then hit
  `chassert(p.find(absolute_key) == 0)` and aborted, crashing
  `MetadataPlainDiskTest.RemoveDirectoryNonEmpty` in the unit tests.
  It also broke `remove_orphan_files`, which compares listed paths against
  manifest paths verbatim: a table reached through a symlink resolving
  inside `user_files` would have live files misclassified as orphans.

Instead, validate the path as-is against the canonical base (so `..` and
symlinks that escape are still rejected with `PATH_ACCESS_DENIED`) and
return the original path unchanged, preserving the form callers expect.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111483&sha=fd80c3406a6e7344ef18d69567ad55bf69c93cab&name_0=PR&name_1=Unit%20tests%20%28tsan%29
PR: #111483

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@scanhex12
scanhex12 force-pushed the iceberg_local_fix branch from 3f7838b to 5c5c547 Compare July 23, 2026 15:37
@scanhex12
scanhex12 force-pushed the iceberg_local_fix branch from 078a822 to a074d39 Compare July 24, 2026 10:59
@scanhex12
scanhex12 force-pushed the iceberg_local_fix branch from e2f62c1 to ed6e952 Compare July 24, 2026 13:56
auto user_files_path = local_context->getUserFilesPath();
if (!fileOrSymlinkPathStartsWith(this->getPathForRead().path, user_files_path))
const auto & table_path = this->getPathForRead().path;
if (!fileOrSymlinkPathStartsWith(table_path, user_files_path) || !pathStartsWith(table_path, user_files_path))

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.

This unconditionally reapplies the server user_files_path sandbox to every local data-lake read, but the rest of this patch explicitly leaves ApplicationType::LOCAL unsandboxed: StorageLocalConfiguration::createObjectStorage now uses "/" for clickhouse-local specifically. In clickhouse-local, getUserFilesPath() is still <path>/user_files/, so icebergLocal('/tmp/table') / deltaLakeLocal('/tmp/table') that currently work will now fail here with PATH_ACCESS_DENIED even though the lower layer was intentionally left unrestricted.

It also catches SETTINGS disk = '<allowed local disk>': fromDisk rewrites table_path to disk->getPath()/suffix and uses disk->getObjectStorage(), so a whitelisted local disk rooted outside user_files_path becomes unreadable after upgrade. This is a new query-time compatibility break; the guard needs to skip ApplicationType::LOCAL and, for disk-backed locals, validate against the selected disk root rather than hard-coding user_files_path (or be gated behind a compatibility setting).

@scanhex12
scanhex12 force-pushed the iceberg_local_fix branch from 2bbf598 to 87fd299 Compare July 27, 2026 10:08
@SmitaRKulkarni SmitaRKulkarni self-assigned this Jul 27, 2026

@SmitaRKulkarni SmitaRKulkarni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rest all LGTM

@scanhex12
scanhex12 force-pushed the iceberg_local_fix branch from fbceebc to 1237ebe Compare July 27, 2026 15:36
clickhouse-gh Bot pushed a commit that referenced this pull request Jul 28, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jul 28, 2026
Backport #111483 to 26.7: Restrict local object access only for user files path
scanhex12 added a commit to scanhex12/ClickHouse that referenced this pull request Jul 29, 2026
`resolvePathRelativelyToBase` was joining the incoming path onto
`key_prefix` (`norm_base / path`) and returning the canonicalized result.
This was wrong on two counts:

- `remote_path` produced by `MetadataStorageFromPlainObjectStorage`
  already contains `key_prefix` (it is `ObjectStorageKey::createAsRelative`
  serialized), so joining it again doubled the prefix.
- Returning the canonical absolute path changed the string form that
  `listObjects` reports as `relative_path`. `listDirectory` then hit
  `chassert(p.find(absolute_key) == 0)` and aborted, crashing
  `MetadataPlainDiskTest.RemoveDirectoryNonEmpty` in the unit tests.
  It also broke `remove_orphan_files`, which compares listed paths against
  manifest paths verbatim: a table reached through a symlink resolving
  inside `user_files` would have live files misclassified as orphans.

Instead, validate the path as-is against the canonical base (so `..` and
symlinks that escape are still rejected with `PATH_ACCESS_DENIED`) and
return the original path unchanged, preserving the form callers expect.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111483&sha=fd80c3406a6e7344ef18d69567ad55bf69c93cab&name_0=PR&name_1=Unit%20tests%20%28tsan%29
PR: ClickHouse#111483

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 7, 2026
@robot-clickhouse robot-clickhouse removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 11, 2026
mkmkme added a commit to Altinity/ClickHouse that referenced this pull request Aug 11, 2026
Antalya 26.6 Backport of ClickHouse#106281, ClickHouse#111483 - Restrict local object access only for user files path
scanhex12 added a commit that referenced this pull request Aug 12, 2026
Cherry pick #111483 to 26.6: Restrict local object access only for user files path
scanhex12 added a commit that referenced this pull request Aug 12, 2026
Cherry pick #111483 to 26.5: Restrict local object access only for user files path
scanhex12 added a commit that referenced this pull request Aug 12, 2026
Cherry pick #111483 to 26.3: Restrict local object access only for user files path
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 12, 2026
UnamedRus pushed a commit to UnamedRus/ClickHouse that referenced this pull request Aug 12, 2026
Restrict local object access only for user files path
scanhex12 added a commit that referenced this pull request Aug 12, 2026
Backport #111483 to 26.5: Restrict local object access only for user files path
filimonov added a commit to Altinity/ClickHouse that referenced this pull request Aug 25, 2026
Upstream `7b89d9e0786` (ClickHouse ClickHouse#111483, "Restrict local object access only
for user files path") reworked blocks that content-addressed work had commented,
and two branches merged it independently four days apart. Both resolutions kept
the same code; only the comment text and one `#include` position came out
different.

Reconciled here so that comparing the two branches stops reporting differences
that are not differences. No code changes: `MergeTask.cpp` and
`IMergeTreeDataPart.cpp` differ only in the wording of the projection
whole-part-transaction comment, `DataPartStorageOnDiskBase.cpp` in one sentence
about the arena scope, and `MergeTreeData.cpp` only in where `IO/copyData.h`
sits in the include list.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Mikhail Filimonov <[email protected]>
@rschu1ze

rschu1ze commented Sep 8, 2026

Copy link
Copy Markdown
Member

@scanhex12 Since this is a security fix, could you please take another look at the backports? (if the corresponding older versions are affected)

PedroTadim added a commit that referenced this pull request Sep 10, 2026
Every build fails with:

    src/Disks/DiskObjectStorage/MetadataStorages/Plain/MetadataStorageFromPlainObjectStorage.cpp:220:37:
        error: no member named 'CANNOT_RMDIR' in namespace 'DB::ErrorCodes'

The cherry-pick replaced this branch's `removeDirectory` / `removeRecursive`
with master's versions, but the matching `extern const int CANNOT_RMDIR;` sits
in the file's `namespace ErrorCodes` block, outside any hunk it touched, so it
was left behind.

Adding that one declaration would make it compile, but it would be the wrong
fix. Master's `removeDirectory` throws on a non-empty directory and deletes
nothing; `26.3`'s deletes the directory's contents and records them in
`objects_to_remove`. That difference is master-only code that predates #111483
(it is already present at 17f9afe^1, the master commit just before #111483
merged) and `26.3` never had it. Keeping it would quietly change disk-cleanup
behaviour on a release branch.

#111483's own delta to this file is only the `CANNOT_RMDIR` message wording and
the `removeRecursive` rewrite, and both presuppose master's semantics: the
wording change applies to a line `26.3` does not have, and the recursive
`removeRecursive` is only correct once `removeDirectory` has stopped deleting.
They are a pair, and neither belongs here on its own.

So revert the file to `26.3`'s version. The actual fix - restricting local
object access to the user files path - is untouched: it lives in
`LocalObjectStorage.{h,cpp}`, `Storages/ObjectStorage/Local/Configuration.{h,cpp}`
and `DataLakeConfiguration.h`, none of which reference either function.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 11, 2026
The auto-backport left two definitions of LocalObjectStorage::readObject:
the 26.3 three-argument one (unchanged, still reading the raw path) and
master's five-argument one, which needs ReadSettings::remote_fs_settings
and ReadBufferFromFileWithLogging - neither exists on 26.3. Drop the
master copy and apply the path resolution from #111483 to the 26.3 one.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 11, 2026
Backport #111483 to 26.3: Restrict local object access only for user files path
clickhouse-gh Bot added a commit that referenced this pull request Sep 13, 2026
Backport #111483 to 26.6: Restrict local object access only for user files path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants