Skip to content

Require the whole ALTER TABLE grant to imply ALTER VIEW - #118194

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai-alter-view-implicit-grant-containment
Sep 5, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai-alter-view-implicit-grant-containment

Conversation

@groeneai

@groeneai groeneai commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #14674

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 privilege escalation in implicit access-rights computation: holding any single child privilege of the ALTER TABLE group (for example ALTER MODIFY COMMENT) on a view implicitly conferred the entire ALTER VIEW group, so such a user could run ALTER TABLE <view> MODIFY QUERY and rewrite the view's query. ALTER VIEW is now implied only by the complete ALTER TABLE grant. A deployment that relied on a partial ALTER TABLE grant to alter views must now grant ALTER VIEW (or one of its members) or the full ALTER TABLE explicitly.

Description

ContextAccess::addImplicitAccessRights tested whether the effective rights overlap the ALTER TABLE mask before implying ALTER VIEW:

if (res & alter_table)
    res |= alter_view;

AccessFlags::operator bool is !isEmpty(), and ALTER TABLE is a GROUP whose bitmask is the union of its 17 children, so holding any one child satisfied the test. A user granted only ALTER MODIFY COMMENT on a view therefore received the whole ALTER VIEW group, and ALTER VIEW MODIFY QUERY is the privilege that ALTER TABLE <view> MODIFY QUERY declares (InterpreterAlterQuery.cpp), so that user could rewrite the view's query. A user holding no ALTER-family grant is correctly refused the same statement, so the check was genuinely bypassed rather than absent. The modifier also runs at every node of the rights tree, so GRANT ALTER UPDATE ON db.* conferred ALTER VIEW MODIFY QUERY on every view in db.

The intended semantics is containment, and AccessType.h already documents ALTER VIEW as "implicitly enabled by the grant ALTER_TABLE", i.e. the group grant. The fix uses AccessFlags::contains. The sibling CREATE TABLE and DROP TABLE implications are deliberately left alone: both antecedents are leaf flags with 0 children, so contains there is a provable no-op.

Validation: a new stateless test whose two escalation arms fail before the fix and pass after, plus four controls that pass on both binaries. Measured separately on both builds: all 17 children of the group flip from allowed to denied, all three ALTER VIEW members are refused, and ALTER VIEW disappears from SHOW GRANTS ... WITH IMPLICIT. Column-level and role-split behaviour is unchanged.

This does not close #14674: a legitimate holder of ALTER VIEW MODIFY QUERY on a SQL SECURITY DEFINER view can still read through it, because table functions bypass the per-table SELECT check.


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

Version info

  • Backported to: 26.8.3.79, 26.7.7.68, 26.6.5.56, 26.3.32.13

`ContextAccess::addImplicitAccessRights` tested whether the effective rights
overlap the `ALTER TABLE` mask before implying `ALTER VIEW`:

    if (res & alter_table)
        res |= alter_view;

`AccessFlags::operator&` returns the intersection and `AccessFlags::operator bool`
is `!isEmpty()`, so this was an overlap test: true whenever the rights shared any
single bit with the mask. `ALTER TABLE` is a `GROUP`, and `Node::addChild` unions
each child's flags into its parent, so the group's mask is the union of its 17
children. Holding one child, for example the metadata-only `ALTER MODIFY COMMENT`,
therefore conferred all three members of the `ALTER VIEW` group, and those flags
are the only gate on `ALTER TABLE <view> MODIFY QUERY`. A user holding no
`ALTER`-family grant is correctly refused that statement, so the privilege check
was bypassed rather than absent.

The modifier runs at every node of the rights tree, so a database-wide grant
behaved the same way: `GRANT ALTER UPDATE ON db.*` conferred
`ALTER VIEW MODIFY QUERY` on every view in `db`.

The intended semantics is containment, which `AccessType.h` already documents by
describing `ALTER VIEW` as implicitly enabled by the grant `ALTER_TABLE`, meaning
the group grant rather than one member of it. `AccessFlags::contains` is that
test, so use it here.

The sibling `CREATE TABLE` and `DROP TABLE` implications are left unchanged on
purpose. Both antecedents are leaf flags with no children, so `contains` there
would be a provable no-op that no test could distinguish from the current code.

This removes an implicit privilege, so a deployment that granted a strict subset
of `ALTER TABLE` and relied on it to alter views must now grant `ALTER VIEW`, one
of its members, or the full `ALTER TABLE` explicitly.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Sep 5, 2026
@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — 1 nit, no code changes

⚠️ nit Switch the changelog category to Critical Bug Fix (crash, data loss, RBAC), since the PR
template names RBAC there. Not applied. Critical Bug Fix is not one of the section headings
CHANGELOG.md actually renders (the seven are Backward Incompatible Change, New Feature,
Experimental Feature, Performance Improvement, Improvement, Bug Fix (user-visible misbehavior in an official stable release), Build/Testing/Packaging Improvement), and the comparable fixes
there ship under Bug Fix: #94865 (ATTACH of a view with SQL security, "prevents potential
privilege escalation"), #99122 and #114596 (RBAC bypasses). Happy to change it if a maintainer
prefers.

💡 Also checked, no change needed: ALTER_TABLE is the only group-flag antecedent among the 17
flag-shaped tests in addImplicitAccessRights, so the one-line scope is complete; the remaining
overlap tests in that file gate the requested privilege against a forbidden class, where overlap
is the fail-close direction; and contains implies the old overlap test for a non-empty mask, so
nothing previously denied can now be allowed.

@clickhouse-gh clickhouse-gh Bot closed this Sep 5, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b6161e7]

Summary: ✅


AI Review

Summary

This PR fixes the ALTER TABLE/ALTER VIEW implicit-grant bug in ContextAccess::addImplicitAccessRights by requiring full containment of the ALTER_TABLE flag set before adding ALTER_VIEW, and it adds a focused stateless regression test for both object-level and database-level grants. I did not find a remaining correctness, RBAC, or test-coverage issue in the patched paths, and the PR’s CI is fully green.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Measured on commit b6161e7.

Metric Baseline Current Δ
Lines 88.70% 88.70% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 81.10% 81.10% +0.00%

Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @vitlibar @pufit, could you review this? addImplicitAccessRights tested res & alter_table before implying ALTER VIEW, and because AccessFlags::operator bool is !isEmpty() while ALTER TABLE is a group whose mask is the union of its children, holding a single child such as ALTER MODIFY COMMENT on a view conferred the whole ALTER VIEW group and let that user run ALTER TABLE <view> MODIFY QUERY. The fix uses contains so only the complete ALTER TABLE grant implies it.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 5, 2026
@pufit pufit self-assigned this Sep 5, 2026
@pufit pufit added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Sep 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b6161e703 with master 21e50a601 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of fd607f937; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 5, 2026
Merged via the queue into ClickHouse:master with commit 5dc7c33 Sep 5, 2026
174 of 344 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 5, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 5, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 5, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 5, 2026
Backport #118194 to 26.6: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
alexey-milovidov added a commit that referenced this pull request Sep 5, 2026
Backport #118194 to 26.3: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
PedroTadim added a commit that referenced this pull request Sep 10, 2026
Backport #118194 to 26.7: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
PedroTadim added a commit that referenced this pull request Sep 10, 2026
Backport #118194 to 26.8: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 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-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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 Materialized Views - MODIFY QUERY requires less privileges than CREATE MATERIALIZED VIEW

5 participants