Skip to content
Open
Changes from 3 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
19 changes: 10 additions & 9 deletions imagegw/shifter_imagegw/dockerv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def do_token_auth(self, auth_loc_str, creds=False):
# TODO, figure out what mode was for
(_, auth_data_str) = auth_loc_str.split(' ', 2)

auth_data = {}
auth_data = {'service':'', 'scope':'pull'}
for item in filter(None, re.split(r'(\w+=".*?"),', auth_data_str)):
(key, val) = item.split('=', 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(key, val) = item.split('=', 2)
(key, val) = item.split('=', 1)

auth_data[key] = val.replace('"', '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
auth_data[key] = val.replace('"', '')
auth_data[key] = val.replace('"', '')
if '?scope=' in auth_data['realm']:
auth_data['realm'], auth_data['scope'] = auth_data['realm'].split('?scope=', 1)

Expand All @@ -383,7 +383,10 @@ def do_token_auth(self, auth_loc_str, creds=False):
'failed to get auth connection')

headers = {}
if creds and self.username is not None and self.password is not None:
if self.username=='$oauthtoken':
self.private = True
headers['Authoriation'] = 'Bearer %s' % (self.password)
Copy link
Contributor

Choose a reason for hiding this comment

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

authoriation is probably a typo

Copy link
Contributor

Choose a reason for hiding this comment

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

the password is just sent plaintext? not even the base64 encoded to assure special characters don't derail the whole thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it is just a bearer token of some sort. Good catch on the misspelling. I'm confused as to how this worked now. Let me test this again.

Copy link
Member Author

Choose a reason for hiding this comment

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

It winds up the typo was part of why it worked. I need to figure out what is going on here.

elif creds and self.username is not None and self.password is not None:
self.private = True
auth = '%s:%s' % (self.username, self.password)
headers['Authorization'] = 'Basic %s' % base64.b64encode(auth)
Expand All @@ -400,8 +403,6 @@ def do_token_auth(self, auth_loc_str, creds=False):

if resp.status != 200:
raise ValueError('Bad response getting token: %d', resp.status)
if resp.getheader('content-type') != 'application/json':
raise ValueError('Invalid response getting token, not json')

auth_resp = json.loads(resp.read())
self.token = auth_resp['token']
Expand Down Expand Up @@ -528,12 +529,12 @@ def save_layer(self, layer, cachedir='./'):
os.unlink(filename)

# If the redirect path includes a verify in the path
# then we don't need the header. If try to use the
# then we don't need the header. If we try to use the
# header, we may get back a 400.
if path.find('verify') > 0:
conn.request("GET", path, None, {})
else:
conn.request("GET", path, None, self.headers)
headers = self.headers
if path.find('verify') > 0 or path.find('X-Amz-Algorithm')>0:
headers = {}
conn.request("GET", path, None, headers)
resp1 = conn.getresponse()
location = resp1.getheader('location')
if resp1.status == 200:
Expand Down