Repository navigation
Refuse granting a role in readonly mode, like granting a privilege - #132330
Conversation
Under `readonly`, `GRANT SELECT ON system.one TO b` is refused with READONLY, but `GRANT r TO b` by a user holding `r WITH ADMIN OPTION` was accepted and persisted (also over HTTP GET, which runs with readonly = 2; reproduced on 26.8.38.9 and master). `readonly` is enforced for grant changes only in the grant-option check of ContextAccess::checkAccessImplHelper. Role grants are authorized by ContextAccess::checkAdminOption, whose admin-option branch does not look at `readonly`, and an ON CLUSTER role-only statement passes an empty `access_to_check` to executeDDLQueryOnCluster, so role GRANT and role REVOKE ON CLUSTER were queued and executed unchecked. InterpreterGrantQuery::execute now states the documented privilege rule for roles before the ON CLUSTER branch: under readonly, granting a role is refused (locally and ON CLUSTER) and revoking a role is refused ON CLUSTER, with the same error as for privileges. A local REVOKE of a role stays allowed, like a local REVOKE of a privilege. The check is done here and not in checkAdminOptionImplHelper because that helper serves local REVOKE too. `full_access` contexts are skipped, as both ContextAccess helpers do. Docs: "Permissions for queries" now mentions roles. Closes ClickHouse#132005 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261117-114200 |
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261117-103001 |
|
Workflow [PR], commit [4abb20d] Summary: ✅
AI ReviewSummaryThe change rejects role Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
@groeneai any other possible similar issue in readonly mode? |
|
🕵️ @groeneai the A local role
Suggested fix: refuse a local role |
|
Yes. I ran a census on master
1-3 have the same cause. The Refused, as expected: I'll send one PR that adds the three missing access types to the gate. If you would rather have the allow-list, I'll do that instead. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
Move the readonly check for role grants from InterpreterGrantQuery into ContextAccess::checkAdminOptionImplHelper, next to the authentication_grants guard, so every admin-option check refuses under readonly with the same "Cannot change grants in readonly mode." error as privilege grants. This now also covers a local REVOKE of a role (and REVOKE ADMIN OPTION FOR), which used to be allowed. ON CLUSTER is still covered before dispatch: checkAdminOptionForExecutingOnCluster checks each role with checkAdminOption, and REVOKE ALL with ROLE ADMIN, which readonly refuses as well. A REVOKE of a role the grantee does not have is still a no-op, as for privileges. A local REVOKE of a privilege and GRANT CURRENT GRANTS are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, done in 4abb20dc. I took the sturdier option: the check now lives in Measured on the fix build: the role matrix ( I'll send the local privilege |
|
The three items from my census above are fixed in #132424: |
|
The local privilege |
|
One more gap my census above did not list: a |
…efuse-privilege-revoke-current-grants Resolve the conflict in the "Permissions for queries" docs with ClickHouse#132330, which refuses granting and revoking a role in readonly mode. Its sentence listed a local privilege `REVOKE` and `GRANT CURRENT GRANTS` as exceptions, which this PR removes, so the merged sentence names both privileges and roles and has no exceptions left. The C++ changes merged without conflicts: the role check of ClickHouse#132330 in `ContextAccess::checkAdminOptionImplHelper` and `checkCanChangeGrants` here apply to different statements. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mode Under readonly = 1 or 2 (every HTTP GET runs with readonly = 2), a session of a user holding a privilege WITH GRANT OPTION could still revoke it from another user with a local REVOKE, or propagate its grants with GRANT CURRENT GRANTS, and the change persisted. A plain GRANT is refused there, and so is the same REVOKE ON CLUSTER. readonly refuses a change of grants only in the grant-option branch of ContextAccess::checkAccessImplHelper. A privilege REVOKE fails that check under readonly and then falls back to the "special case for REVOKE" in checkGrantOption, which narrows the revoke to what the grantees hold and authorizes it with a raw AccessRights::containsWithGrantOption, so the readonly branch is never reached. GRANT CURRENT GRANTS clamps the granted rights to getGrantableRights() instead of checking the grant option (ClickHouse#60304), so ContextAccess is not consulted at all. Add ContextAccess::checkCanChangeGrants() (READONLY, the same message as the grant-option branch, skipped for full_access; next to the existing session-level guard checkCanAdministerDefaultRoles) and call it once in InterpreterGrantQuery::execute after the grant-option checks whenever there is a privilege to grant or, after narrowing, to revoke. A REVOKE of a privilege no grantee holds stays a no-op and is accepted, as for roles in ClickHouse#132330. readonly = 0 is unchanged; the containment and clamp semantics are unchanged. An element-wise checkGrantOption under readonly was rejected: with partial revokes it reports a false ACCESS_DENIED for a revoke the user is entitled to (rows 1-2 of the new test turn ACCESS_DENIED), and it still lets through the elements that return before the readonly branch (CLUSTER when on_cluster_queries_require_cluster_grant = false, the temporary database). Under readonly, GRANT CURRENT GRANTS to a grantee outside the GRANTEES list now reports READONLY instead of ACCESS_DENIED, the order a plain GRANT has. The "Permissions for queries" docs listed both statements as exceptions; they now say GRANT, GRANT CURRENT GRANTS and REVOKE of a privilege are refused. Related: ClickHouse#132330 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`rename_files_after_processing` renames the files a `SELECT` from `file()` has read. ClickHouse#117895 authorizes that write by requesting `WRITE` on the `FILE` source in `StorageFile::read` and on the `fileCluster` initiator, but the readonly gate in `ContextAccess::checkAccessImplHelper` is a deny-list of access types that does not contain `WRITE`. So a read-only session (`readonly = 2`, which every HTTP GET request implies) holding `WRITE ON FILE` renamed the files it read in `user_files` (measured on master and on 26.10.2.103). `WRITE` cannot join the deny-list: it also authorizes `BACKUP` destinations, which `readonly` is documented not to restrict, and reads from an `S3` database. So the two identical checks become one helper, `StorageFile::checkAccessForRenamingFiles`, which keeps the `WRITE` check and then refuses a read-only session with the gate's own `READONLY` error, including its HTTP GET hint. The grant check stays first, so a user without the grant still gets `ACCESS_DENIED`; `full_access` is exempt as in the gate. `DESCRIBE` builds no reader and stays allowed. Related: ClickHouse#132330 Related: ClickHouse#117895 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eadonly mode `readonly` and `allow_ddl` are enforced in `ContextAccess::checkAccessImplHelper` by a deny-list of requested access types. Three statements that change persistent state were missing from it: - `ALTER DATABASE ... MODIFY COMMENT` / `MODIFY SETTING` request the children of `ALTER_DATABASE`, which `table_ddl` did not contain, so they ran at `readonly = 1`, `readonly = 2`, over HTTP GET and with `allow_ddl = 0`. `ALTER_DATABASE` is now part of `table_ddl`, like `ALTER_TABLE` and `ALTER_VIEW`. - `KILL TRANSACTION` requests `KILL_TRANSACTION`, which was not in `not_readonly_flags` (`KILL_QUERY` is), so a read-only session could roll back another user's transaction. - `INSERT INTO FUNCTION` never requests `INSERT`; its only gated flag is `CREATE_TEMPORARY_TABLE` (forced for inserts by ClickHouse#44290), which `readonly = 2` allows on purpose for session temporary tables. So at `readonly = 2`, which is what HTTP GET runs with, `file()` wrote and overwrote files and `url()` sent the POST. The source `WRITE` flag is not added to the deny-list because it is also requested by `BACKUP` destinations (documented as not restricted by `readonly`), by `SELECT` from a `DatabaseS3` table and by `file()` reads with `rename_files_after_processing`, and a filtered `WRITE` grant does not reach the gate at all. Instead `InterpreterInsertQuery::getTable` refuses a table function insert under any `readonly`, with the gate's error text, before anything is resolved or written. Every table function insert (synchronous, asynchronous, parallel replicas) goes through it. The English documentation of these settings is updated, including two stale sentences (named collection management and `UNDROP TABLE` have been gated since ClickHouse#130952 and ClickHouse#131892). Related: ClickHouse#132330 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #132005
Closes: https://github.com/ClickHouse/clickhouse-private/issues/87667
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
GRANTandREVOKEof a role are now refused in readonly mode, like granting a privilege. Previously a read-only session (including any HTTP GET request) of a user holding a roleWITH ADMIN OPTIONcould grant that role to another user or revoke it from one. Closes #132005.Description
On 26.8.38.9, a
readonly = 1session of a user holdingr WITH ADMIN OPTIONrunsGRANT r TO band the grant persists, whileGRANT SELECT ON system.one TO bin the same session is refused withREADONLY. An HTTP GET request (which runs withreadonly = 2) does the same.Root cause:
readonlyis enforced for grant changes only in the grant-option check ofContextAccess::checkAccessImplHelper, which privilege grants pass through. Role grants are authorized byContextAccess::checkAdminOption, whose admin-option branch does not look atreadonly. WithON CLUSTER, a role-only statement leaves nothing forexecuteDDLQueryOnClusterto re-check, so it was queued and executed.Change:
ContextAccess::checkAdminOptionImplHelper, which authorizes every roleGRANTandREVOKE(locally, and per role before theON CLUSTERdispatch), now refuses underreadonlywith the sameREADONLYerror as a privilege grant, next to theauthentication_grantsguard. A localREVOKEof a privilege andGRANT CURRENT GRANTSare unchanged. Underreadonly, a role statement that was already refused may now reportREADONLYinstead ofACCESS_DENIED. The "Permissions for queries" docs now mention roles.Validation: the new test
05820_readonly_role_grantfails on master (the role rows readOK/1) and passes with the fix, 50/50 with randomized settings. Areadonly0/1/2 matrix of role and privilegeGRANT/REVOKE, local andON CLUSTER, matches the updated docs, and a refusedON CLUSTERstatement leaves nothing in the DDL queue.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132330]
Version info
26.11.1.2704-master(included in26.11and later)