Project

Profile

Help

Issue #4092

closed

redirect_host defaults to socket.getfqdn() instead of None

Added by evgeni about 6 years ago. Updated over 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
Actions #2

Updated by pcreech about 6 years ago

  • Assignee set to evgeni
Actions #3

Updated by pcreech about 6 years ago

  • Status changed from NEW to ASSIGNED
Actions #4

Updated by pcreech about 6 years ago

  • Status changed from ASSIGNED to POST
Actions #5

Updated by CodeHeeler about 6 years ago

  • Triaged changed from No to Yes
Actions #6

Updated by evgeni about 6 years ago

I've added tests, but please be aware that they pass also without my change, as the tests currently don't use the default config values from `server/pulp/server/config.py` but have own defaults.

Added by evgeni about 6 years ago

Revision 17e06d25 | View on GitHub

default redirect_host to None (#3726)

  • default redirect_host to ''

this allows to use the host from the incoming request for the redirect

closes #4092

  • test ContentView.redirect with defaults AND explicit values
Actions #8

Updated by evgeni about 6 years ago

  • Status changed from POST to MODIFIED
Actions #9

Updated by daviddavis about 6 years ago

  • Related to Issue #4120: Syncing a repo with `background` download policy raises InvalidURL in RHEL 7.6 added
Actions #10

Updated by ttereshc about 6 years ago

  • Platform Release set to 2.18.0
Actions #11

Updated by ttereshc about 6 years ago

  • Sprint/Milestone set to 2.18.0
Actions #12

Updated by ttereshc about 6 years ago

  • Status changed from MODIFIED to 5
Actions #13

Updated by ttereshc almost 6 years ago

  • Status changed from 5 to CLOSED - CURRENTRELEASE
Actions #14

Updated by bmbouter over 5 years ago

  • Tags Pulp 2 added

Also available in: Atom PDF