Skip to content

Disable functions in readonly for inserts - #44290

Merged
nikitamikhaylov merged 4 commits into
masterfrom
Disable_functions_in_readonly_for_inserts
Jan 3, 2023
Merged

nikitamikhaylov merged 4 commits into
masterfrom
Disable_functions_in_readonly_for_inserts

Conversation

@SmitaRKulkarni

@SmitaRKulkarni SmitaRKulkarni commented Dec 15, 2022 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvements

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Disable functions in readonly for inserts

Implementation:

  • Added a new parameter to ITableFunction::execute to check if query is insert query.
  • Used the new parameter in InterpreterInsertQuery::getTable function when calling ITableFunction::execute .

Testing:

  • Added test case for INSERT in 02473_functions_in_readonly_mode.sh.

Implementation:
* Added a new parameter to ITableFunction::execute to check if query is insert query.
* Used the new parameter in InterpreterInsertQuery::getTable function when calling ITableFunction::execute .
Testing:
* Added test case for INSERT in 02473_functions_in_readonly_mode.sh.
@SmitaRKulkarni
SmitaRKulkarni marked this pull request as draft December 15, 2022 18:52
@nikitamikhaylov nikitamikhaylov self-assigned this Dec 15, 2022
@SmitaRKulkarni
SmitaRKulkarni marked this pull request as ready for review December 19, 2022 07:42
@nikitamikhaylov

Copy link
Copy Markdown
Member

AST Fuzzer (debug) - OOM while executing this query SELECT i FROM generateRandom('i Array(String)', NULL, 1048575) LIMIT 1048575
AST Fuzzer (tsan) - No server logs...

$CLICKHOUSE_CLIENT --query="SELECT * from format('TSV', '123')"

$CLICKHOUSE_CLIENT --readonly=1 --query="SELECT * from numbers(1)"
$CLICKHOUSE_CLIENT --readonly=1 --query="SELECT * from format('TSV', '123')" 2>&1 | grep -Fq "Cannot execute query in readonly mode. (READONLY)" && echo 'ERROR' || echo 'OK'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@SmitaRKulkarni Why can't we execute this query in readonly mode?

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.

Only certain functions are allowed in readonly mode (format is not one of them) : #42708
This is an existing test. I used the same test file, changed it's extension to .sh and appended new insert tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay

@nikitamikhaylov
nikitamikhaylov merged commit 16fca48 into master Jan 3, 2023
@nikitamikhaylov
nikitamikhaylov deleted the Disable_functions_in_readonly_for_inserts branch January 3, 2023 14:25
jkartseva pushed a commit to lazerg/ClickHouse that referenced this pull request Nov 19, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants