Skip to content

fix(admin): report what a half-applied privilege change actually did - #525

Merged
EVWorth merged 1 commit into
mainfrom
fix/admin-partial-privilege-failure
Aug 29, 2026
Merged

EVWorth merged 1 commit into
mainfrom
fix/admin-partial-privilege-failure

Conversation

@EVWorth

@EVWorth EVWorth commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Refs #439.

The proposed fix isn't possible

The issue asks for a transaction around applyChanges. GRANT and REVOKE each force an implicit commit — verified against MySQL 8:

START TRANSACTION;
GRANT SELECT ON *.* TO 'txprobe'@'%';
ROLLBACK;
SHOW GRANTS FOR 'txprobe'@'%';
→ GRANT SELECT ON *.* TO `txprobe`@`%`

The grant survives. Wrapping the loop would have changed nothing while looking like a fix. This is recorded on the issue.

What is achievable

Fail in the safer direction. Every revoke is now emitted before any grant. Statements were previously interleaved by scope — global revoke, global grant, then database revoke, database grant — so an interruption between the global grant and a database revoke left the user holding more access than the admin intended. Being locked out of a schema is recoverable and immediately obvious; keeping a privilege someone believed they had removed is neither.

(I'd originally written a comment claiming revokes already came first, then checked the emission order and found they didn't. The ordering is now real rather than described.)

Say what happened. On failure the panel reports which statements applied, which failed and why, and which were never attempted — and states plainly that the applied ones cannot be rolled back:

Applied 1 of 3 statements, then failed.

Failed: GRANT UPDATE ON *.* TO 'alice'@'%'
  Error: Access denied

Already applied (GRANT and REVOKE cannot be rolled back):
  REVOKE SELECT ON *.* FROM 'alice'@'%'

Not attempted:
  FLUSH PRIVILEGES

The privilege list has been refreshed from the server.

Previously only the failing statement's error surfaced, from which the state of the server could not be worked out at all.

Re-read on failure too. After a partial failure the server holds a state nobody chose, so showing the optimistic edit as though it were real is the worst available option.

A bug the test caught

Writing the test found a bug in this fix: the re-read calls loadGrants, which does setError(null) as it starts — wiping the report immediately after it was set. The report is now applied after the reload completes. The test failed for exactly the right reason before that change.

1651 frontend tests, clippy/tsc/dprint clean.

🤖 Generated with Claude Code

The issue asked for a transaction around applyChanges. That is not possible:
GRANT and REVOKE each force an implicit commit, and a GRANT issued inside
START TRANSACTION survives a ROLLBACK — verified against MySQL 8 and recorded
on the issue. Wrapping the loop would have changed nothing while looking like
a fix.

What is achievable is failing in the safer direction and saying what
happened.

Every revoke is now emitted before any grant. Previously the statements were
interleaved by scope — global revoke, global grant, then database revoke,
database grant — so an interruption between the global grant and a database
revoke left the user holding more access than the admin intended. Being
locked out of a schema is recoverable and immediately obvious; keeping a
privilege someone believed they had removed is neither.

On failure the panel now reports which statements were applied, which one
failed and why, and which were never attempted — and says plainly that the
applied ones cannot be rolled back. The previous behaviour surfaced only the
failing statement's error, from which the state of the server could not be
worked out at all. The grants are re-read on failure as well as on success,
because after a partial failure the server holds a state nobody chose and
showing the optimistic edit as though it were real is the worst option
available.

Writing the test for that turned up a bug in the fix: the re-read calls
loadGrants, which clears the error as it starts, so the report was being
wiped immediately after being set. It is now applied after the reload.

Refs #439
@EVWorth
EVWorth merged commit 73455c0 into main Aug 29, 2026
9 checks passed
@EVWorth
EVWorth deleted the fix/admin-partial-privilege-failure branch August 29, 2026 16:57
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