Skip to content

Docs: fix the "Permissions for queries" page (HTTP readonly default, lightweight UPDATE and DELETE, mutations, RBAC) - #118184

Merged
alexey-milovidov merged 9 commits into
ClickHouse:masterfrom
groeneai:docs-permissions-for-queries-115699
Sep 13, 2026
Merged

alexey-milovidov merged 9 commits into
ClickHouse:masterfrom
groeneai:docs-permissions-for-queries-115699

Conversation

@groeneai

@groeneai groeneai commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #115699
Related: #115697
Related: #115287

Changelog category (leave one):

  • Documentation (changelog entry is not required)

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

Corrected and completed the "Permissions for queries" documentation page.

Description

permissions-for-queries:

  • lightweight DELETE/UPDATE and ALTER TABLE ... DELETE/UPDATE added to "Write data queries",
    plus an "Access management queries" category linking to the RBAC docs;
  • readonly: over HTTP, any method other than POST runs with 2, not 1, and only from an effective
    0, so a stricter profile value survives but an explicit 0 does not; PUT/DELETE at a SQL-defined
    handler skip the bump but still obey the effective value; a query-string readonly is refused, not
    clamped; GRANT is refused, while a local REVOKE and GRANT CURRENT GRANTS are not gated;
  • deleted the <Tip> calling EXISTS/DESCRIBE/EXPLAIN/SHOW PROCESSLIST "equivalent to SELECT";
  • allow_ddl = 0 lists the privileges it blocks; it blocks neither CREATE TEMPORARY TABLE, granting,
    nor ATTACH PARTITION/ATTACH PART, which need only INSERT; the ... FROM form is blocked.
    Neither setting restricts ALTER DATABASE, UNDROP TABLE or named collection management;
  • KILL QUERY: your own needs no KILL QUERY privilege but does need SELECT on system.processes;
    another user's, and any ON CLUSTER, need the privilege, which readonly refuses;
  • new section for allow_introspection_functions and allow_non_metadata_alters.

table-functions/index.mdx said the opposite: they need CREATE TEMPORARY TABLE, so
readonly = 1 blocks them, not allow_ddl.

Duplicate readonly docs: of three copies, the DECLARE keeps the value semantics,
permissions-for-queries#readonly owns the query classes (losing Possible values:), and
constraints-on-settings#read-only keeps only the constraint-type disambiguation.

#115697: the wrong HTTP default is fixed here and 00305_http_and_readonly.sh already asserts it,
so no test is added. The readonly = 2 transition table is deferred to #115695, per @ ringerc.

Left undocumented on purpose: readonly versus SET ROLE and role grants (#115691 contests it), and
the BACKUP/RESTORE and SQL-defined handler policies themselves; what readonly does to each is
stated. The autogenerated DECLARE summary still calls values 1 and 2 read-only (fix belongs in
src/Core/Settings.cpp).


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

Version info

  • Merged into: 26.9.1.1358 (included in 26.9 and later)

groeneai and others added 6 commits September 4, 2026 09:09
The page is what an operator reads to learn which statements each value of
`readonly` and `allow_ddl` permits, and it was both incomplete and wrong. It was
written when those two settings were the whole story and was never re-derived as
the code grew: every permission decision now runs through
`ContextAccess::checkAccessImplHelper` (`ContextAccess.cpp:690-886`), whose flag
sets the page's taxonomy predates. On a permissions page a false sentence is
worse than a gap, because a "locked-down" session gets built on it.

Corrected, each against the enforcing line and measured on a running server as a
real user:

- lightweight `DELETE` and `UPDATE` and `ALTER TABLE ... DELETE`/`UPDATE` were
  missing from "Write data queries", and there was no access management category
  at all.
- The HTTP paragraph said the `GET` method sets `readonly = 1`. It is `2`
  (`setReadOnlyIfHTTPMethodIdempotent.cpp:34-35`), the trigger is any method
  other than `POST`, and it applies only when the effective value is 0, so a
  profile that already pins a stricter value keeps it.
- The refusal list is now enumerated rather than quantified. Both
  `not_readonly_flags` (`:828`) and its complement are open sets, so "all DDL
  queries" was falsifiable as written; `CREATE_TEMPORARY_TABLE` is in neither
  `table_ddl` nor `ddl_flags`, and temporary tables are exempt above both gates
  (`:733-741`).
- The `<Tip>` calling `EXISTS`, `DESCRIBE`, `EXPLAIN` and `SHOW PROCESSLIST`
  "equivalent to `SELECT`" is removed. They are authorized with `SHOW_*` and
  `SHOW_COLUMNS`, not `SELECT`, and `EXPLAIN PIPELINE INSERT` reaches the
  `INSERT` check, which `readonly` refuses.
- `allow_ddl = 0` now names the privileges it blocks. It blocks neither
  `CREATE TEMPORARY TABLE`, named collection management and
  `ALTER DATABASE ... MODIFY SETTING`, nor granting: `:871` exempts the
  grant-option path.
- `KILL QUERY` is qualified on both dimensions. Killing your own query consults
  no privilege (`InterpreterKillQueryQuery.cpp:112-125`), while another user's
  query and any `ON CLUSTER` form require `KILL QUERY`, which is in
  `not_readonly_flags`. The `ON CLUSTER` path has no ownership branch at all
  (`:209-214` to `:473-479`).
- A new section covers `allow_introspection_functions`, the third setting inside
  the permission decision (`ContextAccessParams.cpp:203-205` names exactly three),
  and `allow_non_metadata_alters`.

`readonly` was documented in three places, worded inconsistently. The `DECLARE`
in `src/Core/Settings.cpp` keeps the value semantics and is left untouched, since
its "changing explicitly allowed settings" already covers both mechanisms in
`SettingsConstraints::getChecker`. This page keeps the query-class semantics and
loses its duplicated `Possible values:` block. `constraints-on-settings#read-only`
keeps only the disambiguation between the `readonly` setting and the `readonly`
constraint type, which exists nowhere else, and links on. One copy per aspect.

`table-functions/index.mdx` asserted the opposite of this page, that table
functions need `allow_ddl`. They need `CREATE_TEMPORARY_TABLE`
(`ITableFunction.cpp:78-80`), which is not in `ddl_flags`, so it is `readonly = 1`
that blocks them.

No test is added: `00305_http_and_readonly.sh` with its reference already asserts
the HTTP value, and `00716_allow_ddl.sql:6-7` already pins that `allow_ddl = 0`
refuses `ALTER ... DELETE` and `RENAME`. That last one also settles a point in
the report: the `ALTER` mutations write data, but their privileges are
`ALTER DELETE` and `ALTER UPDATE` inside the `ALTER TABLE` group, so `allow_ddl`
does refuse them, and the page states the measured behaviour.
Follow-up to the previous commit on this branch. Four sentences it shipped are
false against the code they describe, and one link lost its checker coverage. Each
correction below is measured on a running server as a real user, since
`Context.cpp:2455` sets `full_access = !user_id` and a no-user context passes every
check.

- The HTTP paragraph contradicted itself and was wrong twice. A `readonly`
  parameter in the query string is not applied and clamped: `SettingsConstraints`
  refuses any change to `readonly` while the current value exceeds 1 (`:620-621`),
  testing only the current value, so a *stricter* `?readonly=1` is refused as well.
  Only a value equal to the one already in force survives, because an unchanged
  value is dropped before the checker runs (`:362-364`, `:390-398`). An explicitly
  configured `readonly = 0` is not kept either: the bump tests `== 0`
  (`setReadOnlyIfHTTPMethodIdempotent.cpp:34-35`) and cannot tell an explicit 0
  from the default, so only stricter values survive. And the opening "any method
  other than `POST` implies read-only" plus the closing "use `POST` to modify data"
  both denied the paragraph's own `PUT`/`DELETE` parenthetical, which
  `04306_create_handler_http.sh:117-124` shows is the true half.

- `allow_ddl = 0` does not block `ALTER TABLE ... ATTACH PARTITION`. It requires
  only `INSERT` (`InterpreterAlterQuery.cpp:833-837`), and `ddl_flags`
  (`ContextAccess.cpp:831`) contains no `INSERT`, though `not_readonly_flags`
  (`:828`) does, so `readonly` blocks it while `allow_ddl` does not. The error was
  in the permissive direction: an operator relying on `allow_ddl = 0` to stop data
  being attached to a table was misled. The sibling `DETACH PARTITION` reaches
  `ALTER_DELETE` and is blocked, so the asymmetry sits inside the pair the sentence
  names, and both `ATTACH` spellings map to the same command type
  (`ParserAlterQuery.cpp:657,689`).

- Killing your own query does need a privilege. It does not need `KILL QUERY`, but
  `InterpreterKillQueryQuery.cpp:221` reads `system.processes` before the same-user
  exemption at `:114-121`, that table is absent from `always_accessible_tables`
  (`ContextAccess.cpp:200-235`), and `select_from_system_db_requires_grant`
  defaults to true (`AccessControl.cpp:300`). Revoking that one grant turns the
  kill into `ACCESS_DENIED` naming it, and the target query survives.

- The `readonly` section said nothing about `GRANT`, which `readonly` refuses
  (`ContextAccess.cpp:855-856`, on every grant-option check regardless of flags),
  while the `allow_ddl` note volunteers that it does not restrict access
  management. Read together the two sections implied neither setting restricts
  granting. `REVOKE` (`InterpreterGrantQuery.cpp:194-195`) and
  `GRANT CURRENT GRANTS` (`:506-507`) genuinely are not gated, so the page now
  gives the split rather than either half.

`readonly` is backticked in the `table-functions` note, and a blank line follows
each `<Note>`: without it CommonMark treats the first paragraph as a raw HTML
block, so `lychee` never extracts the link and the blocking internal-links check
gives it no coverage. Verified both ways, and this restores coverage the previous
commit would otherwise have removed from the `[HTTP interface]` link.

Role grants and `SET ROLE` stay undocumented on purpose while their behaviour is
still under discussion.

Co-Authored-By: Claude Opus 5 <[email protected]>
Three claims on the page named a statement spelling that stands for a family of
forms whose privileges differ, so each was true of some forms and false of
others.

ALTER DATABASE is restricted by neither setting. ALTER_DATABASE_SETTINGS and
ALTER_MODIFY_DATABASE_COMMENT sit in the ALTER_DATABASE group, a sibling of
ALTER_TABLE, and ContextAccess.cpp names neither of them, so the bare ALTER in
the refusal list is narrowed to ALTER TABLE and ALTER VIEW and the allow_ddl
note now carries both settings for that statement.

The allow_ddl carve-out for ATTACH PARTITION was wrong in both directions.
ATTACH PARTITION ... FROM parses to REPLACE_PARTITION, which needs ALTER DELETE
in the same access element, so allow_ddl = 0 does block that spelling; ATTACH
PART needs only INSERT and was not named.

REVOKE ... ON CLUSTER is refused by readonly. The on-cluster branch sets
grant_option on revoked elements and checks them before the local fast path is
reached, so only the local form is ungated.

A systematic pass over the two sentences that name statement spellings rather
than privileges found one more instance of the same defect: named collection
management is in neither flag set, because NAMED_COLLECTION_ADMIN descends from
ALL rather than from ACCESS_MANAGEMENT, so readonly does not restrict it.

Every claim was measured against a running server as real users, with each arm
sharing one session with its own controls, and with an ordering proof wherever a
statement was observed to succeed.

Also removes the readonly default value restated on this page, since the section
already delegates the values and the default to the settings reference, and says
"Some" rather than "A few" for the table functions allowed in read-only mode,
since 24 of them set allow_readonly.
The `readonly` DDL enumeration said `TRUNCATE`, which reads as a claim about
every statement spelled with that word. It now says `TRUNCATE TABLE`, the
statement whose privilege the setting refuses, so the entry is true of every
form it names. The DDL taxonomy at the top of the page and the `allow_ddl`
privilege list keep the bare word on purpose: the first classifies the
statement, the second is attributed to privileges rather than to statements.

The table-function note said "you can't use them", which is broader than the
gate it describes. The `CREATE TEMPORARY TABLE` check runs in
`ITableFunction::execute`, so the note now names the verbs that reach it, a
`SELECT` or an `INSERT` that executes the function. That is also the wording
the permissions page already uses for the same rule.

Co-Authored-By: Claude Opus 5 <[email protected]>
Two sentences added earlier in this PR named a statement family whose members
differ, so each was true of some members and false of others. Both erred in the
unsafe direction: they promised a restriction that does not exist, so an
operator hardening a session would have been misled.

The blocked-privileges bullet and the `ATTACH PARTITION` carve-out were
unscoped. `ContextAccess::checkAccessImplHelper` returns `access_granted()` when
the target is in the temporary database (`src/Access/ContextAccess.cpp:739`,
inside `if (parameter_type == AccessFlags::NONE)` at `:732`), and that early
return sits above both the `readonly` gate (`:853-869`) and the `allow_ddl` gate
(`:871-876`). Every table-level privilege on an existing temporary table
therefore escapes both settings, not just the `INSERT` and `DROP TABLE` the page
named. Measured as a real user: `ALTER TABLE <temporary> MODIFY COLUMN`
succeeds at `allow_ddl = 0` and at `readonly = 2` and the column type does
change, while the same statement on a persistent table in the same session
returns `QUERY_IS_PROHIBITED` and `READONLY` and the type does not move.
`ATTACH PARTITION` on a temporary `MergeTree` also succeeds at `readonly = 2`,
since it needs `INSERT` alone (`InterpreterAlterQuery.cpp:833-836`), against a
persistent control refused with `READONLY`.

The exemption sentence keeps its "a session that may create one" precondition,
because creating a temporary table is not exempt: `CREATE_TEMPORARY_TABLE` is
`not_readonly_1_flags` (`ContextAccess.cpp:829`), so `readonly = 1` refuses it.
It stays a verb list rather than a universal quantifier, because the early
return is guarded by `parameter_type == AccessFlags::NONE` and a privilege
carrying a parameter type does not take it.

"Access management queries are unaffected by `allow_ddl`" was true of the
statement and false of an embedded `SETTINGS` clause. `CREATE` and `ALTER` of a
user, a role or a settings profile run that clause through the session's own
settings constraints (`InterpreterCreateUserQuery.cpp:318`,
`InterpreterCreateRoleQuery.cpp:66`,
`InterpreterCreateSettingsProfileQuery.cpp:71`), and
`SettingsConstraints::getChecker`'s first branch refuses `allow_ddl` when the
session already has it disabled (`SettingsConstraints.cpp:610-611`). The
qualifier "when it changes the value" is measured rather than inferred: an
unchanged value never reaches `getChecker`, because `getNewValueToCheck` returns
an empty `Field` on the `!ignore_unchanged_settings` branch
(`SettingsConstraints.cpp:361-362`) and `checkImpl` returns on
`new_value.isNull()` (`:435-436`). So `SETTINGS allow_ddl = 1` is refused while
`SETTINGS allow_ddl = 0` in a session already at 0 is accepted. All six
`CREATE`/`ALTER` by user/role/settings-profile combinations were measured, and
`SETTINGS allow_introspection_functions = 1` was measured accepted, which
confines the new sentence to `allow_ddl`.

The `readonly` section gets no symmetric sentence. Under any `readonly > 0` the
access-management statement is already refused by the access gate, because
`write_dcl_access` is inside `not_readonly_flags` (`ContextAccess.cpp:826,828`),
so no embedded-setting case is reachable there.

Also adds the blank line after the `allow_ddl` `<Note>` opening tag, so its
first paragraph is parsed as Markdown like the other two Notes on the page.

Co-Authored-By: Claude Opus 5 <[email protected]>
Each of the three narrowed sentences was added earlier in this PR to fix a
finding, and each replacement carried a new imprecision in the same unsafe
direction: it promised a restriction, or an exemption, wider than the one the
enforcement code implements.

`REVOKE ... ON CLUSTER` is refused only for privileges. A role revocation and a
privilege revocation take different authorization paths. For
`REVOKE <role> FROM <user> ON CLUSTER` there are no privilege elements, so
`getRequiredAccessForExecutingOnCluster` returns an empty `AccessRightsElements`
and its `element.grant_option = true` stamping has nothing to stamp
(`src/Interpreters/Access/InterpreterGrantQuery.cpp:269-275`). Authorization
runs instead through `checkAdminOptionForExecutingOnCluster` (`:281-314`), and
because `ROLE_ADMIN` sits inside `write_dcl_access` and therefore inside
`not_readonly_flags` (`src/Access/ContextAccess.cpp:828`),
`isGranted(AccessType::ROLE_ADMIN)` is false in a read-only session and the code
falls to the per-role `checkAdminOption`. That path has no `readonly` gate: the
only `readonly` sites in that file are `:493`, `:828-829` and `:853-867`.
`executeDDLQueryOnCluster.cpp:187` then checks the empty list and passes.
Measured in one `readonly = 1` session as a real user holding the role with
admin option: `REVOKE <role> FROM <user> ON CLUSTER` succeeds and the grant
disappears from `SHOW GRANTS`, while `REVOKE SELECT ON <table> FROM <role> ON
CLUSTER` in that same session returns `Cannot change grants in readonly mode`
and the privilege survives. The page stays silent about role grants, which
ClickHouse#115691 contests.

The embedded `allow_ddl` clause is keyed on the session, not on the change.
"Refused when it changes the value" has no stated antecedent, and read as
target-relative it is false in both directions. `SettingsConstraints.cpp:611-612`
returns the Checker on `!current_settings[Setting::allow_ddl]` alone, with no
reference to the target entity's stored value, and `getNewValueToCheck`
(`:362-363`) drops a change whose value equals the session's current value
before the checker is consulted. So `SETTINGS allow_ddl = 1` is refused while
the session has 0, and `SETTINGS allow_ddl = 0` is accepted, which is what the
measurements in this PR already showed.

A `PUT` or `DELETE` at a SQL-defined handler can modify data only while the
effective `readonly` is 0. `setReadOnlyIfHTTPMethodIdempotent` can only raise
the value from 0 to 2: when the method is mutating the whole forcing block is
skipped, and the forcing itself is guarded by
`if (context->getSettingsRef()[Setting::readonly] == 0)`
(`src/Server/HTTP/setReadOnlyIfHTTPMethodIdempotent.cpp:23-36`). It never lowers
a value, so a user whose profile pins `readonly = 1` carries that value into the
request and a modifying query is still refused. The unconditional clause
contradicted the paragraph's own preceding sentence about a stricter profile
value being kept. Measured against a handler declared `METHODS (PUT)`: the
handler's query sees `readonly` 1 for a user whose profile pins 1 and 0 for an
unrestricted user, and an `INSERT` through it is refused for the former with
`Cannot execute query in readonly mode` while inserting a row for the latter.
The same sentence stops naming `CREATE HANDLER` as the only origin, since
`ALTER HANDLER ... METHODS (...)` can also supply the accepted method set
(`src/Common/SQLDefinedHandlers/SQLDefinedHandlerFromAST.cpp:574-575`), and now
links the statement.

`UNDROP TABLE` joins the list of statements neither setting restricts.
`AccessType.h:273` declares it with parent `ALL`, so the flag is in neither
`ddl_flags` (`ContextAccess.cpp:831`) nor `not_readonly_flags` (`:828`), and
`InterpreterUndropQuery.cpp:33` checks only `AccessType::UNDROP_TABLE`.
Measured as OK at `allow_ddl = 0` and at `readonly = 1`, in each case against a
`CREATE TABLE` control refused in the same session, and against a `DROP TABLE`
of the same table refused by both settings.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Every sentence on these pages was re-derived from the enforcing source and then measured on a running
server with a real non-default user; independent review rounds re-checked each claim against the source
and the in-tree tests. The corrections themselves are visible in the diff. Recorded below are only the
findings I disagreed with, and the residuals I am deliberately not fixing here.

⚠️ Not restoring the deleted <Tip>. It called EXISTS/DESCRIBE/EXPLAIN/SHOW PROCESSLIST
"equivalent to SELECT". False on outcome — EXPLAIN PIPELINE INSERT INTO t VALUES (1) is refused at
readonly = 1 — and false on mechanism, since EXISTS is authorized with SHOW_* and DESCRIBE with
SHOW_COLUMNS, neither being SELECT. Any replacement blanket claim would be equally false.

⚠️ Not rewriting the allow_non_metadata_alters sentence. ALTER ... CLEAR COLUMN is refused while
changing no metadata, so the sentence does not define the refused set. It does paraphrase the setting's
own description in src/Core/Settings.cpp, and this page deliberately enumerates no statements for the
setting so it stays true across #115287, which rewrites that description. "Requires a mutation" is not a
valid replacement either: ALTER ... DELETE requires one and is not refused, because a standalone
mutation never reaches checkAlterIsPossible.

⚠️ Not widening the table-function note to INSERT. For INSERT INTO FUNCTION the allow_readonly
property is ignored, so it is every table function rather than most. The note names no exemption a
reader could carry over to INSERT, "Most" matches the population (24 of 86 registrations set
allow_readonly), and 02473_functions_in_readonly_mode pins refusal for both verbs.

⚠️ Both lists on the page are openly non-exhaustive, so an omission is not a false claim.
BACKUP/RESTORE under readonly = 2 and the role-grant semantics #115691 contests are out of scope
and noted in the description. The value semantics stay in one place, the setting's own reference page.

💡 One residual, disclosed and not raised: with the <Tip> gone, the surviving phrase "and equivalent
queries" no longer has a definition on the page.

The 8 localized copies of each page are deliberately untouched; the translation workflow generates them.

@clickhouse-gh clickhouse-gh Bot closed this Sep 4, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 4, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @pufit, could you review this? It re-derives the "Permissions for queries" page from the three gate blocks in ContextAccess::checkAccessImplHelper, so the page now states the privilege sets not_readonly_flags and ddl_flags actually test instead of universal claims that several statements falsify. The HTTP correction is the user-visible one: a non-POST request runs with readonly = 2, not 1, and only when the effective value would otherwise be 0.

@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [79ed43c]

Summary: ✅


AI Review

Summary

This PR substantially improves the permissions-for-queries documentation and fixes the previously wrong HTTP readonly default, but two user-visible permission exceptions are still described inaccurately in the current text. Because this page is acting as the permission contract, I do not think it is ready to approve with those gaps left in place.

Findings

⚠️ Majors

  • [docs/concepts/features/configuration/settings/permissions-for-queries.mdx:61] The page still documents temporary tables as the session-scoped DDL exception to readonly / allow_ddl, but CREATE TEMPORARY VIEW is authorized through AccessType::CREATE_TEMPORARY_VIEW, which is outside both not_readonly* and ddl_flags. Readers will still believe those settings fence off temporary views when they do not.
    Suggested fix: mention temporary views alongside temporary tables in the readonly and allow_ddl exception text.

  • [docs/reference/functions/table-functions/index.mdx:88] The new note conflates the SELECT and INSERT INTO FUNCTION rules. ITableFunction::execute always checks CREATE TEMPORARY TABLE on the insert path, so even readonly-safe functions are still refused at readonly = 1 when used as INSERT INTO FUNCTION. The current "Most table functions..." wording implies the readonly exceptions can carry over to inserts.
    Suggested fix: split the rule into "most table functions for SELECT" versus "all table functions for INSERT INTO FUNCTION".

Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: document the temporary-view exception to readonly / allow_ddl, and clarify that INSERT INTO FUNCTION is refused at readonly = 1 for all table functions.

@clickhouse-gh clickhouse-gh Bot added the comp-documentation Documentation (docs, examples, READMEs). label Sep 5, 2026
groeneai and others added 2 commits September 5, 2026 00:32
…adata_alters` rule

Two claims on the page were narrower than the code enforces.

`readonly = 2` was documented as adding only `SET` and `CREATE TEMPORARY TABLE`.
`src/Backups/BackupsWorker.cpp:986` refuses `RESTORE` at `readonly == 1` only, and
`src/Backups/RestorerFromBackup.cpp:378-381` tests `AccessRights::contains` directly and
returns before `context->checkAccess`, so the readonly gate in `checkAccessImplHelper` is
never reached for a session that already holds the required rights. Measured on a running
server: at `readonly = 2` a `RESTORE TABLE ... AS <new table>` creates the table and loads
its rows, while the same statement at `readonly = 1` gives `Cannot execute RESTORE in
readonly mode`; an `INSERT` in that same `readonly = 2` session is still refused with
`Code: 164`. An HTTP `GET` request, which runs at `readonly = 2`, restores as well. Every
read of `Setting::readonly` in `src/` was enumerated, and exactly three sites discriminate
1 from 2: `src/Access/SettingsConstraints.cpp:631` (`SET`),
`src/Access/ContextAccess.cpp:858` (`CREATE TEMPORARY TABLE`) and the `RESTORE` site above.
The list is therefore complete, which is why it stays an enumeration rather than becoming
open-ended.

`allow_non_metadata_alters` was documented as refusing an `ALTER` that changes metadata and
would also rewrite data. `src/Storages/MergeTree/MergeTreeData.cpp:5040-5049` keys on
whether the command yields mutation commands, not on whether metadata changes, so
`CLEAR COLUMN`, `CLEAR INDEX` and `CLEAR PROJECTION` are refused too. Measured:
`CLEAR COLUMN` gives `Code: 524` when the setting is disabled, and when it is enabled it
leaves `create_table_query` byte-identical while blanking the column's values. The refused
forms are now given by example rather than as a universal, because the standalone mutations
`ALTER ... DELETE`, `ALTER ... UPDATE` and the whole `MATERIALIZE` family are permitted
when the setting is disabled, so a "requires a mutation" rule would be false for them.

Both claims were raised by the automated reviewer on this pull request.

Co-Authored-By: Claude Opus 5 <[email protected]>
…mands

The previous wording said "a command that changes the columns, indexes, projections or
TTL", which does not separate a definition change from a data change: `ALTER ... UPDATE`
changes column values and `MATERIALIZE INDEX` builds index data, so both read as covered
by that phrase while `src/Storages/MergeTree/MergeTreeData.cpp:5040-5049` never sees
them. `MergeTreeData::checkAlterIsPossible` runs only on the `AlterCommands` segments of
a statement; commands that parse into `MutationCommands` go straight to `mutate`.

Measured with the setting disabled: `ALTER ... DELETE`, `ALTER ... UPDATE`, lightweight
`DELETE FROM`, and `MATERIALIZE INDEX`, `MATERIALIZE PROJECTION`, `MATERIALIZE COLUMN`
and `MATERIALIZE TTL` all succeed, the last two against fixtures that arm them (a column
with a `DEFAULT` expression and a table with a `TTL`); `DROP COLUMN`, `RENAME COLUMN`, a
`MODIFY COLUMN` type change, `MODIFY TTL`, `CLEAR COLUMN`, `CLEAR INDEX` and
`CLEAR PROJECTION` all give `Code: 524`.

Co-Authored-By: Claude Opus 5 <[email protected]>
The readonly section lists RESTORE as a value-2-only capability and says nothing
about BACKUP, which invites the reader to assume BACKUP follows the same rule.
It does not: BACKUP is not readonly-gated at all.

src/Backups/BackupsWorker.cpp:986 is the only read of Setting::readonly under
src/Backups/, and it sits in RestoreStarter's constructor, so the backup path has
none. BackupUtils::getRequiredAccessToBackup emplaces AccessType::BACKUP only
(src/Backups/BackupUtils.cpp:65-98), and AccessType::BACKUP is in neither
not_readonly_flags nor not_readonly_1_flags (src/Access/ContextAccess.cpp:828-829,
where write_table_access is INSERT | OPTIMIZE and not_readonly_1_flags is
CREATE_TEMPORARY_TABLE alone).

Measured on a running server as a non-default user over HTTP with a session_id,
because Context sets full_access = !user_id and a no-user context would pass every
check. A user granted BACKUP on the table plus READ, WRITE ON DISK gets
BACKUP_CREATED at readonly 0, 1 and 2 and over a plain HTTP GET, while in the same
sessions INSERT is refused with code 164 and RESTORE with code 497. The backup
written at readonly = 1 restores to a table holding the source rows [1,2,3], so it
is a real backup rather than an empty no-op. A user without the BACKUP privilege is
refused, which is what makes those results non-vacuous.

Co-Authored-By: Claude Opus 5 <[email protected]>
a privilege it holds with grant option and propagate its own grants to another user.
Revoking a privilege `ON CLUSTER` is refused.

Temporary tables are exempt from both settings: a session that may create one may also `ALTER` it,

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.

CREATE TEMPORARY VIEW is another public DDL surface that sits outside both gates, so documenting temporary tables as the only exception here is still too narrow. InterpreterCreateQuery::getRequiredAccess checks AccessType::CREATE_TEMPORARY_VIEW for that syntax, and ContextAccess does not include that flag in either not_readonly_flags / not_readonly_1_flags or ddl_flags. As written, readers will still assume readonly and allow_ddl fence off temporary views when they do not. Please mention temporary views alongside temporary tables here (and in the allow_ddl note below).

<Note>
You can't use table functions if the [allow_ddl](/reference/settings/session-settings/allow#allow_ddl) setting is disabled.

Most table functions need the `CREATE TEMPORARY TABLE` privilege to run, so a `SELECT` or `INSERT`

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.

SELECT and INSERT INTO FUNCTION do not follow the same readonly rule. In ITableFunction::execute, is_insert_query forces the CREATE TEMPORARY TABLE check unconditionally, so even functions registered with allow_readonly = true are still refused at readonly = 1 when used as INSERT INTO FUNCTION (for example null). The current "Most table functions..." wording makes it sound like the readonly-safe exceptions also carry over to inserts. Could you split those cases and say that INSERT INTO FUNCTION is refused at readonly = 1 for all table functions?

@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
Merged via the queue into ClickHouse:master with commit 441ab0d Sep 13, 2026
175 checks passed
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-documentation Documentation (docs, examples, READMEs). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-documentation Documentation PRs for the specific code 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.

Docs: "Permissions for queries" is missing lightweight UPDATE and DELETE, does not mention RBAC

3 participants