Skip to content

fix(admin): enforce read-only connections, and stop the app killing itself - #522

Merged
EVWorth merged 1 commit into
mainfrom
fix/admin-read-only-and-self-kill
Aug 29, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/admin-read-only-and-self-kill

Conversation

@EVWorth

@EVWorth EVWorth commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Refs #429, #433.

Two holes of the same shape: a protection that existed on paper and nowhere in the execution path.

read-only was enforced in exactly one place

read_only is stored on the profile, carried onto the live connection (since #512) — and checked only by EXPLAIN ANALYZE. Every other path ignored it. A read-only production profile would still run DROP TABLE from the editor, create accounts from the admin panel, or grant itself SUPER.

The executor now refuses any statement that could change data, schema, privileges or server state, before the batch is assembled, so a script whose second statement writes is rejected whole rather than half-run.

Classifying by leading keyword would have left two ways through, both covered:

Plain EXPLAIN stays allowed whatever it plans, because it only plans. The verb list is an allowlist, so an unrecognised statement is treated as a write and refused rather than waved through.

The app could disconnect itself

PROCESSLIST includes the sessions SQLPilot is using to read PROCESSLIST. Killing one worked; killing the last exhausted the pool and surfaced pool timed out, which never told the user what they had just done.

The pool now records each server thread it opens (in after_connect), kill_process refuses those, and the UI disables the button with an explanatory tooltip rather than letting the click fail. Other users' sessions stay killable. ERROR 1095 is translated into a message naming the missing privilege, since PROCESSLIST is visible to users who cannot act on it.

Writes now carry the account they ran as in the log line — the audit trail #429 asks for.

Two parts of #429 deliberately not done

Verification

65 integration tests against MySQL 8 + MariaDB 11, including:

  • a read-only connection still runs SELECT / SHOW / DESCRIBE / EXPLAIN / WITH ... SELECT
  • it refuses INSERT, UPDATE, DELETE, DROP, CREATE USER, GRANT, the CTE-laundered DELETE, and EXPLAIN ANALYZE DELETE
  • a mixed read-then-write script is refused and the rows are still there afterwards
  • kill_process refuses every thread the pool owns, and the connection still works after the refusal
  • a connection opened outside the pool is still killable

Plus 1635 frontend tests, including the disabled-button guard. clippy/tsc/dprint clean.

🤖 Generated with Claude Code

…tself

Two security holes in the admin area, both of the same shape: a protection
that existed on paper and nowhere in the execution path.

read_only was stored on the profile, carried onto the live connection, and
checked in exactly one place — EXPLAIN ANALYZE. Every other path ignored it.
A read-only production profile would still run DROP TABLE from the editor,
create accounts from the admin panel, or grant SUPER to itself. The executor
now refuses any statement that could change data, schema, privileges or
server state, before the batch is assembled, so a script containing a write
is rejected whole rather than half-run.

Classifying by leading keyword would have left two ways through, both
covered: `WITH doomed AS (...) DELETE` is a DELETE, and `EXPLAIN ANALYZE
<write>` executes the write it measures — so run through the ordinary Run
button, its leading EXPLAIN would have looked harmless. Plain EXPLAIN stays
allowed whatever it plans, since it only plans. The verb list is an
allowlist: an unrecognised statement is treated as a write and refused.

kill_process had no notion of which sessions belonged to SQLPilot, and
PROCESSLIST includes the connections the panel is using to read PROCESSLIST.
Killing one worked; killing the last exhausted the pool and surfaced "pool
timed out", which never told the user they had disconnected themselves. The
pool now records each server thread it opens, kill_process refuses those, and
the UI disables the button with a tooltip explaining why rather than letting
the click fail. Other users' sessions stay killable. ERROR 1095 is translated
into a message naming the privilege that is missing, since PROCESSLIST is
visible to users who cannot act on it.

Writes now carry the account they ran as in the log line, which is the audit
trail #429 asks for.

Two parts of #429 are deliberately not done. Parameterised SQL is not
available for DDL — MySQL takes no placeholders for identifiers or privilege
names, so correct quoting is the remedy, and that landed in #521. Wrapping
GRANT/REVOKE in a transaction is impossible: they force an implicit commit,
verified by a GRANT surviving ROLLBACK. That is recorded on #439.

Refs #429, #433
@EVWorth
EVWorth merged commit 00c7ff1 into main Aug 29, 2026
9 checks passed
@EVWorth
EVWorth deleted the fix/admin-read-only-and-self-kill branch August 29, 2026 15:14
EVWorth added a commit that referenced this pull request Aug 29, 2026
…ord (#526)

The frontend never receives credentials, so on edit it sends them back
absent, and the command layer fills them in from the store. It did that with
`if let Ok(stored)`, which treats every failure the same way: a keyring that
is locked, sandboxed or momentarily unavailable looked exactly like "this
profile has no stored password". The field stayed empty, and `save()` reads an
empty password as "the user cleared it" and calls `delete_password`. The user
edits a profile name, sees a success toast, and the credential is gone.

`ConnectionStore::get_existing` now returns `Option`, so the two outcomes have
different types and the call site has to decide. A profile that does not exist
is `None` — a new profile, where empty really is the intent. Anything else is
an error, and the save is refused with a message saying that nothing was
written and the stored password is untouched. `test_connection` had the same
pattern, where the cost was a false "Access denied" sending the user off to
debug credentials that were fine.

Also completes #277. Enforcement landed in #522; the other half of that issue
is a connection marked read-only being indistinguishable from any other until
the executor refuses something. Read-only connections now carry a lock in
their tab.

Two things found while testing:

The mock specifiers in ConnectionTabs.test.tsx resolve relative to the test
file, not the component, so `../../stores/connectionStore` pointed at
`src/components/stores/…`, which does not exist. None of that file's mocks
were ever applied — the tests ran against the real stores and asserted only
things that held either way. Fixed, which is what let the new tests render a
tab at all.

Three ConnectionStore tests were swept up by the blanket #[ignore] in #516.
They touch only the store and an in-memory keyring, so they are back on the
ordinary test path where they belong; CI has no database services, so a green
Test Rust job is the proof they need none.

Refs #274, #277
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