Skip to content

Require drop privileges when restoring replacement access entities - #127136

Merged
kolsha merged 2 commits into
masterfrom
codex/restore-access-full-privileges
Oct 22, 2026
Merged

kolsha merged 2 commits into
masterfrom
codex/restore-access-full-privileges

Conversation

@kolsha

@kolsha kolsha commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RESTORE with create_access='replace' could overwrite access entities while checking only their CREATE privileges. Require the corresponding DROP privilege, including when the target does not exist, matching CREATE ... OR REPLACE. Preserve the appropriate scope for users, roles, row policies, settings profiles, quotas, and masking policies in Cloud builds.

Combine independent restoration requirements with AccessRights::makeUnion so partial revokes in backed-up grants cannot remove privileges required to restore other entities or tables. Restoring grants also requires GRANT OPTION, even when the backed-up entity does not have it.

Regression tests cover row-policy replacement, user/role partial revokes, grant-option checks, and table restoration. They reuse the existing backup integration fixture because access backups include every entity of a requested type and need an isolated access store. The first commit contains the tests; the second contains the complete fix, including the existing CLICKHOUSE_CLOUD masking-policy branch.

Supersedes the incomplete version below.

Related: #127128

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):

Fix insufficient privilege checks when restoring access entities. Replacement with create_access='replace' now requires the corresponding DROP privilege, and partial revokes in a backup cannot reduce the privileges required for restoration.


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

Version info

  • Merged into: 26.11.1.517-master (included in 26.11 and later)
  • Backported to: 26.10.2.77, 26.9.26.3, 26.8.35.7, 26.3.61.8

Cover replacement without scoped `DROP`, partial revokes cancelling independent requirements, and missing `GRANT OPTION` when restoring grants.

Use the existing backup integration fixture because access backups include every entity of the requested type, making shared stateless access state unsuitable for these checks.
Require the corresponding scoped `DROP` privilege for `create_access='replace'`, matching `CREATE ... OR REPLACE` even when the target does not exist. Include `DROP_MASKING_POLICY` for the existing `CLICKHOUSE_CLOUD` branch.

Build grant requirements separately and combine independent requirements with `AccessRights::makeUnion` so partial revokes cannot remove permissions required by other entities or tables. Restoring a grant requires `GRANT OPTION` even when the backed-up entity lacks it.

Related: #127128
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4a4b936]

Summary: ✅


AI Review

Summary

This PR tightens RESTORE privilege checks for replacement of access entities and for restoring backed-up grants that include partial revokes. I reviewed the changed access-check paths in src/Access/AccessBackup.cpp and src/Backups/RestorerFromBackup.cpp, cross-checked the matching CREATE ... OR REPLACE privilege rules, and did not find any remaining correctness, security, or compatibility issues in the current patch.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 21, 2026
@kolsha
kolsha marked this pull request as ready for review October 21, 2026 09:02
@clickhouse-gh clickhouse-gh Bot added the comp-backup Backup/restore infrastructure and backup formats. label Oct 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4a4b9363d with master 1177311f7 (stripped binary size, per-symbol sizes and ThinLTO time; 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

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

Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -2.2 s (-5%) in total before that adjustment.

Job report

@jkartseva jkartseva self-assigned this Oct 22, 2026

@jkartseva jkartseva 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

@jkartseva jkartseva added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 22, 2026
@kolsha
kolsha added this pull request to the merge queue Oct 22, 2026
Merged via the queue into master with commit 01e72bd Oct 22, 2026
179 checks passed
@kolsha
kolsha deleted the codex/restore-access-full-privileges branch October 22, 2026 08:29
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 22, 2026
Backport #127136 to 26.10: Require drop privileges when restoring replacement access entities
jkartseva added a commit that referenced this pull request Oct 22, 2026
The one conflict is the `MaskingPolicy::TYPE` branch of `getRequiredAccess`, which `26.9` does not
have: it was added to `master` after the branch point and is therefore in the base the cherry-pick was
taken from, not in what #127136 changes. The branch keeps its five cases and the throwing `default`.

`MaskingPolicy` itself does exist in `26.9` (the header, `AccessEntityType::MASKING_POLICY` and the
three access types), but the switch branch is `#if CLICKHOUSE_CLOUD`, so its absence does not change
an open-source build. The other five entity types get the `DROP` requirement as upstream.

Co-Authored-By: Claude Opus 5 <[email protected]>
robot-clickhouse added a commit that referenced this pull request Oct 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 22, 2026
Backport #127136 to 26.9: Require drop privileges when restoring replacement access entities
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 23, 2026
Cherry pick #127136 to 26.3: Require drop privileges when restoring replacement access entities
robot-clickhouse added a commit that referenced this pull request Oct 23, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 23, 2026
Cherry pick #127136 to 26.7: Require drop privileges when restoring replacement access entities
robot-clickhouse added a commit that referenced this pull request Oct 23, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 23, 2026
Cherry pick #127136 to 26.8: Require drop privileges when restoring replacement access entities
robot-clickhouse added a commit that referenced this pull request Oct 23, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #127136 to 26.8: Require drop privileges when restoring replacement access entities
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #127136 to 26.7: Require drop privileges when restoring replacement access entities
alexey-milovidov added a commit that referenced this pull request Oct 24, 2026
Backport #127136 to 26.3: Require drop privileges when restoring replacement access entities
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-backup Backup/restore infrastructure and backup formats. 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.

5 participants