File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
components/image-builder-bob/pkg/proxy Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -178,11 +178,28 @@ func (proxy *Proxy) reverse(alias string) *httputil.ReverseProxy {
178
178
return false , nil
179
179
}
180
180
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 })
182
192
if err != nil {
183
193
log .WithError (err ).WithField ("URL" , resp .Request .URL .String ()).Warn ("cannot add responses although response was Unauthorized" )
184
194
return false , nil
185
195
}
196
+
197
+ err = auth .AddResponses (ctx , []* http.Response {resp , 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
+
186
203
return true , nil
187
204
}
188
205
You can’t perform that action at this time.
0 commit comments