Repository navigation
Restrict local object access only for user files path - #111483
Conversation
|
Workflow [PR], commit [c946946] Summary: ⏳
AI ReviewSummaryThis PR tightens local-path validation for PR Metadata
Findings❌ Blockers
Tests
Final Verdict
|
`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]>
3f7838b to
5c5c547
Compare
078a822 to
a074d39
Compare
e2f62c1 to
ed6e952
Compare
| 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)) |
There was a problem hiding this comment.
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).
2bbf598 to
87fd299
Compare
fbceebc to
1237ebe
Compare
Backport #111483 to 26.7: Restrict local object access only for user files path
`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]>
Antalya 26.6 Backport of ClickHouse#106281, ClickHouse#111483 - Restrict local object access only for user files path
Cherry pick #111483 to 26.6: Restrict local object access only for user files path
Cherry pick #111483 to 26.5: Restrict local object access only for user files path
Cherry pick #111483 to 26.3: Restrict local object access only for user files path
Restrict local object access only for user files path
Backport #111483 to 26.5: Restrict local object access only for user files path
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]>
|
@scanhex12 Since this is a security fix, could you please take another look at the backports? (if the corresponding older versions are affected) |
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]>
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]>
Backport #111483 to 26.3: Restrict local object access only for user files path
Backport #111483 to 26.6: Restrict local object access only for user files path
Changelog category (leave one):
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
26.7.2.27,26.6.6.7,26.3.33.55