Project

Profile

Help

Issue #4092

closed

redirect_host defaults to socket.getfqdn() instead of None

Added by evgeni over 5 years ago. Updated almost 5 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
2.17.1
Platform Release:
2.18.0
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Easy Fix, Pulp 2
Sprint:
Quarter:

Description

the code in server/pulp/server/content/web/views.py currently tries to use the hostname used in the request to build the redirect, if redirect_host is not set in the config:

    @staticmethod
    def redirect(request, key):
        """
        Redirected GET request.

        :param request: The WSGI request object.
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param key: A private RSA key.
        :type key: RSA.RSA
        :return: A redirect or not-found reply.
        :rtype: django.http.HttpResponse
        """
        path = os.path.realpath(request.path_info)
        scheme = request.environ['wsgi.url_scheme']
        host = request.environ['SERVER_NAME']
        port = request.environ['SERVER_PORT']
        query = request.environ['QUERY_STRING']
        remote_ip = request.environ['REMOTE_ADDR']

        redirect_host = pulp_conf.get('lazy', 'redirect_host')
        redirect_port = pulp_conf.get('lazy', 'redirect_port')
        redirect_path = pulp_conf.get('lazy', 'redirect_path')

        redirect = ContentView.urljoin(
            scheme,
            redirect_host or host,
            redirect_port or port,
            redirect_path,
            path,
            query)

        url = URL(redirect)
        signed = url.sign(key, remote_ip=remote_ip)
        return HttpResponseRedirect(str(signed))

however, redirect_host is never empty in the config, as config.py has a default value for it:

      'lazy': {
          'redirect_host': socket.getfqdn(),
          'redirect_port': '',
          'redirect_path': '/streamer/',
          'https_retrieval': 'true',
          'download_interval': '30',
          'download_concurrency': '5'
      },

server.conf has the according documentation comment.

# redirect_host:
#   The host FQDN or IP to which requests are redirected. Defaults to
#   the local host's fully qualified domain name.

given the redirect_host or host code in redirect(), and looking at the similar code in master (https://github.com/pulp/pulp/commit/c35bba60db1d10f7420cd4108b7a960ca073d122), I think redirect_host should default to None.

I have tested this with setting redirect_host to "" (an empty string), and this makes stuff work as expected too:

with redirect_host set to "centos7-katello-nightly.kangae.example.com"

[root@centos7-katello-nightly ~]# curl -v http://localhost/pulp/repos/Default_Organization/Library/custom/Zoo/zoo/Packages/b/bear-4.1-1.noarch.rpm
* About to connect() to localhost port 80 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET /pulp/repos/Default_Organization/Library/custom/Zoo/zoo/Packages/b/bear-4.1-1.noarch.rpm HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 302 Found
< Date: Thu, 18 Oct 2018 11:21:19 GMT
< Server: Apache/2.4.6 (CentOS)
< Content-Length: 0
< ETag: "d41d8cd98f00b204e9800998ecf8427e"
< Location: http://centos7-katello-nightly.kangae.example.com:80/streamer/var/lib/pulp/content/units/rpm/76/78177c241777af22235092f21c3932dd4f0664e1624e5a2c77a201ec70f930/bear-4.1-1.noarch.rpm?…
< Content-Type: text/html; charset=utf-8
< 
* Connection #0 to host localhost left intact

with redirect_host removed from the config:

[root@centos7-katello-nightly ~]# curl -v http://localhost/pulp/repos/Default_Organization/Library/custom/Zoo/zoo/Packages/b/bear-4.1-1.noarch.rpm
* About to connect() to localhost port 80 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET /pulp/repos/Default_Organization/Library/custom/Zoo/zoo/Packages/b/bear-4.1-1.noarch.rpm HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 302 Found
< Date: Thu, 18 Oct 2018 11:25:58 GMT
< Server: Apache/2.4.6 (CentOS)
< Content-Length: 0
< ETag: "d41d8cd98f00b204e9800998ecf8427e"
< Location: http://centos7-katello-nightly.kangae.example.com:80/streamer/var/lib/pulp/content/units/rpm/76/78177c241777af22235092f21c3932dd4f0664e1624e5a2c77a201ec70f930/bear-4.1-1.noarch.rpm?…
< Content-Type: text/html; charset=utf-8
< 
* Connection #0 to host localhost left intact

with redirect_host set to "":

[root@centos7-katello-nightly ~]# curl -v http://localhost/pulp/repos/Default_Organization/Library/custom/Zoo/zoo/Packages/b/bear-4.1-1.noarch.rpm
* About to connect() to localhost port 80 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET /pulp/repos/Default_Organization/Library/custom/Zoo/zoo/Packages/b/bear-4.1-1.noarch.rpm HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
> 
< HTTP/1.1 302 Found
< Date: Thu, 18 Oct 2018 11:28:56 GMT
< Server: Apache/2.4.6 (CentOS)
< Content-Length: 0
< ETag: "d41d8cd98f00b204e9800998ecf8427e"
< Location: http://localhost:80/streamer/var/lib/pulp/content/units/rpm/76/78177c241777af22235092f21c3932dd4f0664e1624e5a2c77a201ec70f930/bear-4.1-1.noarch.rpm?…
< Content-Type: text/html; charset=utf-8
< 
* Connection #0 to host localhost left intact

Related issues

Related to Pulp - Issue #4120: Syncing a repo with `background` download policy raises InvalidURL in RHEL 7.6CLOSED - CURRENTRELEASEdaviddavisActions

Also available in: Atom PDF