Skip to content

Commit 4035c70

Browse files
committed
Force oauth token refresh
1 parent edca0d5 commit 4035c70

File tree

1 file changed

+18
-1
lines changed
  • components/image-builder-bob/pkg/proxy

1 file changed

+18
-1
lines changed

components/image-builder-bob/pkg/proxy/proxy.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,28 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
178178
return false, nil
179179
}
180180
if resp.StatusCode == http.StatusUnauthorized {
181-
err := auth.AddResponses(context.Background(), []*http.Response{resp})
181+
// the docker authorizer only refreshes OAuth tokens after two
182+
// successive 401 errors for the same URL. Rather than issue the same
183+
// request multiple times to tickle the token-refreshing logic, just
184+
// provide the same response twice to trick it into refreshing the
185+
// cached OAuth token. Call AddResponses() twice, first to invalidate
186+
// the existing token (with two responses), second to fetch a new one
187+
// (with one response).
188+
// TODO: fix after one of these two PRs are merged and available:
189+
// https://github.com/containerd/containerd/pull/8735
190+
// https://github.com/containerd/containerd/pull/8388
191+
err := auth.AddResponses(ctx, []*http.Response{resp, resp})
182192
if err != nil {
183193
log.WithError(err).WithField("URL", resp.Request.URL.String()).Warn("cannot add responses although response was Unauthorized")
184194
return false, nil
185195
}
196+
197+
err = auth.AddResponses(ctx, []*http.Response{resp})
198+
if err != nil {
199+
log.WithError(err).WithField("URL", resp.Request.URL.String()).Warn("cannot add responses although response was Unauthorized")
200+
return false, nil
201+
}
202+
186203
return true, nil
187204
}
188205

0 commit comments

Comments
 (0)