Repository navigation
Report the upstream row deleted after a failed persist - #7324
Conversation
When the IdP rotated the refresh token but the new one could not be saved, the refresher deletes the stale row, but its error did not say so. Callers that classify by cause could not tell this from a transient failure on a row that still exists. The refresher now returns an error that wraps both storage.ErrNotFound and the persist error once the delete succeeded. If the delete fails too, the row still exists and the error is unchanged. Observable change: the refresh grant guard now refuses (without revoking) one refresh grant earlier, when a rotated refresh token could not be saved and its row was deleted. Before, that case looked transient and the grant was allowed, and the client got a token whose upstream credential was already gone. The guard table in docs/arch/11-auth-server-storage.md lists the case under the deleted-row refusal. Co-authored-by: Mecatl <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Approve: the change is made at the one place that knows the upstream row was deleted, and it has no breaking side effects beyond the stated one.
Design: refreshAndStore is the only code that knows the delete succeeded after a failed persist, so wrapping storage.ErrNotFound there (and only in the delete-succeeded branch) is the right owner and the smallest fix. All callers go through that function. The refresh grant guard now refuses without revoking, which is correct because the row is really gone. GetValidTokens and the handler treat any error as a failed refresh or a re-prompt, so they behave as before. The only upgrade-visible change is that a refresh that rotated the upstream token and then hit a storage failure is refused with a non-revoking invalid_grant instead of being granted with no upstream credential behind it. The PR body states this.
🤖 Reviewed with Claude Code
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7324 +/- ##
==========================================
- Coverage 82.18% 82.17% -0.01%
==========================================
Files 932 932
Lines 94564 94568 +4
==========================================
- Hits 77715 77714 -1
- Misses 16844 16849 +5
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
When the IdP rotates a refresh token during an upstream refresh and the new token cannot be saved, the refresher deletes the stale row: the old refresh token is dead, and keeping it would trip the IdP's reuse detection on the next refresh. The error it returns did not say that the row was deleted, so callers that classify a refresh failure by its cause could not tell this case from a transient failure on a row that still exists.
storage.ErrNotFoundand the persist error, once its delete succeeded. If the delete fails too, the row still exists and the error is unchanged.storage.ErrNotFound); it now also covers this case.Split out of #7323 at review, so it can be reviewed and reverted on its own. The per-user reader in #7323 classifies this error as "needs authorization"; it works without this change, but reports the case as an infrastructure error until this lands.
Type of change
Test plan
pkg/authserverwith-racegolangci-lintonpkg/authserver)Refresher tests cover both outcomes of the delete: when it succeeds, the error matches
storage.ErrNotFoundand the persist error; when it fails, it does not matchstorage.ErrNotFound. A guard test feeds the real error shape and checks that the guard refuses without revoking.Does this introduce a user-facing change?
Yes, in the refresh grant guard, which runs whenever an upstream is configured:
invalid_grantand keeps the refresh token, the same as when the row is deleted by anything else while the guard refreshes it.The guard table in
docs/arch/11-auth-server-storage.mdlists the case under the deleted-row refusal.