Skip to content

Move the handler privileges out of CREATE, ALTER and DROP into a new HANDLER ADMIN group - #129033

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:handler-admin-privilege-group
Nov 13, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:handler-admin-privilege-group

Conversation

@groeneai

@groeneai groeneai commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #106231

Changelog category (leave one):

  • Backward Incompatible Change

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

CREATE HANDLER, ALTER HANDLER, DROP HANDLER and SHOW HANDLERS now form the new HANDLER ADMIN privilege group and are no longer part of the CREATE, ALTER and DROP groups. Previously GRANT CREATE ON *.* or GRANT ALTER ON *.* was enough to define or rewrite an HTTP handler, whose query runs with the privileges of the user who calls it. Users who manage handlers must now be granted HANDLER ADMIN or the individual handler privileges, including users whose stored grants name only the old groups: for example, GRANT CREATE, CREATE HANDLER is stored as GRANT CREATE, and GRANT ALL followed by REVOKE SYSTEM is stored as a list of groups. Revoking CREATE, ALTER or DROP no longer revokes them, so a configured grant list that revokes one of these from ALL should also revoke HANDLER ADMIN.

Description

On 26.8, 26.9 and 26.10 (system.privileges checked on 26.8.18.2, 26.9.11.2 and 26.10.2.103), a user whose only privilege is GRANT CREATE ON *.* can run CREATE HANDLER. The handler's query runs with the privileges of whoever calls its URL, so CREATE HANDLER h URL '/h' METHODS (POST) AS GRANT SELECT ON secret.* TO me gives that user SELECT ON secret.* the next time a privileged user sends a POST to /h. GRANT ALTER ON *.* can rewrite an existing handler the same way through ALTER HANDLER.

Cause: in AccessType.h the handler privileges are children of the CREATE, ALTER and DROP groups, and a group grant includes its children.

Change: a new HANDLER ADMIN group under ALL holds all four handler privileges, the same layout as NAMED COLLECTION ADMIN. ALL and standalone grants of the individual privileges keep working, and the readonly / allow_ddl checks are unchanged (they check the individual privileges). This PR narrows who may define a handler; what a stored handler query may do when it is invoked will be addressed in a separate PR.

Requested by @ nikitamikhaylov.

Validation: the new test 05493_handler_admin_privilege fails on master (a user with CREATE, ALTER, DROP ON *.* can create, alter and drop handlers, and GRANT HANDLER ADMIN does not parse) and passes 50/50 with randomized settings. 01271_show_privileges is updated.

Grants holding all four handler privileges are now saved as HANDLER ADMIN, which servers without this change do not parse (relevant for a replicated access storage during a rolling upgrade).


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

Version info

  • Merged into: 26.11.1.2183-master (included in 26.11 and later)
  • Backported to: 26.10.9.12, 26.9.34.23, 26.8.43.11

CREATE_HANDLER, ALTER_HANDLER and DROP_HANDLER were children of the
CREATE, ALTER and DROP groups, so GRANT CREATE ON *.* (or GRANT ALTER)
was enough to define or rewrite a SQL-defined HTTP handler. The handler
query runs with the privileges of whoever calls the URL, so a user with
only CREATE could plant e.g. `AS GRANT SELECT ON secret.* TO me` behind
METHODS (POST) and gain it the next time a privileged user posts there.

Add a HANDLER_ADMIN group under ALL and re-parent all four handler
privileges (including SHOW_HANDLERS) to it, the same layout as
NAMED_COLLECTION_ADMIN. ALL holders and explicit grants of the individual
privileges are unaffected; the readonly and allow_ddl checks are keyed on
the individual privileges and do not change. A GROUP takes no flag bit,
so AccessFlags::SIZE stays 256; AccessType now has 256 values, the full
range of uint8_t.

Update 01271_show_privileges, add 05493_handler_admin_privilege, and
document the group in the CREATE HANDLER and GRANT documentation sources.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 4 findings over 3 passes on the same tree; the last pass had 0 findings). None needed a code change; three changed the PR description.

# Sev Finding Verdict Evidence / action
1 ⚠️ A users.xml grant list GRANT ALL + REVOKE CREATE (or ALTER, DROP) keeps the handler privileges after the upgrade (UsersConfigParser.cpp re-applies the list at every load) AGREE Upgrade guidance added to the changelog entry. SQL-created principals are not affected: a global revoke is stored as the remaining grant list.
2 ❌ An older replica of a replicated access storage cannot parse HANDLER ADMIN and drops the entity during a rolling upgrade DISAGREE Holds for every new privilege keyword (ZooKeeperReplicator.cpp drops any entity it cannot parse, serializeAccessEntity writes the current keywords). Not specific to this change; noted in the description.
3 ⚠️ A handler privilege granted together with its old group (GRANT CREATE, CREATE HANDLER is stored as GRANT CREATE) is lost on upgrade AGREE Changelog entry and description updated.
4 💡 Use Critical Bug Fix for an RBAC fix DISAGREE I do not choose that category myself; a maintainer can change it.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-10:20261103-145800

@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. As a user with only GRANT CREATE ON *.*: CREATE HANDLER t URL '/t' METHODS (POST) AS GRANT SELECT ON secret.* TO <user> succeeds on master; a POST to /t by default then adds GRANT SELECT ON secret.* to that user. Every run.
b Root cause explained? The handler privileges are children of the CREATE / ALTER / DROP groups in AccessType.h, a group grant includes its children, and a handler query runs with the caller's privileges.
c Fix matches root cause? Yes, the privilege tree is changed: a new HANDLER ADMIN group under ALL holds all four handler privileges. No new check in the interpreters (they already check the individual privileges).
d Test intent preserved / new tests added? New 05493_handler_admin_privilege.sh: CREATE, ALTER, DROP ON *.* no longer allows handler DDL (with a CHECK GRANT CREATE TABLE positive control), and HANDLER ADMIN allows create, alter, drop and SHOW HANDLERS. 01271_show_privileges.reference regenerated (5 lines).
e Both directions demonstrated? Master: 05493 and 01271 fail (handler DDL succeeds, GRANT HANDLER ADMIN is a syntax error). Fix: both pass; 05493 50/50 with randomized settings and 20/20 with -j 20.
f Fix is general across code paths? All four handler privileges moved, including ALTER HANDLER, which can rewrite a handler body. CREATE/ALTER/DROP HANDLER and system.handlers check the individual privileges; no other code path creates or changes handlers.
g Fix generalizes across inputs (params/datatypes/wrappers)? Grant shapes checked: the CREATE/ALTER/DROP groups, HANDLER ADMIN, the four individual privileges (shown as HANDLER ADMIN in SHOW GRANTS), ALL, ALL minus CREATE, plus readonly = 1 (Code 164) and allow_ddl = 0 (Code 392).
h Backward compatible? (maintainer-approved exception only) Intended tightening, requested by a maintainer: users who manage handlers through CREATE/ALTER/DROP ON *.* need HANDLER ADMIN (named in the changelog entry). ALL, users from XML and explicit grants of the individual privileges are unaffected.
i Invariants and contracts preserved? The parent group is declared after its children; a group uses no flag bit, so AccessFlags::SIZE is unchanged; the enum fills uint8_t exactly (256 values). The readonly and allow_ddl checks use the individual privileges and behave as before.

Session id: cron:clickhouse-impl-slot-40:20261103-140200

@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @pufit @alexey-milovidov, could you review this and add the can be tested label so CI runs? It moves CREATE HANDLER, ALTER HANDLER, DROP HANDLER and SHOW HANDLERS into a new HANDLER ADMIN group under ALL, so GRANT CREATE ON *.* or GRANT ALTER ON *.* no longer allows defining or rewriting an HTTP handler, whose query runs with the privileges of the user who calls it.

@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [150cec2]

Summary: ✅


AI Review

Summary

The change moves the four handler privileges into HANDLER ADMIN, preventing ordinary CREATE, ALTER, and DROP grants from administering HTTP handlers. The focused regression test passes in the current Fast test report. One previously dismissed compatibility blocker remains: existing access entities can automatically acquire a serialized privilege name that older replicas cannot read. Reviewed PR head: 150cec2ba363e712350e6639eff1a73f124f22db; all six changed checkout files match that head.

Findings

❌ Blockers

  • src/Access/Common/AccessType.h:323 — Existing users and roles can disappear from older replicas during a rolling upgrade. [dismissed by author -- https://github.com/Move the handler privileges out of CREATE, ALTER and DROP into a new HANDLER ADMIN group #129033#issuecomment-6608077001] This remains real because the new group changes serialization of existing privileges without requiring anyone to grant a new privilege.

    Start with an existing user explicitly granted CREATE HANDLER, ALTER HANDLER, DROP HANDLER, and SHOW HANDLERS. An unrelated ALTER USER on an upgraded replica calls serializeAccessEntity; flagsToKeywordsRec now compresses those four existing flags into HANDLER ADMIN. ZooKeeperReplicator::updateZooKeeper writes that definition to Keeper. A replica without this PR cannot parse it; with the default invalid-entity handling, tryReadEntityFromZooKeeper returns null and refreshEntityImpl removes the entire entity from its local access storage. Authentication or access through the affected role consequently fails. The base revision's parser and replication code confirm this path.

    Preserve the four existing individual privilege names in persisted access definitions until older replicas are compatible, or provide an explicit versioned rollout mechanism. The PR description acknowledges the risk but does not prevent the automatic rewrite.

Tests
  • ⚠️ Add a focused mixed-version regression: create the four individual grants before the upgrade, update an unrelated user property through the upgraded replica, and verify that the older replica still loads the user and its grants. 05493_handler_admin_privilege covers the new hierarchy, but not this persistence boundary. The rollout failure above was traced in source; no mixed-version runtime reproduction was performed.
Performance & Safety

Consumers of the newly grouped AccessFlags output were traced:

  • AccessRightsElement, ASTGrantQuery, and ASTCheckGrantQuery format registered keywords; the current parser accepts the new group. ASTAuthenticationData uses the same formatter, and ASTCreateTokenQuery hashes its precise string representation.
  • replaceDeprecated accepts the group as one registered access type; StorageSystemGrants obtains its enum from the same privilege declarations.
  • DiskAccessStorage, ZooKeeperReplicator, and AccessBackup persist the group through serializeAccessEntity. Current readers accept it; older readers reject it, affecting replicated access, rollback, and restoring those definitions on older versions.
Final Verdict

Status: ❌ Block. Preserve compatibility of persisted existing handler grants and cover the mixed-version update case. No new inline comments were posted: the remaining issue was already explicitly dismissed in the author's discussion and is retained here only.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. labels Nov 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 150cec2ba with master 7f7d60b3e (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.60, programs/clickhouse-keeper ×0.63 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 6.2 s 10.6 s +6.9 s (+186%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 7.2 s +5.2 s (+254%)
Compile time of recompiled translation units

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

Job report

@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 8484806

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug, targeted, old_compatibility) infra, not from this PR: the fuzzer found nothing. The targeted corpus (01271_show_privileges.sql, whose reference this PR changes) finishes a pass before run-fuzzer.sh finds the client PID, and set -e then stops the script before status.tsv is written #129073 (mine, open)
PR praktika rollup of the row above #129073 (mine, open)

The first two runs of this head stopped at Config Workflow / Pre Hooks before the can be tested label was set. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261103-200006

…lege-group

# Conflicts:
#	src/Parsers/Access/ParserGrantQuery.cpp
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit a33dd5a Nov 13, 2026
204 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@groeneai @alexey-milovidov — this PR looks backward incompatible but is categorized as Bug Fix (user-visible misbehavior in an official stable release).

Why: Re-parenting CREATE_HANDLER/ALTER_HANDLER/DROP_HANDLER under HANDLER_ADMIN (AccessType.h:231,259,271) changes what existing grants mean after upgrade: stored GRANT CREATE loses CREATE HANDLER, and the same GRANT ALL + REVOKE CREATE, ALTER, DROP leaves SHOW HANDLERS on 26.10 but HANDLER ADMIN on this build. The entry itself tells users to re-grant and to edit users.xml revoke lists, and the identical sibling #129772 (workload/resource privileges, same author) is filed as Backward Incompatible Change. The entry text is accurate; only the category is wrong, so the upgrade warning lands outside the Backward Incompatible section of the 26.11 changelog.

Suggested category: Backward Incompatible Change. Ignore if the change is intentionally non-breaking.

@groeneai

Copy link
Copy Markdown
Collaborator Author

I changed the changelog category to Backward Incompatible Change; the entry is unchanged.

robot-ch-test-poll4 added a commit that referenced this pull request Nov 20, 2026
Cherry pick #129033 to 26.8: Move the handler privileges out of `CREATE`, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
robot-clickhouse added a commit that referenced this pull request Nov 20, 2026
…, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
robot-ch-test-poll4 added a commit that referenced this pull request Nov 20, 2026
Cherry pick #129033 to 26.9: Move the handler privileges out of `CREATE`, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
robot-clickhouse added a commit that referenced this pull request Nov 20, 2026
…, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
robot-ch-test-poll4 added a commit that referenced this pull request Nov 20, 2026
Cherry pick #129033 to 26.10: Move the handler privileges out of `CREATE`, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
robot-clickhouse added a commit that referenced this pull request Nov 20, 2026
…`, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
@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 Nov 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 20, 2026
Backport #129033 to 26.10: Move the handler privileges out of `CREATE`, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
clickhouse-gh Bot added a commit that referenced this pull request Nov 20, 2026
Backport #129033 to 26.9: Move the handler privileges out of `CREATE`, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
clickhouse-gh Bot added a commit that referenced this pull request Nov 20, 2026
Backport #129033 to 26.8: Move the handler privileges out of `CREATE`, `ALTER` and `DROP` into a new `HANDLER ADMIN` group
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. 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.

7 participants