Repository navigation
Support ON CLUSTER for SET DEFAULT ROLE - #118429
Conversation
SET DEFAULT ROLE r TO u ON CLUSTER c
Code: 62. DB::Exception: Syntax error: failed at position 35 (ON): ON CLUSTER c.
(SYNTAX_ERROR)
while `CREATE ROLE ... ON CLUSTER`, `CREATE USER ... ON CLUSTER` and
`GRANT ON CLUSTER ...` all worked, so setting a user's default roles fleet-wide meant
falling back to `ALTER USER u ON CLUSTER c DEFAULT ROLE r`.
`ASTSetRoleQuery` now implements `ASTQueryWithOnCluster`, and the clause is accepted in
either position, as `GRANT` does:
SET DEFAULT ROLE r TO u ON CLUSTER c
SET DEFAULT ROLE ON CLUSTER c r TO u
`CURRENT_USER` is resolved on the initiator before the query is distributed - the AST
text is what reaches every host, and a DDL worker there runs as its own user.
`SET ROLE` only changes the current session, so it takes no `ON CLUSTER` clause and
still fails to parse with one.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [55b82a1] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict
LLVM Coverage ReportMeasured on commit 55b82a1.
Changed lines: Changed C/C++ lines covered: 89/93 (95.70%) · Uncovered code |
The AST fuzzer aborted with `No user in current context, it's a bug`. Making
`ASTSetRoleQuery` distributable exposed a path that did not exist before: the DDL worker
executes a distributed query in a context with no user, unless
`distributed_ddl_use_initial_user_and_roles` is set, and the server-side fuzzer mutated
the queued `SET DEFAULT ROLE ... TO ...` into the session-local `SET ROLE`, which reached
`Context::setCurrentRoles` there. `ContextAccess::getUser` treats a missing user as a
logical error and aborts:
DDLWorker: Executing query: SET DEFAULT ROLE `05107_role_a` TO `05107_user`
executeQuery: (internal) SET ROLE `05107_role_a` (stage: Complete)
<Fatal> : Logical error: 'No user in current context, it's a bug'.
Two guards:
- Refuse a cluster on any kind other than `SET DEFAULT ROLE`. Only that one changes the
user; `SET ROLE` and `SET ROLE DEFAULT` change the current session, for which a
cluster is meaningless. The parser only accepts the clause for `SET DEFAULT ROLE`, so
this covers an AST built by other means.
- Refuse `SET ROLE` when the current context has no user, with a proper exception
instead of an abort.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 The AST fuzzer failure was real and caused by this PR. Diagnosis from the artifacts: with Two guards added:
Verified against a local build:
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes8 object files changed (+50.20 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units14 translation units recompiled, 62 s compile time in total, 14 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.09 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…distributing Addresses the review of `SET DEFAULT ROLE ... ON CLUSTER`: 1. The role names are now resolved into a `RolesOrUsersSet` before the cluster branch, so an unknown role is rejected on the initiator instead of being queued into the DDL log and failing on every host. This is the contract of both the local `SET DEFAULT ROLE` path and `ALTER USER ... DEFAULT ROLE ... ON CLUSTER`, which builds `default_roles_from_query` before calling `executeDDLQueryOnCluster` too. Pinned in `05107_set_default_role_on_cluster`. 2. `replaceCurrentUserTag` moved into the cluster branch, after the access check. `collectRequiredGrants` collects nothing for the `CURRENT_USER` tag and `ALTER USER` on the named user otherwise, so resolving the tag before the check made `SET DEFAULT ROLE ... TO CURRENT_USER` require `ALTER USER` on oneself, which plain `SET DEFAULT ROLE` never did. The local path does not need the tag resolved at all - `RolesOrUsersSet` resolves it from the context's user id. 3. New test `05182_set_default_role_on_cluster_current_user.sh`: a non-`default` user with only its role and `CLUSTER` granted runs `SET DEFAULT ROLE <role> TO CURRENT_USER ON CLUSTER test_shard_localhost`, and the test asserts that this user - and no other - gets the default role. Verified as a real control: with `replaceCurrentUserTag` commented out, the DDL worker reaches `RolesOrUsersSet` with no user in its context and the server aborts on `optional operator* called on a disengaged value`. 4. That abort also poisons the DDL queue: the entry is retried on every restart, so the server no longer starts. Guard the local path against a `CURRENT_USER` tag in a context with no user and throw `BAD_ARGUMENTS` instead. Verified on the crash-looping data directory from item 3 - the server starts and reports `SET DEFAULT ROLE TO CURRENT_USER requires a user in the current context` for the queued entry. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Pushed the review fixes (role names resolved on the initiator before the query is distributed, Both public CI reds on the previous head are unrelated to this PR:
@groeneai, investigate these two failures and provide fixes in separate PRs:
If a fix is already in progress, link it here. I could not find an open issue for either.
|
|
Both failures already have owners, and neither needs a new pull request from me.
|
…served initial user The initiator replaces the `CURRENT_USER` tag with its user name before queueing the DDL entry. With `distributed_ddl_use_initial_user_and_roles` (and entry format version 8) the DDL worker runs the query as that user, and `collectRequiredGrants` then demanded `ALTER USER` on the user's own name, so a query the initiator accepted failed on every host. In a distributed query executed with a user, the user's own name no longer requires a grant; other names still do. Added an integration test, since a stateless test cannot enable the server setting. Without the fix it fails with `Not enough privileges ... ALTER USER ON u`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Merged @groeneai, thanks. The new head carries #118474, so |
… merging master `ASTRolesOrUsersSet::names` is now an `ASTUserNamesWithHost` node instead of `Strings`, so drop the current user's name from its children instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged The previous red checks are unrelated to this PR: |
Resolve the cherry-pick of #118021 to 26.9. The conflict in `InterpreterSetRoleQuery.cpp` comes from #118429, which is not on 26.9 and has no backport label: on master `setRole` also refuses a context without a user, next to the new `readonly` check. Only the `readonly` check is added. The new integration test merges cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the cherry-pick of #118021 to 26.8. The conflict in `InterpreterSetRoleQuery.cpp` comes from #118429, which is not on 26.8 and has no backport label: on master `setRole` also refuses a context without a user, next to the new `readonly` check. Only the `readonly` check is added. `ParserCreateHandlerQuery.cpp` has no `getDocumentation` on 26.8, so its documentation change is dropped. The new integration test merges cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts for the 26.7 backport of #118021: - `InterpreterSetRoleQuery.cpp`: keep only the `readonly` check; the missing-user check comes from #118429, which is not on 26.7. - `SQLDefinedHandlerFromAST.cpp`, `ParserCreateHandlerQuery.cpp`, `04824_handler_safe_method_session_state.sh`: removed, 26.7 has no SQL-defined handlers. Resolution matches the one proposed by @groeneai in #125310 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the cherry-pick of #118021 to 26.3. The conflict in `InterpreterSetRoleQuery.cpp` comes from #118429, which is not on 26.3 and has no backport label: on master `setRole` also refuses a context without a user, next to the new `readonly` check. Only the `readonly` check is added. `docs/concepts/features/interfaces/http.mdx` and the SQL-defined handler files (`SQLDefinedHandlerFromAST.cpp`, `ParserCreateHandlerQuery.cpp`, `04824_handler_safe_method_session_state.sh`) do not exist on 26.3, so their comment and documentation changes are dropped. The server setting row is added to 26.3's `_server_settings_outside_source.md`. The new integration test merges cleanly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
SET DEFAULT ROLEtook noON CLUSTERclause:even though
CREATE ROLE ... ON CLUSTER,CREATE USER ... ON CLUSTERandGRANT ON CLUSTER ...all did, so the one statement in that sequence that could not be distributed was the one setting the default roles.ASTSetRoleQuerynow implementsASTQueryWithOnClusterand the clause is accepted in either position, matchingParserGrantQuery:Details:
CURRENT_USERis resolved on the initiator before the query is distributed. The AST text is what reaches every host and a DDL worker there runs as its own user, so an unresolved tag would set the default roles of the wrong user. This mirrors whatInterpreterGrantQuerydoes for grantees.checkCanAdministerDefaultRolesandALTER USERon the grantees) run on the initiator before distributing, as they do for the local path.ASTSetRoleQueryis added toisAccessControlQueryinremoveOnClusterClauseIfNeeded, soignore_on_cluster_for_replicated_access_entities_queriesdrops the redundant clause on aReplicatedAccessStoragethe same way it does forGRANTandCREATE USER.SET ROLEonly changes the current session. It takes noON CLUSTERclause and still fails to parse with one; the parser only looks for the clause in theSET DEFAULT ROLEbranch, and the interpreter refuses a cluster on any other kind, in case an AST is built by other means.SET ROLEis also refused when the current context has no user. The DDL worker executes a distributed query in such a context unlessdistributed_ddl_use_initial_user_and_rolesis set, andContext::setCurrentRolesreachesContextAccess::getUserthere, which treats a missing user as a logical error and aborts. The AST fuzzer found this by mutating the queuedSET DEFAULT ROLE ... TO ...into aSET ROLEand running it on the worker; a proper exception replaces the abort.ALTER USER u ON CLUSTER c DEFAULT ROLE rremains the equivalent long form and is unchanged.Closes: #31058
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
SET DEFAULT ROLEnow accepts anON CLUSTERclause, in either position:SET DEFAULT ROLE role1 TO user ON CLUSTER my_clusterandSET DEFAULT ROLE ON CLUSTER my_cluster role1 TO user.CURRENT_USERis resolved on the initiator before the query is distributed.SET ROLEonly affects the current session and still takes noON CLUSTERclause.Workflow [PR]
Sync PR [sync-upstream/pr/118429]
Version info
26.10.1.1358-master(included in26.10and later)