Skip to content

Commit

Permalink
Stop sending basic auth credentials to redirect location
Browse files Browse the repository at this point in the history
Pulp is getting redirected and sending the Remote's credentials to the
redirected location. Looks like if we set the credentials on the request
instead of the session, aiohttp will only send the credentials to
redirected locations when the domains match which is the behavior we
want.

fixes #6227
  • Loading branch information
David Davis committed Feb 25, 2020
1 parent 7be835f commit 4505f14
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES/6227.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stopped HttpDownloader sending basic auth credentials to redirect location if domains don't match.
15 changes: 7 additions & 8 deletions pulpcore/download/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,8 @@ def _make_aiohttp_session_from_remote(self):

conn = aiohttp.TCPConnector(**tcp_conn_opts)

auth_options = {}
if self._remote.username and self._remote.password:
auth_options['auth'] = aiohttp.BasicAuth(
login=self._remote.username,
password=self._remote.password
)

timeout = aiohttp.ClientTimeout(total=None, sock_connect=600, sock_read=600)
return aiohttp.ClientSession(connector=conn, timeout=timeout, **auth_options)
return aiohttp.ClientSession(connector=conn, timeout=timeout)

def build(self, url, **kwargs):
"""
Expand Down Expand Up @@ -160,6 +153,12 @@ class to be instantiated.
if self._remote.proxy_url:
options['proxy'] = self._remote.proxy_url

if self._remote.username and self._remote.password:
options['auth'] = aiohttp.BasicAuth(
login=self._remote.username,
password=self._remote.password
)

return download_class(url, **options, **kwargs)

def _generic(self, download_class, url, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/download/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def _run(self, extra_data=None):
Args:
extra_data (dict): Extra data passed by the downloader.
"""
async with self.session.get(self.url, proxy=self.proxy) as response:
async with self.session.get(self.url, proxy=self.proxy, auth=self.auth) as response:
response.raise_for_status()
to_return = await self._handle_response(response)
await response.release()
Expand Down

0 comments on commit 4505f14

Please sign in to comment.