Repository navigation
Require the whole ALTER TABLE grant to imply ALTER VIEW - #118194
alexey-milovidov merged 1 commit into
Conversation
`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.
Internal second-model review — 1 nit, no code changes
💡 Also checked, no change needed: |
|
Workflow [PR], commit [b6161e7] Summary: ✅
AI ReviewSummaryThis PR fixes the Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit b6161e7.
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
|
cc @vitlibar @pufit, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
5dc7c33
Backport #118194 to 26.6: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
Backport #118194 to 26.3: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
Backport #118194 to 26.7: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
Backport #118194 to 26.8: Require the whole `ALTER TABLE` grant to imply `ALTER VIEW`
…rant to imply `ALTER VIEW`
…rant to imply `ALTER VIEW`
…rant to imply `ALTER VIEW`
Related: #14674
Changelog category (leave one):
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 TABLEgroup (for exampleALTER MODIFY COMMENT) on a view implicitly conferred the entireALTER VIEWgroup, so such a user could runALTER TABLE <view> MODIFY QUERYand rewrite the view's query.ALTER VIEWis now implied only by the completeALTER TABLEgrant. A deployment that relied on a partialALTER TABLEgrant to alter views must now grantALTER VIEW(or one of its members) or the fullALTER TABLEexplicitly.Description
ContextAccess::addImplicitAccessRightstested whether the effective rights overlap theALTER TABLEmask before implyingALTER VIEW:if (res & alter_table) res |= alter_view;AccessFlags::operator boolis!isEmpty(), andALTER TABLEis aGROUPwhose bitmask is the union of its 17 children, so holding any one child satisfied the test. A user granted onlyALTER MODIFY COMMENTon a view therefore received the wholeALTER VIEWgroup, andALTER VIEW MODIFY QUERYis the privilege thatALTER TABLE <view> MODIFY QUERYdeclares (InterpreterAlterQuery.cpp), so that user could rewrite the view's query. A user holding noALTER-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, soGRANT ALTER UPDATE ON db.*conferredALTER VIEW MODIFY QUERYon every view indb.The intended semantics is containment, and
AccessType.halready documentsALTER VIEWas "implicitly enabled by the grant ALTER_TABLE", i.e. the group grant. The fix usesAccessFlags::contains. The siblingCREATE TABLEandDROP TABLEimplications are deliberately left alone: both antecedents are leaf flags with 0 children, socontainsthere 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 VIEWmembers are refused, andALTER VIEWdisappears fromSHOW GRANTS ... WITH IMPLICIT. Column-level and role-split behaviour is unchanged.This does not close #14674: a legitimate holder of
ALTER VIEW MODIFY QUERYon aSQL SECURITY DEFINERview can still read through it, because table functions bypass the per-tableSELECTcheck.Workflow [PR]
Sync PR [sync-upstream/pr/118194]
Version info
26.8.3.79,26.7.7.68,26.6.5.56,26.3.32.13