Repository navigation
fix(admin): report what a half-applied privilege change actually did - #525
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #439.
The proposed fix isn't possible
The issue asks for a transaction around
applyChanges.GRANTandREVOKEeach force an implicit commit — verified against MySQL 8: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:
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 doessetError(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