Skip to content

Report an unknown engine name in CREATE as unknown instead of as a missing TABLE ENGINE grant - #124753

Merged
evillique merged 4 commits into
ClickHouse:masterfrom
groeneai:unknown-engine-name-before-table-engine-grant
Oct 15, 2026
Merged

evillique merged 4 commits into
ClickHouse:masterfrom
groeneai:unknown-engine-name-before-table-engine-grant

Conversation

@groeneai

@groeneai groeneai commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #124614
Related: #100746

Changelog category (leave one):

  • Improvement

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

An unregistered engine name in CREATE TABLE or CREATE DATABASE (for example ENGINE = memory, ENGINE = atomic or the table-function spelling ENGINE = s3(...)) is now reported as UNKNOWN_STORAGE / UNKNOWN_DATABASE_ENGINE with the "Maybe you meant" hint for users without a wildcard TABLE ENGINE grant, instead of ACCESS_DENIED for a TABLE ENGINE ON <name> grant that cannot be given.

Description

Since #100746 (26.5), implicit TABLE ENGINE grants are per registered engine name, so a user without TABLE ENGINE ON * has none for a misspelled name. InterpreterCreateQuery checks TABLE ENGINE ON <name as written> before StorageFactory / DatabaseFactory resolve the name, so CREATE TABLE t (x Int32) ENGINE = memory fails with ACCESS_DENIED ... TABLE ENGINE ON memory, a grant that GRANT itself rejects, while a user holding the wildcard gets Unknown table engine memory. Maybe you meant: ['Memory'].

Change. At both places InterpreterCreateQuery checks TABLE ENGINE (getRequiredAccess and the re-check after setEngine, which also covers short ATTACH and RESTORE), 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 as CREATE TABLE or CLUSTER) 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 still ACCESS_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 = memory for 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-engine ACCESS_DENIED controls, users missing CREATE or CLUSTER, and the IF NOT EXISTS no-op for a grant holder) fails on master and passes 50/50 randomized, with table_engines_require_grant both false (the default) and true; test_grant_and_revoke and the neighbouring access tests pass.

Not changed here: GRANT TABLE ENGINE ON Atomic (or any other engine registered only in DatabaseFactory) is rejected with UNKNOWN_STORAGE, because InterpreterGrantQuery validates the name against StorageFactory only. I can fix that separately if you want.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.2503-master (included in 26.10 and later)

groeneai and others added 2 commits October 8, 2026 21:15
…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 8, 2026
@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author
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.

# Sev Finding Verdict Evidence / action
1 ⚠️ The test does not kill the grant escape in throwIfEngineIsUnknownAndNotGranted, so the unconditional variant would stay green AGREE, fixed @ 7982dfc IF NOT EXISTS no-op arms for a grant holder; removing the escape fails exactly those two lines
2 ⚠️ The test does not reach the post-setEngine call DISAGREE proven live by a short ATTACH of a stored ENGINE = memory definition (master ACCESS_DENIED, fix UNKNOWN_STORAGE); the only SQL route left is the private-preview TimeSeries inner engines, whose syntax differs on each backport target
3 💡 GRANT TABLE ENGINE ON Atomic (database-only engines) is rejected AGREE, disclosed in the PR body different statement; not changed here
4 💡 Hintless database message lacks the factory's colon DROPPED same error code

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

Session id: cron:clickhouse-review-slot-11:20261008-211900

@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The issue's SQL on a default-config server: ENGINE = memory, ENGINE = s3(...), CREATE DATABASE ... ENGINE = atomic fail with ACCESS_DENIED ... TABLE ENGINE ON <name> on master every time; the new test fails on master with both table_engines_require_grant values.
b Root cause explained? InterpreterCreateQuery checks TABLE ENGINE ON <name as written> before StorageFactory / DatabaseFactory resolve the name. Since #100746 implicit grants are per registered name, so an unregistered name has no grant and the access check fails first, naming a grant GRANT itself rejects.
c Fix matches root cause? Yes. Both TABLE ENGINE check sites resolve the name first when the check is going to fail anyway, and throw the factory's own unknown-engine error. No access is relaxed.
d Test intent preserved / new tests added? New stateless test: wrong-case table and database engine names, the table-function spelling, two registered-engine ACCESS_DENIED controls, and two IF NOT EXISTS no-ops on an existing table and database for a user holding the grant.
e Both directions demonstrated? Yes: master fails / fix passes in both config modes, also for a short ATTACH of an edited definition (the re-check site). Removing the access checks flips both controls, and removing the grant escape flips both IF NOT EXISTS arms, so they are live. 50/50 randomized runs pass.
f Fix is general across code paths? Both places that check TABLE ENGINE on a user-written name: getRequiredAccess (CREATE/ATTACH TABLE and DATABASE, temporary tables, ON CLUSTER initiator) and the re-check after setEngine (short ATTACH, RESTORE).
g Fix generalizes across inputs (params/datatypes/wrappers)? Wrong case, table-function spelling, table and database engines, registered controls, both table_engines_require_grant modes, IF NOT EXISTS. Type wrappers: N/A (engine names are strings).
h Backward compatible? (maintainer-approved exception only) Yes. No setting. The set of statements that succeed is unchanged; only the error of statements that already fail changes.
i Invariants and contracts preserved? The helper only throws or falls through to the unchanged check, so a registered engine without the grant is still ACCESS_DENIED. It runs before any side effect.

Session id: cron:clickhouse-impl-slot-4:20261008-204400

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aecd6fd]

Summary: ✅


AI Review

Summary

This PR changes InterpreterCreateQuery so unknown ENGINE = ... names surface the factories' UNKNOWN_STORAGE / UNKNOWN_DATABASE_ENGINE errors instead of an impossible TABLE ENGINE grant error. The main explicit-engine paths look reasonable, but the access-control contract is still incomplete: CREATE DATABASE / short ATTACH DATABASE without an explicit engine still bypass TABLE ENGINE, and the earlier privilege-order fix is still incomplete for ATTACH ... FROM.

Findings
  • ❌ Blocker — [src/Interpreters/InterpreterCreateQuery.cpp:3982] TABLE ENGINE is still required only when the parser already attached an explicit engine AST. CREATE DATABASE db and short ATTACH DATABASE db therefore pass checkAccess(getRequiredAccess()) with only CREATE_DATABASE, then createDatabase fills in Atomic or loads the stored engine at src/Interpreters/InterpreterCreateQuery.cpp:347 and src/Interpreters/InterpreterCreateQuery.cpp:360 without any follow-up TABLE ENGINE check. A role that has CREATE DATABASE but no engine grant can still create or attach a database simply by omitting the engine clause, and ON CLUSTER magnifies it because the worker legs run without the original user. Materialize the database engine before access calculation, or add a second checkAccess(AccessType::TABLE_ENGINE, ...) after the default/metadata engine is filled in.
  • ⚠️ Major — [src/Interpreters/InterpreterCreateQuery.cpp:3991] The "unknown engine only when TABLE ENGINE is the first missing grant" invariant is still false for ATTACH TABLE ... FROM. The helper runs before src/Interpreters/InterpreterCreateQuery.cpp:4000 appends the READ | WRITE ON FILE requirement, so a caller missing those source grants still gets UNKNOWN_STORAGE first. Either include the file-source requirement in required_before for the has_attach_from_path case, or delay the unknown-engine shortcut until after the file access requirement has been established.
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 ATTACH ... FROM.

@evillique evillique self-assigned this Oct 8, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Oct 8, 2026

if (create.storage && create.storage->engine)
{
throwIfEngineIsUnknownAndNotGranted(create.storage->engine->name, /*is_database_engine=*/ !create.table, getContext());

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.

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?

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.

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.

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.

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)

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.

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?

@groeneai

groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 639c59d

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
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05230_materialized_cte_shared_by_two_ctes_in_set_subquery flaky, not from this PR (which changes InterpreterCreateQuery.cpp): Code: 60 ... Unknown table expression identifier '_materialized_cte_d_<hash>' on a reused MATERIALIZED CTE under parallel replicas (issue #112642). Reruns 106/106 passed #123121 (mine, open)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05317_local_read_throttler_filesystem_cache flaky in the parallel replicas lane (result differs from the reference), not from this PR, which does not touch the filesystem cache or the read throttler. Reruns 72/72 passed #124920 (mine, open)
Mergeable Check, PR praktika rollups of the two rows above (Failed: Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)), no independent failure #123121 (mine, open), and #124920 (mine, open) for 05317
Sync - CH Inc sync (private, not actionable by me)

All other check runs passed.

Session id: cron:our-pr-ci-monitor:20261009-070003

jh0x pushed a commit to jh0x/ClickHouse that referenced this pull request Oct 11, 2026
…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]>
@evillique

Copy link
Copy Markdown
Member

@groeneai Merge the master again, let's try our luck

@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master in aecd6fd (no conflicts, the PR's own diff is unchanged). CI is running on the new head.

@evillique
evillique added this pull request to the merge queue Oct 15, 2026
Merged via the queue into ClickHouse:master with commit ae8f0be Oct 15, 2026
177 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
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 comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-improvement Pull request with some product improvements 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.

Unknown table/database engine name in CREATE is reported as ACCESS_DENIED instead of UNKNOWN_STORAGE for users without a wildcard TABLE ENGINE grant

4 participants