Skip to content

Backport #115914 to 26.7: check the target engine's grant when ATTACH carries a URL engine definition - #115966

Merged
clickhouse-gh[bot] merged 1 commit into
ClickHouse:26.7from
groeneai:backport-115914-26.7
Aug 23, 2026
Merged

clickhouse-gh[bot] merged 1 commit into
ClickHouse:26.7from
groeneai:backport-115914-26.7

Conversation

@groeneai

@groeneai groeneai commented Aug 23, 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):

Fixed a TABLE ENGINE privilege bypass in the URL table engine. A user granted only TABLE ENGINE ON URL could ATTACH TABLE ... ENGINE = URL('file://...') (or s3://, az://, hdfs://) and read through it, because the privilege re-check on the backend the scheme dispatches to ran only for CREATE. It now runs for every statement that supplies a fresh definition, ATTACH and RESTORE included, while a definition replayed from the server's own metadata stays exempt so existing tables keep loading.

Description

Backport of #115914 to 26.7. 26.7 is the only active release branch affected: URL scheme dispatch does not exist on 25.8, 26.3, 26.5 or 26.6, where a URL('file://...') read fails Code: 36, Unknown protocol in the URL.

The robot cherry-pick #115950 is CONFLICTING, but only in the two test files, and only because master renamed 04401_url_engine_s3_dispatch.sh to 04401_url_engine_s3_dispatch_engine_grant.sh, which makes the pair a modify/delete here. StorageURL.cpp itself merges cleanly: tryDispatchURLEngineByScheme is byte-identical between master and 26.7, so the fix hunk applies unchanged. This is that resolved tree as a single commit on the 26.7 tip.

The bypass reproduces on the released 26.7.6.8: as a user holding only URL and TABLE ENGINE ON URL, the CREATE and a direct ENGINE = File(...) ATTACH are both denied Code: 497, while ATTACH TABLE ... ENGINE = URL('file://.../secret.csv') is accepted and the following SELECT returns the file contents.

Validated in both directions against a server configured like the stateless one, after asserting live that table_engines_require_grant denies a no-grant user and that the backups disk accepts a backup. On 26.7.6.8 the ported test fails on exactly attach-file-engine-denied, attach-azure-engine-denied, restore-file-engine-denied and restore-rejected-not-created, the same four lines it inverted against pre-fix master; on the fixed build it passes with no diff. So the port is not a silent no-op.

I opened this from my fork because I have no push access to this repository, which is where the cherrypick/26.7/115914 branch lives, so its conflicts cannot be resolved in place. Same route as #112916 and #112899.

Version info

  • Merged into: 26.7.6.9

…hen ATTACH carries a URL engine definition

The URL engine dispatches by scheme to File/S3/AzureBlobStorage/HDFS. The
delegate's TABLE ENGINE privilege was re-checked only when the mode was
CREATE, so a user holding TABLE ENGINE ON URL alone could ATTACH a table with
a full URL('file://...') definition and then read it, while the equivalent
CREATE and a direct ENGINE = File(...) ATTACH were both denied. The outer
engine check is not mode-gated, so the inner one was the only gap.

The predicate now exempts only a definition replayed from this server's own
metadata: server startup, force-restore, a short ATTACH TABLE t, and the
tables an ATTACH DATABASE loads. Those were validated when the table was
created and must stay loadable after a revoke. Every other statement, ATTACH
with a definition and RESTORE included, supplies a fresh definition and is
checked.

The cherry-pick ClickHouse#115950 conflicts only because master renamed
04401_url_engine_s3_dispatch.sh to 04401_url_engine_s3_dispatch_engine_grant.sh,
which makes the pair a modify/delete on this branch. The source hunk applies
unchanged: tryDispatchURLEngineByScheme is byte-identical between master and
26.7. This is that resolved tree as a single commit on the 26.7 tip.

Validated in both directions on a server configured like the stateless one,
after asserting that table_engines_require_grant denies a no-grant user and
that the backups disk accepts a backup. Against the released 26.7.6.8 binary
the test fails on attach-file-engine-denied, attach-azure-engine-denied,
restore-file-engine-denied and restore-rejected-not-created, the same four
lines it inverted against pre-fix master; against the fixed build it passes
with no diff. The bypass itself reproduces on 26.7.6.8: ATTACH of a
URL('file://...') table is accepted and the following SELECT returns the file
contents, while both the CREATE and a direct File engine ATTACH are denied.

The four older branches are unaffected and need no backport: URL scheme
dispatch does not exist there, so a URL('file://...') read fails with
Code: 36, Unknown protocol in the URL.
@clickhouse-gh

clickhouse-gh Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [8642b76]

Summary: ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant