Project

Profile

Help

Issue #4092

redirect_host defaults to socket.getfqdn() instead of None

Added by evgeni about 1 year ago. Updated 7 months ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Severity:
2. Medium
Version:
2.17.1
Platform Release:
2.18.0
Blocks Release:
OS:
Backwards Incompatible:
No
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Easy Fix, Pulp 2
QA Contact:
Complexity:
Smash Test:
Verified:
No
Verification Required:
No
Sprint:

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.6 CLOSED - CURRENTRELEASE Actions

Associated revisions

Revision 17e06d25 View on GitHub
Added by evgeni about 1 year ago

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

History

#2 Updated by pcreech about 1 year ago

  • Assignee set to evgeni

#3 Updated by pcreech about 1 year ago

  • Status changed from NEW to ASSIGNED

#4 Updated by pcreech about 1 year ago

  • Status changed from ASSIGNED to POST

#5 Updated by CodeHeeler about 1 year ago

  • Triaged changed from No to Yes

#6 Updated by Jackkevin about 1 year ago

As a side note, gethostbyname returns promptly on my Fedora 18 framework (python-2.7.3-13) regardless of whether I obstruct the reactions from my DNS servers, so there doesn't appear to be any hazard utilizing it if the DNS servers are back or off. [[http://www.assignmentbay.co.uk/assignment-writing-service]]

#7 Updated by evgeni about 1 year 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.

#9 Updated by evgeni about 1 year ago

  • Status changed from POST to MODIFIED

#10 Updated by daviddavis about 1 year ago

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

#11 Updated by ttereshc about 1 year ago

  • Platform Release set to 2.18.0

#12 Updated by ttereshc about 1 year ago

  • Sprint/Milestone set to 2.18.0

#13 Updated by ttereshc about 1 year ago

  • Status changed from MODIFIED to ON_QA

#14 Updated by ttereshc 12 months ago

  • Status changed from ON_QA to CLOSED - CURRENTRELEASE

#15 Updated by bmbouter 7 months ago

  • Tags Pulp 2 added

Please register to edit this issue

Also available in: Atom PDF