Skip to content

Commit 06b6a62

Browse files
committed
Add support for identity tokens in config file.
Signed-off-by: Joffrey F <[email protected]>
1 parent e4cf97b commit 06b6a62

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

docker/auth/auth.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ def parse_auth(entries, raise_on_error=False):
174174
'Invalid configuration for registry {0}'.format(registry)
175175
)
176176
return {}
177+
if 'identitytoken' in entry:
178+
log.debug('Found an IdentityToken entry for registry {0}'.format(
179+
registry
180+
))
181+
conf[registry] = {
182+
'IdentityToken': entry['identitytoken']
183+
}
184+
continue # Other values are irrelevant if we have a token, skip.
185+
177186
if 'auth' not in entry:
178187
# Starting with engine v1.11 (API 1.23), an empty dictionary is
179188
# a valid value in the auths config.
@@ -182,13 +191,15 @@ def parse_auth(entries, raise_on_error=False):
182191
'Auth data for {0} is absent. Client might be using a '
183192
'credentials store instead.'
184193
)
185-
return {}
194+
conf[registry] = {}
195+
continue
186196

187197
username, password = decode_auth(entry['auth'])
188198
log.debug(
189199
'Found entry (registry={0}, username={1})'
190200
.format(repr(registry), repr(username))
191201
)
202+
192203
conf[registry] = {
193204
'username': username,
194205
'password': password,

tests/unit/auth_test.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,28 @@ def test_load_config_invalid_auth_dict(self):
460460
json.dump(config, f)
461461

462462
cfg = auth.load_config(dockercfg_path)
463-
assert cfg == {}
463+
assert cfg == {'scarlet.net': {}}
464+
465+
def test_load_config_identity_token(self):
466+
folder = tempfile.mkdtemp()
467+
registry = 'scarlet.net'
468+
token = '1ce1cebb-503e-7043-11aa-7feb8bd4a1ce'
469+
self.addCleanup(shutil.rmtree, folder)
470+
dockercfg_path = os.path.join(folder, 'config.json')
471+
auth_entry = encode_auth({'username': 'sakuya'}).decode('ascii')
472+
config = {
473+
'auths': {
474+
registry: {
475+
'auth': auth_entry,
476+
'identitytoken': token
477+
}
478+
}
479+
}
480+
with open(dockercfg_path, 'w') as f:
481+
json.dump(config, f)
482+
483+
cfg = auth.load_config(dockercfg_path)
484+
assert registry in cfg
485+
cfg = cfg[registry]
486+
assert 'IdentityToken' in cfg
487+
assert cfg['IdentityToken'] == token

0 commit comments

Comments
 (0)