fix(auth): reject RotateAPIKey when SoftDelete affects 0 rows - #822
Conversation
Deterministic fake-repo tests for concurrent RotateAPIKey and Rotate-vs-Delete SoftDelete races. Both fail on current :exec SoftDelete behavior (loser still mints a successor). Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Switch SoftDeleteModelRouterAPIKey to :execrows and have RotateAPIKey bail with ErrAPIKeyNotFound when SoftDelete matches no row, closing the concurrent-rotate and rotate-vs-delete zombie-key races from #817. DeleteAPIKey keeps discarding the count for idempotent success. Also lands the DB-backed repro scripts referenced by #817. Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: rohith500 <rohith500@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
PR author is not in the allowed authors list. |
|
Claude finished @devin-ai-integration[bot]'s task —— View job 🤖 Claude Code Review
Posted advisory comment-length nits on 2 blocks:
|
workweave-bot
left a comment
There was a problem hiding this comment.
Advisory only — comment-length nits. Won't block merge.
|
Claude finished @devin-ai-integration[bot]'s task —— View job Claude finished @devin-ai-integration[bot]'s task — View job 🤖 Claude Code Review
Posted advisory comment-length nits on 2 blocks in
|
workweave-bot
left a comment
There was a problem hiding this comment.
Advisory only — comment-length nits. Won't block merge.
|
Claude finished @devin-ai-integration[bot]'s task —— View job 🤖 Claude Code Review
Posted advisory comment-length nits on 2 blocks:
|
workweave-bot
left a comment
There was a problem hiding this comment.
Advisory only — comment-length nits. Won't block merge.
|
Claude finished @devin-ai-integration[bot]'s task —— View job 🤖 Claude Code Review
Posted advisory comment-length nits on 3 blocks:
|
workweave-bot
left a comment
There was a problem hiding this comment.
Advisory only — comment-length nits. Won't block merge.
Summary
Compliance rewrite of #819 by @rohith500 (thanks!). Fixes #817:
RotateAPIKeyno longer mints a successor when its ownSoftDeletematches 0 rows (a lost race against a concurrent Rotate or a Delete), which previously produced untracked "zombie" credentials.Production logic and tests are preserved verbatim from #819; the only delta is trimming godoc/SQL comments to the repo's comment convention (root
CLAUDE.mdline 15: concise, no multi-paragraph, no pre-fix narrative, no caller references).Behavior:
Coverage (unchanged from #819): in-memory fake-repo race tests in
internal/auth/rotate_race_test.go(concurrent Rotate → exactly one success; Rotate-vs-Delete → no zombie), plus live-Postgres repro scripts underscripts/{rotate_key_race_check,rotate_key_race_ext_check,upsert_external_key_race_check}(per the AGENTS.md rule that DB-backed checks live inscripts/, notinternal/*_test.go).make generate+make precommitgreen.Co-authored-by: rohith500 rohithreddy2202@gmail.com
Link to Devin session: https://app.devin.ai/sessions/03fe47e3946a4829b431a2e2a35c1606
Requested by: @steventohme