Repository navigation
Report an unknown engine name in CREATE as unknown instead of as a missing TABLE ENGINE grant - #124753
Conversation
…TABLE ENGINE grant Since ClickHouse#100746 implicit `TABLE ENGINE` grants are given per registered engine name, so a user without `TABLE ENGINE ON *` has no grant for a name no factory knows (wrong case, the table-function spelling `ENGINE = s3(...)`). Both `TABLE ENGINE` checks in `InterpreterCreateQuery` run before `StorageFactory` / `DatabaseFactory` resolve the name, so such a statement failed with `ACCESS_DENIED ... TABLE ENGINE ON <name>`, a grant `GRANT` itself rejects, while a wildcard holder got `UNKNOWN_STORAGE` with the "Maybe you meant" hint. Before each check, an unregistered and ungranted name now throws the factory's own unknown-engine error. Everything else reaches the unchanged check, so the set of statements that succeed is the same and a registered engine without the grant is still denied. An unconditional name check was not used because it would also reject statements that succeed today, such as `CREATE TABLE IF NOT EXISTS <existing> ... ENGINE = memory` for a grant holder. Closes ClickHouse#124614 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the throwIfEngineIsUnknownAndNotGranted comment to a one-line invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 rounds, 1 finding in round 1 split into 2 parts, 0 findings in round 2) plus my own cold reviews.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261008-211900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261008-204400 |
|
Workflow [PR], commit [aecd6fd] Summary: ✅
AI ReviewSummaryThis PR changes Findings
Final Verdict❌ Changes required before merge: the database-engine access bypass still needs to be closed, and the earlier access-order fix is not complete for |
|
|
||
| if (create.storage && create.storage->engine) | ||
| { | ||
| throwIfEngineIsUnknownAndNotGranted(create.storage->engine->name, /*is_database_engine=*/ !create.table, getContext()); |
There was a problem hiding this comment.
Because this runs inside getRequiredAccess, it executes before the normal checkAccess(getRequiredAccess()) call in execute. A user who is also missing earlier rights such as CREATE TABLE, CREATE DATABASE, the DROP_* privilege on a REPLACE, or READ|WRITE ON FILE for ATTACH ... FROM will now get UNKNOWN_STORAGE / UNKNOWN_DATABASE_ENGINE (with hints) instead of the expected ACCESS_DENIED.
That changes the privilege-error order and leaks engine metadata before we've established that the caller may even run this CREATE. Can we keep the unknown-engine shortcut out of getRequiredAccess and run it only after the non-TABLE ENGINE checks have already passed?
There was a problem hiding this comment.
Fixed in 639c59d: the unknown-engine error is now raised only where TABLE ENGINE is the first missing grant, so a missing CREATE TABLE, CREATE DATABASE or CLUSTER is still reported as ACCESS_DENIED.
There was a problem hiding this comment.
The general "only when TABLE ENGINE is the first missing grant" claim still does not hold for ATTACH ... FROM: src/Interpreters/InterpreterCreateQuery.cpp:3991 still calls throwIfEngineIsUnknownAndNotGranted before src/Interpreters/InterpreterCreateQuery.cpp:4000 adds the READ | WRITE ON FILE requirement, so a caller missing those source grants will still see UNKNOWN_STORAGE before the expected ACCESS_DENIED.
… grant The unknown-engine error was thrown from `getRequiredAccess`, before any privilege was checked, so a user also missing an earlier privilege (`CREATE TABLE`, `CREATE DATABASE`, the `DROP` of a replaced table, the `SELECT, INSERT` on a target table, or `CLUSTER` for `CREATE DATABASE ... ON CLUSTER`) got `UNKNOWN_STORAGE` / `UNKNOWN_DATABASE_ENGINE` instead of the `ACCESS_DENIED` master reports for that privilege. Throw it only when every element required before `TABLE ENGINE` is granted, i.e. where master reports the ungrantable `TABLE ENGINE ON <name>`. The `CREATE DATABASE` and legacy-format (`distributed_ddl_entry_format_version` below 3) `CREATE TABLE` `ON CLUSTER` routes check `CLUSTER` first, so there `CLUSTER` is required too; the current-format `CREATE TABLE ... ON CLUSTER` checks `TABLE ENGINE` before `CLUSTER`. The `READ, WRITE ON FILE` of `ATTACH ... FROM` is listed after `TABLE ENGINE`, so master already reported `TABLE ENGINE` first there. The test gains a storage-only `File` control: `URL` is registered in both factories, so it could not catch a lookup in the wrong one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| @@ -3880,7 +3902,18 @@ AccessRightsElements InterpreterCreateQuery::getRequiredAccess() const | |||
| } | |||
|
|
|||
| if (create.storage && create.storage->engine) | |||
There was a problem hiding this comment.
Because this guard only runs when the parser already attached an explicit engine AST, CREATE DATABASE db without ENGINE = ... skips the TABLE ENGINE privilege entirely. getRequiredAccess() returns only CREATE_DATABASE, then createDatabase later fills in the default Atomic engine at src/Interpreters/InterpreterCreateQuery.cpp:356-src/Interpreters/InterpreterCreateQuery.cpp:374 (and short ATTACH DATABASE can load one at src/Interpreters/InterpreterCreateQuery.cpp:343-src/Interpreters/InterpreterCreateQuery.cpp:354) without any follow-up checkAccess(AccessType::TABLE_ENGINE, ...).
So a role that has CREATE DATABASE but no TABLE ENGINE grant can still create an Atomic database simply by omitting the engine clause, which is a privilege bypass on the same surface this PR is tightening. Can we materialize the default database engine before access calculation, or add a second database-engine access check after the default/metadata engine is filled in?
CI finish ledger - 639c59dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All other check runs passed. Session id: cron:our-pr-ci-monitor:20261009-070003 |
…lesystem_cache` off parallel replicas In the `ParallelReplicas` CI configuration every query runs with parallel replicas, and the coordinator hands the marks to whichever replica asks first. When the remote replicas read all of them, the cache, file descriptor and throttler `ProfileEvents` land on their own `query_log` rows (`is_initial_query = 0`, `current_database = 'default'`), which the test's `current_database = currentDatabase()` filter drops, so the initiator row shows `CachedReadBufferReadFromCacheBytes = 0` and the throttler check compares `0 <= 0`. Observed in the failing job's `query_log` (PR ClickHouse#124753, arm_binary ParallelReplicas): the initiator read 0 marks, the two remote rows read 1 + 28 marks with 12268 + 1409476 cache bytes. Pin `enable_parallel_replicas = 0` on the measured read only, as ClickHouse#124528 did for the columns cache tests, so both columns are evaluated on the row that did the read. The warm-up read is unchanged: the replicas are the same server process and warm the same filesystem cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai Merge the master again, let's try our luck |
…-before-table-engine-grant
|
Merged master in aecd6fd (no conflicts, the PR's own diff is unchanged). CI is running on the new head. |
Closes: #124614
Related: #100746
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
An unregistered engine name in
CREATE TABLEorCREATE DATABASE(for exampleENGINE = memory,ENGINE = atomicor the table-function spellingENGINE = s3(...)) is now reported asUNKNOWN_STORAGE/UNKNOWN_DATABASE_ENGINEwith the "Maybe you meant" hint for users without a wildcardTABLE ENGINEgrant, instead ofACCESS_DENIEDfor aTABLE ENGINE ON <name>grant that cannot be given.Description
Since #100746 (26.5), implicit
TABLE ENGINEgrants are per registered engine name, so a user withoutTABLE ENGINE ON *has none for a misspelled name.InterpreterCreateQuerychecksTABLE ENGINE ON <name as written>beforeStorageFactory/DatabaseFactoryresolve the name, soCREATE TABLE t (x Int32) ENGINE = memoryfails withACCESS_DENIED ... TABLE ENGINE ON memory, a grant thatGRANTitself rejects, while a user holding the wildcard getsUnknown table engine memory. Maybe you meant: ['Memory'].Change. At both places
InterpreterCreateQuerychecksTABLE ENGINE(getRequiredAccessand the re-check aftersetEngine, which also covers shortATTACHandRESTORE), a name that is not registered in the relevant factory and not granted now throws the factory's own unknown-engine error, unless a privilege checked earlier (such asCREATE TABLEorCLUSTER) is also missing, which is still reported first. Every other case reaches the unchanged check: the same statements succeed, and a registered engine without the grant is stillACCESS_DENIED.I kept it conditional so that it is safe to backport: an unconditional name check would also reject statements that succeed today, such as
CREATE TABLE IF NOT EXISTS <existing> ... ENGINE = memoryfor a user holding the grant. I can make it unconditional if you prefer.Validation. New stateless test (wrong case, table-function spelling, a database engine,
ON CLUSTER, three registered-engineACCESS_DENIEDcontrols, users missingCREATEorCLUSTER, and theIF NOT EXISTSno-op for a grant holder) fails on master and passes 50/50 randomized, withtable_engines_require_grantbothfalse(the default) andtrue;test_grant_and_revokeand the neighbouring access tests pass.Not changed here:
GRANT TABLE ENGINE ON Atomic(or any other engine registered only inDatabaseFactory) is rejected withUNKNOWN_STORAGE, becauseInterpreterGrantQueryvalidates the name againstStorageFactoryonly. I can fix that separately if you want.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124753]
Version info
26.10.1.2503-master(included in26.10and later)