mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd): allow user-admin password resets to succeed (#26537)
User Admin password resets could update the target user's hashed password but fail while revoking that user's API keys. The transaction then rolled back and returned HTTP 500, so the password was never changed. Add a user-scoped API key revoker actor and use it in both password reset flows so key revocation succeeds without broader system auth. Refs: https://linear.app/codercom/issue/PLAT-316
This commit is contained in:
+3
-1
@@ -1713,7 +1713,9 @@ func (api *API) putUserPassword(rw http.ResponseWriter, r *http.Request) {
|
||||
return xerrors.Errorf("update user hashed password: %w", err)
|
||||
}
|
||||
|
||||
err = tx.DeleteAPIKeysByUserID(ctx, user.ID)
|
||||
//nolint:gocritic // Password resets must revoke all keys owned by the
|
||||
// target user, not just keys addressable by the caller's actor.
|
||||
err = tx.DeleteAPIKeysByUserID(dbauthz.AsAPIKeyRevoker(ctx, user.ID), user.ID)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("delete api keys by user ID: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user