A 401 with code unauthorized is treated as an expired token and replayed

Aperta Adatta ai principianti
#101 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Inizia da base.Action in base/base.go e dal percorso di retry in b2/backend.go (withReauth); l’issue identifica la classificazione attuale e indica il comportamento richiesto in base al codice di errore. Aggiungi o aggiorna i test httptest per unauthorized, entrambi i codici di errore del token e access_denied con risposte 401 e 403. Il lavoro è completato quando solo gli errori del token attivano una nuova autorizzazione e la ripetizione della richiesta, mentre i codici non ritentabili vengono restituiti senza una richiesta aggiuntiva.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Every HTTP 401 from a native API call (other than b2_authorize_account and uploads) is classified as "re-authenticate", including 401s that have nothing to do with an expired token. Found while reviewing #53.

base.Action (base/base.go) returns ReAuthenticate for any 401 outside b2_authorize_account, b2_upload_file and b2_upload_part, without looking at the error code. withReauth (b2/backend.go) then calls reauthorizeAccount and replays the request once. The B2 spec lists three different 401 codes for b2_delete_file_version (bad_auth_token, expired_auth_token, unauthorized), and only the first two mean the token needs refreshing. unauthorized means the token is valid but the key does not authorize this call with these parameters.

Reproduced with a throwaway httptest test: a b2_delete_file_version response of 401 with code unauthorized is classified as ReAuthenticate. So a caller using b2.BypassGovernance() with a key that lacks the bypassGovernance capability triggers an extra b2_authorize_account call and a second identical delete request before getting the same error back. The cost is bounded (withReauth retries once), but it is wasted work, it hides the real cause behind two failed attempts, and it applies to every operation that returns unauthorized, such as a prefix-restricted key listing outside its prefix (the v4 multi-bucket key case in #30).

The same spec page also leaves the status of the Object Lock access_denied response unclear (401 in one rendering, 403 in another). If it is 401, a locked delete would also be re-authorized and replayed. The code string should decide the action, not the status alone.

What is needed:

  • Classify 401 by code: re-authenticate only for bad_auth_token and expired_auth_token; treat unauthorized and access_denied as non-retryable (Punt) and surface the message.
  • Keep the existing behavior for uploads (AttemptNewUpload) and for b2_authorize_account (Punt).
  • Decide the behavior for a 401 with an unknown or missing code (keep re-authenticating once, as today, to stay safe).

Acceptance checks:

  • An httptest test returns 401 with code unauthorized for a native call and asserts base.Action is not ReAuthenticate and that exactly one request reaches the server and no extra b2_authorize_account is made.
  • The same test with bad_auth_token and expired_auth_token still re-authenticates and replays once.
  • A test covers access_denied returned as 401 and as 403.

Related: #53, #30. This overlaps the retry and error classification gaps already noted for base/base.go:92-97.

Lingua principale
Go
Stelle
66
Fork
18
Merge medio
1g 10h
PR unite (30g)
132

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Backblaze/blazer

Tutte le issue di Backblaze/blazer

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.