Repository navigation
Infer an omitted Buffer structure under the user's context - #113372
PedroTadim merged 1 commit into
Conversation
StorageBuffer's constructor infers an omitted structure from the destination table's in-memory metadata (StorageBuffer.cpp:180-185). Neither DatabaseCatalog::getTableImpl nor IStorage::getInMemoryMetadataPtr performs an access check, and registerStorageBuffer hands the constructor args.getContext(), which StorageFactory::get asserts is the global context (StorageFactory.cpp:236). There is no user on that path, so nothing gates the read: a user holding only CREATE TABLE on its own database could learn the column names and types of any local table by creating a columns-less Buffer over it and describing its own table. The inferred columns are written back into the creator's own persisted metadata by addColumnsDescriptionToCreateQueryIfNecessary (InterpreterCreateQuery.cpp:2283), so the disclosure survives a restart. Reads and writes were already authorized against the destination under the query context (StorageBuffer.cpp:337, :778), so this is disclosure-only. The bypass is recorded in master: 03631_buffer_access_check creates a columns-less Buffer over a table its user has no rights on, and its reference shows that CREATE succeeding. Move the inference into registerStorageBuffer, where the user's context exists, and check SHOW_COLUMNS on the destination there. This is the shape Merge (StorageMerge.cpp:213, under args.getLocalContext()) and Remote (StorageDistributed.cpp:2592) already have. The check is unconditional: Merge's SHOW_TABLES pre-filter has no analogue here because a Buffer names exactly one destination. The predicate skips loading of already-validated metadata (isLoadingFromExistingMetadata || attach_short_syntax), which is the guard Remote uses. DatabaseOnDisk deliberately stores no column list for a schema-inferring engine (DatabaseOnDisk.cpp:141-153) and sets attach_short_syntax for every such load (:90-102); without the guard, loading such a definition would try to authorize it under a context that has no user, which is the regression 04601_remote_storage_engine_short_attach exists for on the Remote side. It also skips a destination-less Buffer, keeping the existing UNKNOWN_TABLE failure for that form byte-identical rather than turning it into ACCESS_DENIED. The constructor keeps its inference branch, which now serves only the loading path. checkAccess runs before getTable, so a user without SHOW_COLUMNS on a missing destination now gets ACCESS_DENIED instead of UNKNOWN_TABLE. That is the standard ordering and is desirable: it avoids a table-existence oracle. SHOW_COLUMNS is the narrowest privilege for the disclosure, and it is implied by SELECT (ContextAccess.cpp:152-162), so no user who can already read the destination is affected. Creates that carry an explicit column list are unchanged, so this does not widen into Remote's SELECT+INSERT requirement. 03631_buffer_access_check gains a SHOW COLUMNS grant so its columns-less create still succeeds and the test keeps reaching the read and write assertions it was written for. Its reference is unchanged and no assertion was weakened.
Internal second-model review (2 rounds: own cold review + Gate B) -- click to expandAn independent reviewer read the resulting code cold, without the author's evidence, and a ❌ BlockersNone.
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260804-151700 |
|
cc @pufit @azat, could you review this? A columns-less |
|
Workflow [PR], commit [4425cff] Summary: ❌
AI ReviewSummaryThis PR moves omitted-schema inference for Final Verdict✅ No review findings in the current patch. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 17/18 (94.44%) · Uncovered code |
CI finish ledger - 4425cffEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260805-033000 |
0e1f3dd
The backported code calls `isLoadingFromExistingMetadata`, which does not exist on this branch, so add it next to the enum it tests. Nothing else here calls it yet. Identical to the addition in the backport of #113372 to this branch, so whichever merges second is not a conflict. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Backport #113372 to 26.6: Infer an omitted Buffer structure under the user's context
Backport #113372 to 26.7: Infer an omitted Buffer structure under the user's context
Backport #113372 to 26.5: Infer an omitted Buffer structure under the user's context
Backport #113372 to 25.8: Infer an omitted Buffer structure under the user's context
Backport #113372 to 26.3: Infer an omitted Buffer structure under the user's context
| auto destination = DatabaseCatalog::instance().getTable(destination_id, args.getLocalContext()); | ||
| auto destination_metadata = destination->getInMemoryMetadataPtr(args.getLocalContext(), false); | ||
| columns = destination_metadata->getColumns(); | ||
| } |
There was a problem hiding this comment.
Same as in #113220 (comment), let's move resolving from the ctor into register method as well
There was a problem hiding this comment.
Will do, same shape as #113220. The register method already resolves under the user's context, so what is left is dropping the ctor fallback and covering the metadata-loading path in the register method too (no access check on that branch, there is no user there). I will follow up here with the PR.
There was a problem hiding this comment.
Done: #114203. The ctor is now a plain setColumns(columns_); the register branch covers the stored-metadata callers too, with no access check there since they carry no user, resolving with args.getContext(), which is the context the ctor used on those paths.
I left Distributed out: that ask is on @ PedroTadim's thread in #113220, and getStructureOfRemoteTable over a cluster is a much larger change than Buffer's local metadata read.
… under the user's context
… under the user's context
… under the user's context
… under the user's context
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a case where
CREATE TABLE ... ENGINE = Buffer(...)without a column list could reveal the structure of a destination table the creating user is not allowed to see. For aCREATEthe local server executes itself, the structure is now inferred under the user's own context, soSHOW COLUMNSon the destination is required, as it already is forMergeandRemote. ACREATEreplayed from the DDL queue (ON CLUSTER, or inside aReplicateddatabase) is not covered.Description
Related: #113220, the
Distributedsibling. No related open issue; found while sweeping the engines that infer an omitted structure from a local table.What breaks. A user with
CREATE TABLEon its own database can learn the columns and types of any local table by creating a columns-lessBufferover it and describing its own table.Bufferdeclares nosource_access_type, soTABLE ENGINE ON Bufferis auto-granted on a default server and is the only other privilege needed. The inferred columns are persisted, so it survives a restart. Reads and writes were already authorized, so this is disclosure-only.Root cause. The constructor infers the structure from the destination's in-memory metadata (
StorageBuffer.cpp:180-185), and neitherDatabaseCatalog::getTablenorgetInMemoryMetadataPtrchecks access. It is handedargs.getContext(), whichStorageFactory::getasserts is the global context, so there is no user to check. Master's own03631_buffer_access_checkalready records the bypass.The change. The inference moves into
registerStorageBuffer, where the user's context exists, with an unconditionalSHOW_COLUMNScheck -- the shapeMerge(StorageMerge.cpp:213) andRemote(StorageDistributed.cpp:2592) already have. It is skipped for already-validated metadata (isLoadingFromExistingMetadata || attach_short_syntax), which has no user and stores no column list; the constructor keeps its branch for that path only.SHOW_COLUMNSis implied bySELECT, so readers are unaffected, and explicit-column creates are unchanged.Scope. A queue-replayed
CREATEreaches the engine with no user, so the check is a no-op there.ON CLUSTERsets one only withdistributed_ddl_use_initial_user_and_roleson anddistributed_ddl_entry_format_versionat least 8 (default 5); aReplicateddatabase records no initiator. Both want #113073.Validation. New
04729_buffer_infer_columns_accesscovers the denial, inference after the grant, explicit columns, temporary tables and re-attach; it fails on master and 50 randomized runs pass here.03631gains aSHOW COLUMNSgrant so its create still reaches its own unchanged assertions.Version info
26.7.4.6,26.6.3.15,26.5.7.17,26.3.18.9,25.8.30.6