Skip to content

Commit 96022e8

Browse files
committed
Properly fill out auth headers in APIClient.build when using
a credentials store Signed-off-by: Joffrey F <[email protected]>
1 parent 0cdc855 commit 96022e8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

docker/api/build.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,19 +230,35 @@ def _set_auth_headers(self, headers):
230230
# Send the full auth configuration (if any exists), since the build
231231
# could use any (or all) of the registries.
232232
if self._auth_configs:
233+
auth_data = {}
234+
if self._auth_configs.get('credsStore'):
235+
# Using a credentials store, we need to retrieve the
236+
# credentials for each registry listed in the config.json file
237+
# Matches CLI behavior: https://github.com/docker/docker/blob/
238+
# 67b85f9d26f1b0b2b240f2d794748fac0f45243c/cliconfig/
239+
# credentials/native_store.go#L68-L83
240+
for registry in self._auth_configs.keys():
241+
if registry == 'credsStore' or registry == 'HttpHeaders':
242+
continue
243+
auth_data[registry] = auth.resolve_authconfig(
244+
self._auth_configs, registry
245+
)
246+
else:
247+
auth_data = self._auth_configs
248+
233249
log.debug(
234250
'Sending auth config ({0})'.format(
235-
', '.join(repr(k) for k in self._auth_configs.keys())
251+
', '.join(repr(k) for k in auth_data.keys())
236252
)
237253
)
238254

239255
if utils.compare_version('1.19', self._version) >= 0:
240256
headers['X-Registry-Config'] = auth.encode_header(
241-
self._auth_configs
257+
auth_data
242258
)
243259
else:
244260
headers['X-Registry-Config'] = auth.encode_header({
245-
'configs': self._auth_configs
261+
'configs': auth_data
246262
})
247263
else:
248264
log.debug('No auth config found')

0 commit comments

Comments
 (0)