Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bearer token invalidation bug by calling AddResponses() twice on 401 errors #763

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion fs/remote/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,23 @@ func (tr *transport) RoundTrip(req *http.Request) (*http.Response, error) {
if resp.StatusCode == http.StatusUnauthorized {
log.G(ctx).Infof("Received status code: %v. Refreshing creds...", resp.Status)

// prepare authorization for the target host using docker.Authorizer
// Prepare authorization for the target host using docker.Authorizer.
// The docker authorizer only refreshes OAuth tokens after two
// successive 401 errors for the same URL. Rather than issue the same
// request multiple times to tickle the token-refreshing logic, just
// provide the same response twice to trick it into refreshing the
// cached OAuth token. Call AddResponses() twice, first to invalidate
// the existing token (with two responses), second to fetch a new one
// (with one response).
// TODO: fix after one of these two PRs are merged and available:
// https://github.com/containerd/containerd/pull/8735
// https://github.com/containerd/containerd/pull/8388
if err := tr.auth.AddResponses(ctx, []*http.Response{resp, resp}); err != nil {
if errdefs.IsNotImplemented(err) {
return resp, nil
}
return nil, err
}
if err := tr.auth.AddResponses(ctx, []*http.Response{resp}); err != nil {
if errdefs.IsNotImplemented(err) {
return resp, nil
Expand Down