Skip to content

fix(duckdb): read_only caveat allows only plain reads (TC-3035) - #607

Draft
samgbafa wants to merge 3 commits into
mainfrom
fix/sql-readonly-classification
Draft

samgbafa wants to merge 3 commits into
mainfrom
fix/sql-readonly-classification

Conversation

@samgbafa

@samgbafa samgbafa commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

DuckDB: a delegation with the read_only caveat now allows only plain reads, whatever its ability tier.

Behaviour

  • With read_only: true, a statement counts as read-only only if it is a query with no write inside it, EXPLAIN (with or without ANALYZE of a read), EXPLAIN TABLE, or a transaction statement (BEGIN, COMMIT, ROLLBACK).
  • Any other statement is refused with a read-only violation: PREPARE, EXECUTE, DEALLOCATE, CALL, COPY, ATTACH, SET, CREATE SCHEMA and so on. Statements added to the parser later are refused the same way until they are classified.
  • The read tier and every non-admin tier are unchanged: they already allowed only the statements they were granted.
  • Plain SELECT, WITH ... SELECT and EXPLAIN still run under read_only, for every tier.
  • New ParsedQuery::is_plain_read(): true only for queries, EXPLAIN TABLE and EXPLAIN without ANALYZE. It is the one rule for callers that decide whether a request can write, so the DuckDB storage floor (TC-2917: DuckDB disk headroom, spill limit and startup cache sweep #603) can use it rather than keep its own copy.
  • SQL (SQLite) is unchanged.

Tests

  • read_only_caveat_refuses_what_is_not_a_plain_read_for_admin: with an admin ability and read_only, INSERT, PREPARE ... AS INSERT/UPDATE/DELETE, EXECUTE, DEALLOCATE and EXPLAIN ANALYZE INSERT/UPDATE/DELETE are read-only violations; CALL, COPY ... TO, CREATE SCHEMA, CREATE SEQUENCE and ATTACH are refused.
  • read_only_caveat_refuses_explain_analyze_of_execute: EXPLAIN ANALYZE EXECUTE p is never allowed (a read-only violation, or a parse refusal).
  • read_only_caveat_still_allows_plain_reads_for_admin: SELECT, WITH ... SELECT, EXPLAIN, EXPLAIN ANALYZE SELECT, BEGIN, COMMIT still run.
  • only_queries_and_plans_are_plain_reads: the is_plain_read rule, including EXPLAIN ANALYZE and transactions.
  • Mutant checks, each run against the new tests and killed:
    • Restoring the old fall-through (_ => {}) fails the refusal test.
    • Counting EXPLAIN ANALYZE as plain fails the is_plain_read test.
    • Flagging transaction statements as writes fails the plain-reads test and the existing transaction test.

Local results: cargo test -p tinycloud-core --features duckdb --lib -- duckdb 55 passed; fmt and clippy -D warnings (tinycloud-core, duckdb feature, all targets) clean.

Details: TC-3035

This branch has not been deployed

No deployments
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.

1 participant