Skip to content

Fix table engine grants - #98984

Merged
pufit merged 6 commits into
ClickHouse:masterfrom
pufit:pufit/fix-table-engine-grants
Mar 23, 2026
Merged

pufit merged 6 commits into
ClickHouse:masterfrom
pufit:pufit/fix-table-engine-grants

Conversation

@pufit

@pufit pufit commented Mar 8, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Replace the hardcoded source_table_engines list with a runtime lookup via StorageFactory::getAllStorages().
This adds access checks for some missing table engines and closes #71544


Note

Medium Risk
Touches privilege/authorization logic by changing how TABLE_ENGINE is implicitly granted based on source READ/WRITE, which could unintentionally broaden or restrict engine usage if misapplied. Adds integration coverage, but behavior changes affect security-sensitive access checks.

Overview
Fixes implicit TABLE_ENGINE privilege derivation by removing the hardcoded source_table_engines list and instead iterating StorageFactory::getAllStorages() to map each engine’s registered source_access_type to READ/WRITE source grants.

Adjusts the sync logic to only add grants (no revokes) to avoid stripping WITH GRANT OPTION state when computing implicit rights (regression noted in #71544).

Extends integration tests to cover source-grant→engine access bridging, source revocation blocking engine usage, and preserving GRANT TABLE ENGINE ... WITH GRANT OPTION behavior under both table-engine-grant enabled/disabled configs.

Written by Cursor Bugbot for commit e47a373. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.4.1.155

@clickhouse-gh

clickhouse-gh Bot commented Mar 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bf67746]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug) failure
Logical error: Unexpected number of columns in result sample block: A expected B ([C] = [D] + [E] + [F]) (STID: 2980-385f) FAIL cidb, issue ISSUE EXISTS
AST fuzzer (arm_asan_ubsan) failure
AddressSanitizer: stack-use-after-scope (STID: 2136-3203) FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR replaces a hardcoded source-engine mapping with StorageFactory::getAllStorages() when deriving implicit TABLE_ENGINE rights from source READ/WRITE grants, and adds tests for grant/revoke bridging and WITH GRANT OPTION. The current PR head addresses earlier regressions around source-name round-trip (ARROW FLIGHT) and revoke-path coverage; I did not find additional high-confidence correctness, safety, or compatibility issues in the changed code.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Mar 8, 2026
@pufit
pufit marked this pull request as ready for review March 8, 2026 16:39
@SmitaRKulkarni SmitaRKulkarni self-assigned this Mar 9, 2026

@SmitaRKulkarni SmitaRKulkarni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@pufit pufit mentioned this pull request Mar 13, 2026
1 task
Comment thread src/Access/Common/AccessType.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.70% 83.70% +0.00%
Functions 24.00% 24.00% +0.00%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 100.00% (56/56, 1 noise lines excluded)
Diff coverage report
Uncovered code

@pufit
pufit added this pull request to the merge queue Mar 23, 2026
Merged via the queue into ClickHouse:master with commit 48c3107 Mar 23, 2026
146 of 148 checks passed
@pufit
pufit deleted the pufit/fix-table-engine-grants branch March 23, 2026 19:26
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 23, 2026
@pufit pufit added the pr-backward-incompatible Pull request with backwards incompatible changes label Mar 24, 2026
zlareb1 added a commit that referenced this pull request Mar 25, 2026
…rants

PR #98984 replaced a hardcoded source engine list with `getAllStorages()`,
which incorrectly included database engines (e.g. `Shared` in ClickHouse
Cloud) in the `TABLE ENGINE` grant check. This caused `CREATE DATABASE`
to fail with `ACCESS_DENIED` even when `table_engines_require_grant = false`.

Adds `test_create_database_does_not_require_table_engine_grant` to both
`test_with_table_engine_grant.py` and `test_without_table_engine_grant.py`
to verify that `CREATE DATABASE` (with default `Atomic` engine or explicit
`ENGINE = Atomic`) succeeds with only `CREATE DATABASE` privilege and no
`TABLE ENGINE` grants, regardless of the `table_engines_require_grant` setting.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
zlareb1 added a commit that referenced this pull request Mar 25, 2026
With `table_engines_require_grant = true`, `TABLE ENGINE ON Atomic` was
never implicitly granted — before PR #98984, after it, or after the revert.
The test would fail on all three states, so it tests behaviour that was
never supported and adds no regression signal.

The test in `test_without_table_engine_grant.py` (setting=false) is the
correct regression test: before PR #98984 the wildcard `TABLE_ENGINE ON *`
grant covered database engines like `Atomic`; after PR #98984 only
StorageFactory engines are granted individually, leaving `Atomic` uncovered.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
pufit added a commit that referenced this pull request Mar 25, 2026
Re-introduce dynamic engine lookup from StorageFactory (replacing the
hardcoded source_table_engines list) and additionally grant database
engines from DatabaseFactory when table_engines_require_grant=false.

The previous attempt (#98984) missed database engines (Atomic, Shared,
Replicated, etc.) which are registered in DatabaseFactory, not
StorageFactory.  CREATE DATABASE checks TABLE_ENGINE access in
InterpreterCreateQuery, so omitting them caused ACCESS_DENIED on
CREATE DATABASE.

Closes #71544
@yariks5s yariks5s added the post-approved Approved, but after the PR is merged. label Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-approved Approved, but after the PR is merged. pr-backward-incompatible Pull request with backwards incompatible changes 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.

RBAC: GRANT TABLE ENGINE ON * fails with table_engines_require_grant=false

5 participants