Skip to content

Require drop privileges when restoring replacement access entities - #127128

Closed
kolsha wants to merge 2 commits into
masterfrom
codex/restore-access-drop-privileges
Closed

kolsha wants to merge 2 commits into
masterfrom
codex/restore-access-drop-privileges

Conversation

@kolsha

@kolsha kolsha commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by the complete fix, including the CLICKHOUSE_CLOUD masking-policy branch, in the pull request below.

Related: #127136

RESTORE with create_access='replace' could overwrite access entities while checking only their CREATE privileges. Require the corresponding scoped DROP privilege, including when the target does not exist, matching CREATE ... OR REPLACE.

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.

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/127128]

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 `DROP` privilege for `create_access='replace'`, matching `CREATE ... OR REPLACE` even when the target does not exist.

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.
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e74b53f]


AI Review

Summary

The PR requires DROP privileges for replacement access restores and unions independent privilege requirements so backed-up partial revokes cannot cancel them. ❌ Block: the replacement check still omits Cloud masking policies.

Missing context / blind spots
  • ⚠️ No local ClickHouse build or binary was available. The integration and bugfix-validation jobs for the added tests were still pending in the PR CI report; passing results would close this runtime-validation gap. Cloud behavior also needs validation with a Cloud build.
Findings

❌ Blockers

  • src/Access/AccessBackup.cpp:438: Replacement must require the corresponding DROP privilege for every restored access-entity type. The MaskingPolicy branch requires only CREATE MASKING POLICY, while restoreAccessEntitiesFromBackup still inserts it with replace_if_exists=true. The shared insertion path adds no caller privilege check. In Cloud, an actor able to create masking policies and read the backup can overwrite an existing policy with a weaker definition without DROP MASKING POLICY. Include AccessType::DROP_MASKING_POLICY when replace is true.
Tests
  • ⚠️ Add a Cloud masking-policy replacement regression: deny replacement without DROP MASKING POLICY, verify the existing definition is preserved, then grant it and verify replacement succeeds.
Final Verdict

Status: ❌ Block. Apply the replacement privilege check to masking policies and prove it with the focused Cloud regression; obtain passing results for the added integration tests.

@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 07:49
/// `CREATE MASKING POLICY` is a GLOBAL-scope privilege, so the element carries no database or
/// table argument even though the policy itself names a table.
res.emplace_back(AccessType::CREATE_MASKING_POLICY);
res.grant(AccessType::CREATE_MASKING_POLICY);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ Blocker: require DROP MASKING POLICY for replacement restores.

In CLICKHOUSE_CLOUD builds, RESTORE TABLE system.masking_policies ... SETTINGS create_access='replace' reaches this branch but still requires only CREATE MASKING POLICY. restoreAccessEntitiesFromBackup passes replace_if_exists=true to destination_access_storage.insert for every restored entity type, and AccessControl::RestoreAccessStorage::insertImpl adds no caller privilege check. A user who can create masking policies and read the backup can therefore overwrite an existing policy with a weaker backed-up definition without DROP MASKING POLICY, leaving the same authorization gap this PR closes for row policies.

Include AccessType::DROP_MASKING_POLICY when replace is true, and add a Cloud regression case proving replacement is denied without that grant and succeeds after it is granted.

@clickhouse-gh clickhouse-gh Bot added the comp-backup Backup/restore infrastructure and backup formats. label Oct 21, 2026
@kolsha kolsha closed this Oct 21, 2026
@kolsha
kolsha deleted the codex/restore-access-drop-privileges branch October 21, 2026 08:31
zvonand pushed a commit to zvonand/ClickHouse that referenced this pull request Oct 22, 2026
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: ClickHouse#127128
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-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant