Skip to content

Require the DROP privilege for CREATE ... OR REPLACE of an access entity - #117960

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-90833-create-or-replace-access-check
Sep 5, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-90833-create-or-replace-access-check

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

CREATE USER OR REPLACE, CREATE ROLE OR REPLACE, CREATE QUOTA OR REPLACE, CREATE SETTINGS PROFILE OR REPLACE and CREATE ROW POLICY OR REPLACE overwrite an existing entity of the same name, but they only required the corresponding CREATE privilege. A user holding just CREATE USER could therefore replace any other user - including a privileged one - resetting its authentication methods, its granted roles and its settings, and then log in as that user:

-- as `default`
CREATE USER foo IDENTIFIED WITH no_password;
GRANT CREATE USER ON *.* TO foo;
CREATE USER foo2 IDENTIFIED BY 'abc';

-- as `foo`, which holds only CREATE USER
CREATE USER OR REPLACE foo2 IDENTIFIED BY 'efg';  -- succeeded, `foo2` is now owned by `foo`

CREATE ... OR REPLACE is a drop followed by a create, so it now requires the privileges of both. This is what REPLACE TABLE, CREATE OR REPLACE VIEW, CREATE OR REPLACE FUNCTION, CREATE OR REPLACE WORKLOAD and CREATE OR REPLACE RESOURCE already do; the access entities were the only object kind missing it. As with REPLACE TABLE, the DROP privilege is required whether or not the entity currently exists, so the check cannot be used to find out which entities exist either.

Plain CREATE and ALTER are unaffected, and so is any user holding ACCESS MANAGEMENT (which covers both the CREATE and the DROP privileges). Only a grant of CREATE <entity> without the matching DROP <entity> changes behaviour.

Closes: #90833

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

CREATE USER OR REPLACE and the OR REPLACE form of CREATE ROLE, CREATE QUOTA, CREATE SETTINGS PROFILE and CREATE ROW POLICY now require the corresponding DROP privilege in addition to CREATE, because they overwrite an existing entity. Previously CREATE USER alone was enough to reset the password of any other user, including a privileged one.


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

Version info

  • Merged into: 26.9.1.784 (included in 26.9 and later)
  • Backported to: 26.8.3.49, 26.7.7.35, 26.6.5.61, 26.3.33.3

`CREATE USER OR REPLACE`, `CREATE ROLE OR REPLACE`, `CREATE QUOTA OR REPLACE`,
`CREATE SETTINGS PROFILE OR REPLACE` and `CREATE ROW POLICY OR REPLACE` overwrite
an existing entity of the same name, but they only required the corresponding
`CREATE` privilege. A user holding just `CREATE USER` could therefore replace any
other user - including a privileged one - resetting its authentication methods,
its granted roles and its settings, and then log in as that user.

`CREATE ... OR REPLACE` is a drop followed by a create, so it now requires the
privileges of both, the same way `REPLACE TABLE`, `CREATE OR REPLACE VIEW`,
`CREATE OR REPLACE FUNCTION`, `CREATE OR REPLACE WORKLOAD` and
`CREATE OR REPLACE RESOURCE` already do. The `DROP` privilege is required whether
or not the entity currently exists, mirroring `REPLACE TABLE`, so the check
cannot be used to find out which entities exist either.

Closes: #90833

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [335d081]

Summary: ✅


AI Review

Summary

This PR closes the public-tree privilege gap in CREATE ... OR REPLACE for access entities by requiring the matching DROP privilege before the replace path runs, and it adds a focused stateless regression test for the affected entity types. I did not find a remaining bypass in the touched user-facing interpreters (USER, ROLE, QUOTA, SETTINGS PROFILE, ROW POLICY), and the PR metadata matches the actual change.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 335d081.

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

Changed lines: Changed C/C++ lines covered: 58/59 (98.31%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. labels Sep 3, 2026
alexey-milovidov and others added 2 commits September 5, 2026 00:55
The Fast test build has no SSL library, so `IDENTIFIED WITH sha256_password`
fails there with `SUPPORT_IS_DISABLED`. Use `plaintext_password` instead: the
test only needs a password that the replaced user can no longer log in with,
not a specific hashing scheme.

Also renumber the test from 05060 to 05078, because master already has ten
other tests with the 05060 prefix.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117960&sha=8d554168ea280f118ccf995446e7350d591ee79c&name_0=PR&name_1=Fast%20test
PR: #117960

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 335d08101 with master d1adb9f9f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

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.

Object file sizes ⚠️

49 object files changed (+295.58 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/Cascades/Rules/AggregationPushdown.cpp.o new 278.38 KiB +278.38 KiB

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

339 translation units recompiled, 2730 s compile time in total, 338 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/Processors/QueryPlan/Optimizations/Cascades/Rules/AggregationPushdown.cpp: 7.4 s

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The sole red so far, Docker keeper image (clickhouse-keeper:head-distroless-arm64), is unrelated to this change: the in-region apt mirror answered 503 for the jammy, jammy-updates and jammy-security InRelease files, so apt-get install failed with wget : Depends: libpsl5 ... but it is not installable. Every arm64 keeper image build on the fleet reded the same way on 2026-09-05 around 00:00 and 04:00 UTC, and the mirror fallback never ran because it did not recognise this failure shape. Fix: #118213. The job only needs a rerun here.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The second red, Stress test (amd_debug), is also unrelated: it is the known Logical error: Cannot add ZooKeeper operation because query is executed on TRUNCATE of a TimeSeries table in a Replicated database, tracked in #117900 with the fix in progress in #117902 (CI already matched it to that issue and marked it flaky). This PR does not touch TimeSeries, TRUNCATE, or ZooKeeper. I merged the current master to get a fresh CI run; the two reds will clear once those fixes land.

pull Bot pushed a commit to weiyilai/ClickHouse that referenced this pull request Sep 5, 2026
…ial index

When the in-region mirror withholds a suite's `InRelease` (a `503` for `jammy`,
`jammy-updates` and `jammy-security` on 2026-09-05), `apt-get update` only
warns and carries on with the suites it did get, so the failure surfaces on
`apt-get install` as `E: Package 'ca-certificates' has no installation
candidate` or `E: Unable to correct problems, you have held broken packages`.
`is_apt_mirror_failure` did not know either shape, so every arm64 keeper image
build on the fleet reded without ever trying Canonical.

Both lines are still required to be apt `E:` output inside the terminal buildx
failure block, so a recovered `apt-get update` warning or a step header naming
apt still does not trigger a rebuild.

Example: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117960&sha=e523443dea969b125df53bdba9f23e04c37cc19b&name_0=PR&name_1=Docker%20keeper%20image
(PR: ClickHouse#117960)

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 5, 2026
Merged via the queue into master with commit 5b8a4ca Sep 5, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-90833-create-or-replace-access-check branch September 5, 2026 14:50
@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 Sep 5, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 5, 2026
alexey-milovidov added a commit that referenced this pull request Sep 5, 2026
Cherry-pick of #117960 to 26.3. The parser files conflicted only on the in-source
statement documentation (`registerStatement*`), which does not exist in 26.3, so the
doc hunks were dropped and the parsers kept identical to 26.3. The interpreter
changes and the test apply unchanged.
robot-ch-test-poll3 added a commit that referenced this pull request Sep 5, 2026
Cherry pick #117960 to 26.3: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
robot-clickhouse added a commit that referenced this pull request Sep 5, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Sep 5, 2026
Cherry pick #117960 to 26.6: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
robot-clickhouse added a commit that referenced this pull request Sep 5, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Sep 5, 2026
Cherry pick #117960 to 26.7: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
robot-clickhouse added a commit that referenced this pull request Sep 5, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Sep 5, 2026
Cherry pick #117960 to 26.8: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
robot-clickhouse added a commit that referenced this pull request Sep 5, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 6, 2026
Backport #117960 to 26.7: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
clickhouse-gh Bot added a commit that referenced this pull request Sep 6, 2026
Backport #117960 to 26.6: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
clickhouse-gh Bot added a commit that referenced this pull request Sep 6, 2026
Backport #117960 to 26.8: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
alexey-milovidov added a commit that referenced this pull request Sep 6, 2026
Backport #117960 to 26.3: Require the DROP privilege for CREATE ... OR REPLACE of an access entity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix 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.

Potential issue: CREATE USER OR REPLACE requires only CREATE USER privilege when replacing an existing user

4 participants