Skip to content

Require the FILE source grant for an EmbeddedRocksDB table with an explicit rocksdb_dir - #117428

Merged
PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:rocksdb-explicit-dir-file-grant
Sep 2, 2026
Merged

PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:rocksdb-explicit-dir-file-grant

Conversation

@groeneai

@groeneai groeneai commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

ENGINE = EmbeddedRocksDB(ttl, rocksdb_dir, read_only) with an explicit rocksdb_dir now requires the FILE source grant that file requires for the same directory: READ ON FILE to create such a table, plus WRITE ON FILE when read_only = 0. Previously it required no source grant, so a user holding only CREATE TABLE in a database of their own could point a table at another table's directory and read its rows. ON CLUSTER and Replicated-database DDL are not covered: the replay runs with no user. The argument-less form is unaffected. Backward incompatible for anyone already using an explicit rocksdb_dir without them.

Description

A user holding only CREATE TABLE in their own database could read another table's rows:

GRANT CREATE TABLE, SELECT, INSERT ON poc.* TO low;   -- no FILE grant

SELECT * FROM victim.secret;   -- denied, correctly

CREATE TABLE poc.leak (k String, v String)
    ENGINE = EmbeddedRocksDB(0, 'secret_rocks', 1) PRIMARY KEY k;
SELECT * FROM poc.leak;      -- returns victim.secret's rows

create performed no access check, and the engine declares no source_access_type, so the implicit TABLE ENGINE grant was the only engine-level check. The containment fence bounds where the directory may be, not who may read it, and read_only = 1 opens with OpenForReadOnly, which takes no RocksDB lock, so the victim table can be live.

create now requires that grant on the explicit-directory branch only, READ always plus WRITE when read_only = 0, using the fresh-definition predicate of StorageURL, StorageDistributed, StorageBuffer and DatabaseBackup: a definition replayed from this server's metadata (startup, short ATTACH TABLE t, UNDROP) stays loadable after a revoke, and clickhouse-local is exempt as in file. RESTORE is checked, per StorageDistributed.cpp:2675-2691. Not declared as source_access_type: that is engine-wide and argument-blind, so it would also gate the argument-less form the documentation uses.

Two same-class gaps stay open. An ON CLUSTER or Replicated-database replay runs with no user unless distributed_ddl_use_initial_user_and_roles is on, so the check is a no-op there, as in the precedents above; #113073 is the initiator-side preflight. Directory ownership is untouched: a READ ON FILE holder can still co-opt a live table's directory, and truncate has no read_only guard, so that half destroys data too. Rejecting it would break the supported one-writable-plus-N-read_only configuration, so it needs your call. StorageFileLog reads the same way, unexercised.

New stateless test: four statements master allows are now refused, six others pinned.


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

Version info

  • Merged into: 26.9.1.517 (included in 26.9 and later)

groeneai and others added 3 commits August 31, 2026 17:28
…_dir

`ENGINE = EmbeddedRocksDB(ttl, rocksdb_dir, read_only)` opened a directory under
`user_files_path` with no access check of any kind, so a user holding only
`CREATE TABLE` in a database of their own could point a table at another table's
directory and read its rows. Reading the same bytes through `file` costs
`READ ON FILE`; through this engine it cost nothing.

`create` parsed both arguments and went straight to construction. The engine
also declares no `source_access_type`, so it took the unconditional branch of
`ContextAccess::calculateFinalAccess` and received the implicit `TABLE ENGINE`
grant, which is the only engine-level check `InterpreterCreateQuery` makes. What
remained was the constructor's `fileOrSymlinkPathStartsWith` fence, and that
bounds where the directory may be, not who may read it. `read_only = 1` routes
to `rocksdb::DB::OpenForReadOnly`, which takes no RocksDB LOCK, so the victim
table can be live while it is read.

The check goes in `create` rather than on the `StorageFeatures`, for three
reasons. `source_access_type` is engine-wide and cannot see the arguments, so it
would also gate the argument-less form, which touches only the table's own data
directory under the database path and is the form the engine's documentation
uses. It is tested with `isGranted(READ | WRITE, source)`, so a `read_only`
table would need `WRITE ON FILE`. And `replaceExternalEngineWithNullIfNeeded`
keys off the same field, so declaring it would silently start replacing the
engine with `Null` under `restore_replace_external_engines_to_null`.

The context must be `args.getLocalContext()`. `args.getContext()` is asserted to
be the global context in `StorageFactory::get`, and `Context::getAccess` treats a
context with no user as having full access, so a check written against it
compiles, reads correctly, and enforces nothing. I built it that way to confirm:
every denial assertion in the new test passes.

The guard is the fresh-definition predicate already used by `StorageURL`,
`StorageDistributed`, `StorageBuffer`, `StorageNATS` and `DatabaseBackup`:
authorize a definition being introduced now, skip one replayed from this
server's own metadata, so server startup, a short `ATTACH TABLE t`, an
`ATTACH DATABASE` and an `UNDROP` keep working after a revoke. The weaker
`mode <= LoadingStrictnessLevel::CREATE` was not used: it exempts `ATTACH`, and a
full-definition `ATTACH TABLE ... ENGINE = EmbeddedRocksDB(0, 'dir', 1)` runs at
that level while requiring only `CREATE TABLE`, which would leave the same hole
open through a different keyword. `RESTORE` arrives at `SECONDARY_CREATE` and is
therefore checked, matching the ruling in `StorageDistributed`. The
`ApplicationType::LOCAL` exemption mirrors `FunctionFile`: in `clickhouse-local`
the engine skips the `user_files` fence entirely, so there is no boundary there
for a `FILE` grant to authorize.

The new stateless test has seven arms, and deleting any one term of the
condition reddens a specific one: the explicit-directory scope is pinned by the
argument-less and `ttl`-only arms, the replayed-definition exemption by the
short-`ATTACH` arm, the `WRITE` half by the writable arm, and the local context
by all three denial arms. Names carry the shell pid because a `.sh` test's
`CLICKHOUSE_DATABASE` is `default` rather than the runner's per-test database,
so `CLICKHOUSE_TEST_UNIQUE_NAME` is identical in every concurrent copy while a
user, a database and a `user_files` directory are global names.

Two gaps of the same class are left open deliberately. An `ON CLUSTER` or
`Replicated`-database replay executes with no user unless
`distributed_ddl_use_initial_user_and_roles` is on, so the check is a no-op
there; that is true of all four in-tree precedents, and the initiator-side
preflight is a separate change. Directory ownership is untouched: a legitimate
`READ ON FILE` holder can still co-opt a live table's directory, and rejecting
that would break the supported configuration of one writable plus several
`read_only` tables over one directory, so it needs an owner-level design rather
than a guess.

Co-Authored-By: Claude Opus 5 <[email protected]>
A RESTORE supplies a table definition under whoever is restoring, who need
not be the user the backup was taken from, and it arrives at
LoadingStrictnessLevel::SECONDARY_CREATE, which isLoadingFromExistingMetadata
does not include. So the new FILE source check applies to it exactly as it
does to a CREATE. That was true of the previous commit but only by reading the
predicate: no arm reached SECONDARY_CREATE.

The arm backs up an explicit-dir table as the admin, drops it, and has a user
holding READ ON FILE but not WRITE ON FILE restore it. The RESTORE is refused
with the privilege sentence naming the missing WRITE, leaves no table behind,
and succeeds once WRITE ON FILE is granted. Modelled on the equivalent arm in
04401_url_engine_s3_dispatch_engine_grant.sh, which pins the same half of the
same predicate for the URL engine.

Measured against the same tree without the check: the denial half flips to
NOT DENIED and the table is created anyway, so it is a live arm, while the
granted half passes on both binaries and is therefore a positive control
rather than a second denial assertion.
The stateless test config enables table_engines_require_grant
(tests/config/config.d/enable_access_control_improvements.xml, installed by
tests/config/install.sh), and EmbeddedRocksDB declares no source_access_type,
so ContextAccess withholds the implicit TABLE ENGINE grant from the test user.
InterpreterCreateQuery then rejects the statement before StorageFactory reaches
create, which is where the FILE check this test is about lives. Without the
engine grant the test does not exercise that check at all: the four denial arms
report a TABLE ENGINE privilege sentence instead of a FILE one, and the six
permitted arms cannot create their tables, so ten of the eleven arms break.

The grant is a precondition, not part of the assertion, so it is taken once in
the setup block and never revoked. Same shape as
04401_url_engine_s3_dispatch_engine_grant.sh, which pairs the table grant with
GRANT TABLE ENGINE ON URL for the URL engine; 22 stateless tests use the idiom.

No source change and no reference change: the arms' outputs are identical, only
the precondition differs. Verified on a server carrying that config file, with
a control that an ungranted argument-less CREATE is still refused naming TABLE
ENGINE, and that with the engine grant held an explicit directory is still
refused naming READ ON FILE.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-unknown PR origin: unclassified (legacy task) labels Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Three rounds of pre-publication review by an independent model (engine: codex; 3 findings, then 2,
then 1), plus my own cold review of the resulting code in each round. Two rounds sent the change
back for fixes; the third found nothing blocking.

# Sev Finding Verdict Evidence / action
1 ❌ The new FILE check is bypassed by ON CLUSTER and by Replicated-database DDL, so the leak is still reachable there DISAGREE (scope), mechanism confirmed and disclosed in the description Real, and stated in the description rather than left implicit. It cannot be closed inside this creator: both paths return through tryEnqueueReplicatedDDL / executeQueryOnCluster (InterpreterCreateQuery.cpp:2039-2051) before StorageFactory::get (:2495), so it needs an argument-aware check in the cross-engine initiator path, which is #113073. The ON CLUSTER half also needs a CLUSTER grant the premise user does not hold: executeDDLQueryOnCluster.cpp:118 checks it and on_cluster_queries_require_cluster_grant defaults to true (AccessControl.cpp:299). Every creator-side source or engine check in the tree has this property (StorageURL.cpp:2507, DatabaseBackup.cpp:540, StorageDistributed.cpp:2692, StorageBuffer.cpp:1541), and the in-tree treatment is to disclose and track: 04401_url_engine_s3_dispatch_engine_grant.sh:2-8 carries no-replicated-database for exactly this reason, citing issue #111561. This test inherits the same protection through use-rocksdb, which clickhouse-test:3038-3040 skips under --replicated-database.
2 ⚠️ The test exercises neither the existing-metadata predicate nor the RESTORE behaviour the description promises AGREE on RESTORE, fixed; DISAGREE on the metadata half A denied / allowed RESTORE pair was added, modelled on 04401_url_engine_s3_dispatch_engine_grant.sh:124-141; it is a fourth arm that fails without the fix. On the metadata half: dropping isLoadingFromExistingMetadata changes nothing observable, because both named paths run with no user and therefore full access. Startup is loadMetadata(global_context, ...) (Server.cpp:3722); UNDROP builds a stub ATTACH off the catalogue's own context (DatabaseCatalog.cpp:1537-1549) and is covered by the other half of the predicate regardless. An arm for it could not fail.
3 ⚠️ The test never reaches the new FILE check under the stateless server config, because the test user holds no TABLE ENGINE ON EmbeddedRocksDB AGREE, fixed Confirmed, and it would have surfaced as a red test. tests/config/config.d/enable_access_control_improvements.xml:9 sets table_engines_require_grant and install.sh:118 installs it, so ContextAccess.cpp:286-290 withholds the implicit TABLE ENGINE grant from an engine declaring no source_access_type, and InterpreterCreateQuery requires it at :3615/:3549 (re-checked at :815) before StorageFactory::get runs. Earlier rounds had measured the code default (AccessControl.cpp:311, false) instead of the deployment. Fixed by granting the engine in setup, as the equivalent merged test does at 04401_url_engine_s3_dispatch_engine_grant.sh:57, and the whole matrix was re-measured on a server carrying that config, with a printed control showing the grant does not mask the check under test.
4 ❌ read_only = 1 needs only READ ON FILE, yet truncate has no read_only guard, so a reader can delete the directory it shares DISAGREE (scope), mechanism confirmed and now disclosed in the description The mechanism is real: truncate calls fs::remove_all(rocksdb_dir) unconditionally and getDataPaths() returns {rocksdb_dir} (StorageEmbeddedRocksDB.h:89), so the bulk-insert sink also creates its temporary directory beneath a shared path. Both halves of the harm sit outside this change. Reaching another table's directory is the ownership question the description leaves open, which needs the owner-level design it asks for; without it a user destroys only their own data. And this change strictly narrows who can reach it: on master that same TRUNCATE needs no source grant at all. Guarding truncate on read_only would also remove the premise of 04330_rocksdb_truncate_drop_null_ptr.sh, which exists to run exactly that statement. What the finding contributes is now in the description: that residual destroys data, it is not only a read.
5 ⚠️ No test proves that clickhouse-local stays exempt from the new grant DISAGREE, gap disclosed here True: deleting the ApplicationType::LOCAL term reddens nothing. The proposed remedy cannot be written as specified, though. It asks for a local arm holding CREATE TABLE and TABLE ENGINE but no FILE grant to create an explicit-directory table successfully, and in the default local database that statement is already denied READ ON FILE on master: createClickHouseLocalDatabaseOverlay registers DatabaseURL(name, 'file://') (programs/local/LocalServer.cpp:520-552) and DatabaseURL::tryGetTable checks the FILE source for a file:// scheme (DatabaseURL.cpp:344-348). Measured on the unpatched binary, and for the argument-less form too, which this check never evaluates. A variant routed through a non-default database probably is writable, so I am declining on warrant rather than on impossibility: the term cannot affect anyone by default, because clickhouse-local authenticates as default (LocalConnection.cpp:87) and the minimal local user receives ALL (LocalServer.cpp:1099-1119, UsersConfigParser.cpp:568-572); and it exists because LOCAL skips the user_files fence entirely (StorageEmbeddedRocksDB.cpp:258-265), leaving no boundary for a FILE grant to authorize, exactly as FunctionFile.cpp:47 treats file. Nothing in the tree pins that exemption class: no stateless test runs clickhouse-local with a restricted users configuration. Happy to add the arm if you want the term pinned.
6 💡 The category should be Critical Bug Fix (crash, data loss, RBAC) rather than Bug Fix DISAGREE The two merged changes of this same class, both adding a required source grant to close an access-control bypass, are published under Bug Fix (user-visible misbehavior in an official stable release): #114405 and #115914, both under that heading in docs/changelogs/v26.8.1.2041-lts.md. The incompatibility is stated in the changelog entry. Happy to change the category if you prefer.
7 💡 With read_only = 1 only READ ON FILE is required, yet a fresh CREATE still creates the directory Noted, not blocking A filesystem write under a read grant, so not perfectly symmetric with file. Master requires no grant at all for the same action, and requiring WRITE here would break the supported configuration of one writable plus several read_only tables over one directory, whose read-only consumers hold READ only.
8 💡 The check runs before the primary-key validation, so an unauthorised malformed definition now reports ACCESS_DENIED instead of BAD_ARGUMENTS Noted, not blocking Deliberate: an unauthorised caller learns nothing about the definition it submitted. No test pins the previous order.
9 💡 The engine's documentation block describes rocksdb_dir without the new grant requirement Noted, not blocking No table engine in the tree documents its source-grant requirement: StorageFile and StorageURL both declare a source_access_type and say nothing about it in their Documentation{} blocks, nor do FunctionFile or DatabaseFilesystem, and READ ON FILE appears under docs/ only inside changelogs. It is a convention rather than an absolute, since one database engine does document it (DatabaseURL.cpp:451-454). Neither #114405 nor #115914 touched docs; the requirement travels in the changelog entry. Glad to add a line to the engine page if you would rather have it there.
10 💡 Six comments in the new test spell literal names without backticks (table_engines_require_grant, user_files, Atomic, RESTORE) Noted, not blocking .claude/CLAUDE.md:7 does ask for them. The comment added to src/ complies; these are shell comments in the test, whose tag-justification lines follow the plain style every stateless test uses.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Review sessions: cron:clickhouse-review-slot-11:20260831-173600, cron:clickhouse-review-slot-9:20260831-210500, cron:clickhouse-review-slot-49:20260831-224300

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, no randomization needed. As a user holding only SELECT, INSERT, CREATE TABLE ON poc.*: SELECT * FROM victim.secret is denied ACCESS_DENIED, while CREATE TABLE poc.leak (k String, v String) ENGINE = EmbeddedRocksDB(0, 'secret_rocks', 1) PRIMARY KEY k succeeds and SELECT * FROM poc.leak returns the victim's row.
b Root cause explained? No declared source_access_type, so ContextAccess grants TABLE ENGINE unconditionally, which is the only engine-level check CREATE TABLE makes; create adds none of its own; the constructor's fence bounds the path but authorizes nobody; read_only = 1 opens with OpenForReadOnly, which takes no RocksDB lock, so the directory can belong to a live table.
c Fix matches root cause? The check is added where the directory argument is known, in the single construction site. There is no other make_shared<StorageEmbeddedRocksDB> in src/ and no embeddedRocksDB table function.
d Test intent preserved / new tests added? No existing test changed. One new stateless test, 05054_embedded_rocksdb_explicit_dir_file_grant.sh: four statements master allows are refused, six others are pinned unchanged, and a control asserts the victim table's own SELECT is still denied.
e Both directions demonstrated? Yes, on Build-ID-verified binaries: the test passes with the fix and fails on the same tree without it, with the four denial arms flipping to NOT DENIED and CREATED ANYWAY. Each of the five terms of the new condition was also deleted one at a time; four of them redden a specific arm, and the clickhouse-local exemption reddens nothing (noted below). The sweep was re-taken on a server carrying the stateless access-control config, each mutant additionally asserting that config was still in effect, and a sixth mutant removing only the attach_short_syntax disjunct reddens the short-ATTACH arm while leaving RESTORE green.
f Fix is general across code paths? Sole construction site; ttl > 0 and ttl = 0 are both downstream of it; CREATE and full-definition ATTACH both covered, which is why the predicate is the fresh-definition one rather than mode <= CREATE. RESTORE is checked too, and exercised: an arm denies it without WRITE ON FILE and allows it once granted. Knowingly not closed and stated in the description: the ON CLUSTER replay runs with no user, and StorageFileLog.cpp:193 reads the same way but I did not exercise it.
g Fix generalizes across inputs? The predicate reads only the presence of the directory argument and read_only, and the test enumerates that space: directory absent in two forms, present with read_only = 1, present with read_only defaulted to 0, each in both grant states. The other axis is the loading mode, and every level a user statement can reach now has an arm: CREATE, ATTACH in both the full-definition and short forms, and SECONDARY_CREATE through RESTORE. Column types and ttl do not enter it.
h Backward compatible? No, deliberately, and said so in the description and the changelog entry: an explicit rocksdb_dir now needs READ ON FILE, and WRITE ON FILE as well when writable. Tables already on disk keep loading, which is what the replayed-definition term is for, pinned by its own arm. No setting default changes, so no SettingsChangesHistory.cpp entry, and no new AccessType, so 01271_show_privileges.reference is untouched.
i Invariants and contracts preserved? The check is a read-only precondition before any state is built: no allocation, no lock, one throw per CREATE, and placed before the primary-key and settings validation so an unauthorized caller learns nothing about the definition it submitted and sees ACCESS_DENIED rather than the fence's BAD_ARGUMENTS. On the new failure path nothing is constructed, which the test asserts by checking no table is left behind. args.getLocalContext() is the user-bearing context; args.getContext() is the global one and would make the check vacuous, which I confirmed by building it that way.

Validation, on a server carrying tests/config/config.d/enable_access_control_improvements.xml so that table_engines_require_grant is in effect as it is in CI: 27 of 27 in one selection of the rocksdb family plus 03602_embeddedrock_path, 03313_sources_read_write_grants, 01271_show_privileges and 04330_rocksdb_truncate_drop_null_ptr; the new test is 50 for 50 sequentially and 36 for 36 with 12 concurrent copies of itself, with no no-parallel tag; integration test_rocksdb_options is 10 for 10. test_rocksdb_read_only has two failures in a Debug build that reproduce identically on the unpatched binary: the server hits a contrib/rocksdb TTL assert in the read path, which NDEBUG removes from release builds.

Session id: cron:clickhouse-impl-slot-5:20260831-214504

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8bbab37]

Summary: ❌

job_name test_name status info comment
Docs examples FAIL
Documentation examples FAIL cidb IGNORED
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL IGNORED
Bugfix validation (functional tests, amd64) ERROR IGNORED
Bugfix validation (functional tests, aarch64) ERROR IGNORED
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) ERROR
Container memory budget exceeded (/docker) ERROR cidb IGNORED

AI Review

Summary

This PR adds a FILE source-grant check for EmbeddedRocksDB(ttl, rocksdb_dir, read_only) when an explicit rocksdb_dir is supplied, and the new stateless test gives good coverage for the local CREATE / full-definition ATTACH / RESTORE paths. I am still blocking it because two RBAC invariants remain open: the new check is bypassed by distributed DDL entrypoints that return before StorageFactory::get, and the read_only branch still exposes mutating entrypoints that touch the underlying directory while requiring only READ ON FILE.

Findings

❌ Blockers

  • [src/Storages/RocksDB/StorageEmbeddedRocksDB.cpp:865] This read_only ? READ : READ|WRITE split is unsafe because a read_only table still has mutating entrypoints that write to rocksdb_dir. StorageEmbeddedRocksDB::write never checks read_only, and with the default optimize_for_bulk_insert = 1 the bulk sink creates insert_directory_queue under the shared path before the ingest fails (src/Storages/RocksDB/EmbeddedRocksDBBulkSink.cpp:99-105). truncate also remove_alls the directory unconditionally (src/Storages/RocksDB/StorageEmbeddedRocksDB.cpp:299-310). That means READ ON FILE plus ordinary table rights on the alias still gives filesystem-write effects on another table's directory.
    Suggested fix: either require WRITE ON FILE even for read_only = 1, or make read_only instances reject write, truncate, and mutation paths before they touch the filesystem.

  • [src/Storages/RocksDB/StorageEmbeddedRocksDB.cpp:856-866] [dismissed by author -- https://github.com/Require the FILE source grant for an EmbeddedRocksDB table with an explicit rocksdb_dir #117428#discussion_r3899755541] The new check still does not run on the two DDL entrypoints that return before storage creation: Replicated-database DDL and CREATE ... ON CLUSTER (src/Interpreters/InterpreterCreateQuery.cpp:2040-2052). On the worker side, DDLTaskBase::makeQueryContext preserves the initiating user only when distributed_ddl_use_initial_user_and_roles = 1 (src/Interpreters/DDLTask.cpp:332-353), and otherwise Context::getAccess treats the no-user context as full access (src/Interpreters/Context.cpp:2454-2462). So the same explicit-rocksdb_dir RBAC bypass is still reachable through supported creation paths.
    Why this still matters: disclosing the gap in the description does not close it; the access check still fails the “every entrypoint before derivation” invariant for this engine.

Tests
  • ⚠️ Once the distributed-DDL path is fixed, add one focused negative regression for a Replicated-database or ON CLUSTER create without READ ON FILE; the current stateless test exercises only the local StorageFactory::get path.
  • ⚠️ Once the read_only grant split is fixed, add a regression proving a read_only table cannot create bulk-insert temp files or TRUNCATE the shared rocksdb_dir without WRITE ON FILE.
Final Verdict
  • Status: ❌ Block
  • Minimum required actions: close the initiator-side distributed-DDL bypass, and make the read_only branch non-mutating before it is authorized with only READ ON FILE (with focused regression coverage for both).

LLVM Coverage Report

Measured on commit 8bbab37.

Metric Baseline Current Δ
Lines 88.60% 88.60% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 80.90% 80.90% +0.00%

Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @GrigoryPervakov @pufit, could you review this? ENGINE = EmbeddedRocksDB(ttl, rocksdb_dir, read_only) with an explicit directory opened a path under user_files_path with no access check of any kind, so a user holding only CREATE TABLE in a database of their own could point a table at another table's directory and read its rows. create now requires the same FILE source grant that file requires for the same directory, on the explicit-directory branch only, so the argument-less form the documentation uses stays free.

{
const AccessFlags required
= read_only ? AccessFlags(AccessType::READ) : (AccessType::READ | AccessType::WRITE);
local_context->checkAccess(required, toStringSource(AccessTypeObjects::Source::FILE));

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 only protects the local CREATE / full-definition ATTACH / RESTORE path that actually reaches StorageFactory::get. CREATE in a Replicated database returns via tryEnqueueReplicatedDDL, and CREATE ... ON CLUSTER returns via executeQueryOnCluster, before the storage is instantiated at all (src/Interpreters/InterpreterCreateQuery.cpp:2039-2051), so the initiator never executes this branch.

On the worker side, DDLTaskBase::makeQueryContext preserves the initiating user only when distributed_ddl_use_initial_user_and_roles = 1 (src/Interpreters/DDLTask.cpp:332-353). Otherwise the query runs with no user_id, and Context::getAccess treats that as full_access (src/Interpreters/Context.cpp:2453-2461), so this checkAccess is a no-op there too.

That leaves the same RBAC hole open for distributed DDL: a user who can create in a Replicated database, or who also holds CLUSTER, can still create EmbeddedRocksDB(0, 'secret_rocks', 1) without any READ ON FILE grant and read another table's directory. The authorization needs an initiator-side, argument-aware preflight before the enqueue/ON CLUSTER return paths, otherwise the PR title and changelog are still false for those entrypoints.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Citations check out at 71272f0. InterpreterCreateQuery.cpp:2039-2045 returns via tryEnqueueReplicatedDDL and :2048-2051 via executeQueryOnCluster, both before StorageFactory::get; DDLTask.cpp:332 sets the initiating user only when distributed_ddl_use_initial_user_and_roles is on, and it defaults to false (ServerSettings.cpp:1171); Context.cpp:2454 is bool full_access = !user_id.

The mechanism is not new to this thread. It is row 1 of the adjudication comment on this PR and it is in the description, with the same line numbers. Scope is unchanged: every creator-side source or engine check in the tree has this property, and DatabaseBackup.cpp:538-541 guards on has_real_user for exactly this reason. #111561 is the no-user root cause and #113073 is the argument-aware initiator-side preflight. Adding a new initiator-side authorization layer is a separate change with its own design question, and I am not making it inside this one.

Your last clause is the part that was not already covered, and it is right for the changelog. That entry lands in CHANGELOG.md on its own, without the description, so as written it read as if the hole were closed everywhere. I added to it: "ON CLUSTER and Replicated-database DDL are not covered: the replay runs with no user." I also named Replicated databases in the description, which said only ON CLUSTER even though that is a separate return path. I left the title, which describes the change at the same granularity as the precedents it follows, and the entry under it now carries the limitation.

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8bbab378a with master c90895196 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

3 object files changed (+21.70 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/RocksDB/StorageEmbeddedRocksDB.cpp.o 806.16 KiB 827.85 KiB +21.69 KiB (+2.69%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 16 s compile time in total, 7 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 71272f0

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

This head is 170 nodes: 146 OK, 19 SKIPPED, 5 red. The diff is 3 files (src/Storages/RocksDB/StorageEmbeddedRocksDB.cpp plus one stateless test and its reference), 0 under ci/, and none of the 5 reds touches a path it changes.

Check / test Reason Owner / fixing PR
Bugfix validation (functional tests, amd64) ERRORs at ci/jobs/functional_tests.py:734 with AssertionError: Could not find master builds in S3 before any server starts, so the job validated nothing and reports at job level with no test attributed. Trunk-wide #117433 (mine, open)
Bugfix validation (functional tests, aarch64) same Could not find master builds in S3 abort as the row above #117433 (mine, open)
Finish Workflow / python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py cascade of the two rows above: the hook reds when no per-arch bugfix job reports OK or XFAIL #117433 (mine, open)
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) job-level container-memory abort with no failing test assertion: the shard's nested containers breach the /docker cgroup leaf, which ci/jobs/integration_test_job.py then reports #117411 / #117412 (external, open)
AST fuzzer (arm_asan_ubsan) / Logical error: Invalid number of columns in chunk pushed to OutputPort. Expected 0, found 1 (STID 2270-3258) pre-existing trunk logical error, reachable on master without this diff: the failing query is SELECT DISTINCT DENSE_RANK() OVER (ROWS BETWEEN 1024 PRECEDING AND CURRENT ROW) FROM remoteSecure('127.0.0.{3,4}:9440', view(SELECT 3 AS a)) FINAL LIMIT 931, a distributed read whose header carries no table column and so diverges from what RemoteSource pushes. No RocksDB or access-control frame #113469 (mine, open)

Session id: cron:our-pr-ci-monitor:20260901-060000

@PedroTadim PedroTadim self-assigned this Sep 1, 2026
&& local_context->getApplicationType() != Context::ApplicationType::LOCAL)
{
const AccessFlags required
= read_only ? AccessFlags(AccessType::READ) : (AccessType::READ | AccessType::WRITE);

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 read_only ? READ : READ|WRITE split is only safe if a read_only EmbeddedRocksDB table has no mutating entrypoints that touch rocksdb_dir. That is not true today. StorageEmbeddedRocksDB::write never checks read_only, and with the default optimize_for_bulk_insert = 1 the EmbeddedRocksDBBulkSink constructor creates insert_directory_queue under storage.getDataPaths()[0] before any RocksDB write is attempted (src/Storages/RocksDB/EmbeddedRocksDBBulkSink.cpp:99-105). truncate also remove_alls rocksdb_dir unconditionally (src/Storages/RocksDB/StorageEmbeddedRocksDB.cpp:299-310).

So a user with only READ ON FILE plus ordinary rights on their alias still gets filesystem-write effects on another table's directory. Either the read_only = 1 branch needs WRITE ON FILE too, or the mutating entrypoints on read_only instances need to throw before they touch the filesystem.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed all three call sites and measured them on pristine master 26.9.1.1; this PR changes only create, so those paths are identical there. EmbeddedRocksDBBulkSink.cpp:103-104, StorageEmbeddedRocksDB.cpp:819, :309.

  • write: the INSERT does reach the sink, then fails with Code: 555 ... Not supported operation in read only mode. 0 rows written, victim row intact.
  • Bulk sink: two tmp_insert_* directories appeared inside the victim's directory during the INSERT (7 of 31 samples at 20 ms; 0 of 28 with optimize_for_bulk_insert = 0). Both were removed on sink destruction and the directory returned to its original 6 entries.
  • truncate: this is the one with teeth. The alias owner's TRUNCATE emptied the victim's directory, 6 files to 0. The victim kept answering from its still-open handle, and after a server restart SELECT count() on it returns 0. Silent, permanent data loss.

I am not taking the first remedy. Requiring WRITE ON FILE for read_only = 1 makes a reader hold WRITE, which breaks the one-writable-plus-N-read_only shared-directory configuration this engine documents, and it does not close truncate anyway: any legitimate WRITE ON FILE holder still wipes a neighbour's directory with that same statement.

Making read_only instances refuse mutating entrypoints is the right shape. For write it costs nothing given the error above. truncate succeeds destructively today, so guarding it changes documented read_only behavior, which is the directory-ownership half the description already flags as needing a maintainer call. I am not folding it into this PR.

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8bbab37

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Bugfix validation (functional tests, aarch64) job-level abort before any server starts: AssertionError: Could not find master builds in S3 at ci/jobs/functional_tests.py:734, so nothing was validated and no test is attributed #117433 (mine, open)
Bugfix validation (functional tests, amd64) same Could not find master builds in S3 abort as the row above #117433 (mine, open)
Finish Workflow / Post Hooks workflow_hooks/new_tests_check.py reads the two Bugfix validation results above and fails on their ERROR state, so it is downstream of the same defect #117433 (mine, open)
Docs examples / Documentation examples the toYYYYMM documentation example pinned its own output to 202608, so SELECT toYYYYMM(now(), 'US/Eastern') started returning 202609 at 2026-09-01 00:00 America/New_York and the check now fails on master and on 158 pull requests #117459 (mine, merged 2026-09-01), absent from this tree
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) the job ran with CI_DIND_INIT_RESERVE=17179869184, i.e. the 16 GiB reserve this tree still computes, so the leaf was sized before the fix #117412 (external, merged 2026-09-01), absent from this tree

Session id: cron:our-pr-ci-monitor:20260901-173000

@PedroTadim
PedroTadim added this pull request to the merge queue Sep 2, 2026
Merged via the queue into ClickHouse:master with commit 9a853c0 Sep 2, 2026
169 of 175 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 2, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 3, 2026
Edited by the NightlyChangelog CI job following .claude/skills/edit-changelog/SKILL.md.

Changelog-revert: 117651 117428 Revert "Require the FILE source grant for an EmbeddedRocksDB table with an explicit rocksdb_dir"
Changelog-deleted-entry: 117428 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * `ENGINE = EmbeddedRocksDB(ttl, rocksdb_dir, read_only)` with an explicit `rocksdb_dir` now requires the `FILE` source grant that `file` requires for the same directory: `READ ON FILE` to create such a table, plus `WRITE ON FILE` when `read_only = 0`. Previously it required no source grant, so a user holding only `CREATE TABLE` in a database of their own could point a table at another table's directory and read its rows. `ON CLUSTER` and `Replicated`-database DDL are not covered: the replay runs with no user. The argument-less form is unaffected. Backward incompatible for anyone already using an explicit `rocksdb_dir` without them. [#117428](#117428) ([Groene AI](https://github.com/groeneai)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-unknown PR origin: unclassified (legacy task) pr-bugfix Pull request with bugfix, not backported by default 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.

3 participants