Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docker/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def parse_auth(entries, raise_on_error=False):
'Invalid configuration for registry {0}'.format(registry)
)
return {}
if 'identitytoken' in entry:
log.debug('Found an IdentityToken entry for registry {0}'.format(
registry
))
conf[registry] = {
'IdentityToken': entry['identitytoken']
}
continue # Other values are irrelevant if we have a token, skip.

if 'auth' not in entry:
# Starting with engine v1.11 (API 1.23), an empty dictionary is
# a valid value in the auths config.
Expand All @@ -182,13 +191,15 @@ def parse_auth(entries, raise_on_error=False):
'Auth data for {0} is absent. Client might be using a '
'credentials store instead.'
)
return {}
conf[registry] = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, either the client is using a cred store and all entries are empty, or they're not and none should be, so returning an empty dict here is not a big problem - but just in case weird hybrid config.json files start popping up, this should allow it to continue working.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a missing return or continue here, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah crud, yeah it needs a continue.

continue

username, password = decode_auth(entry['auth'])
log.debug(
'Found entry (registry={0}, username={1})'
.format(repr(registry), repr(username))
)

conf[registry] = {
'username': username,
'password': password,
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,28 @@ def test_load_config_invalid_auth_dict(self):
json.dump(config, f)

cfg = auth.load_config(dockercfg_path)
assert cfg == {}
assert cfg == {'scarlet.net': {}}

def test_load_config_identity_token(self):
folder = tempfile.mkdtemp()
registry = 'scarlet.net'
token = '1ce1cebb-503e-7043-11aa-7feb8bd4a1ce'
self.addCleanup(shutil.rmtree, folder)
dockercfg_path = os.path.join(folder, 'config.json')
auth_entry = encode_auth({'username': 'sakuya'}).decode('ascii')
config = {
'auths': {
registry: {
'auth': auth_entry,
'identitytoken': token
}
}
}
with open(dockercfg_path, 'w') as f:
json.dump(config, f)

cfg = auth.load_config(dockercfg_path)
assert registry in cfg
cfg = cfg[registry]
assert 'IdentityToken' in cfg
assert cfg['IdentityToken'] == token