]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/dashboard: fix reverse proxy support 20182/head
authorNick Erdmann <n@nirf.de>
Mon, 22 Jan 2018 12:33:32 +0000 (12:33 +0000)
committerJohn Spray <john.spray@redhat.com>
Tue, 30 Jan 2018 16:18:48 +0000 (16:18 +0000)
This fixes http redirection for reverse http proxies

Fixes: http://tracker.ceph.com/issues/22557
Signed-off-by: Nick Erdmann <n@nirf.de>
(cherry picked from commit 95e1963cb5327f0699081c4c4b0b355d109ff0e3)

src/pybind/mgr/dashboard/module.py

index 1d0f8f3daee4d0dd074a2d36a79160c988bcb7d8..21310f3a46fccbeba1b77028865ecde8c6e79df6 100644 (file)
@@ -26,6 +26,7 @@ import socket
 
 import cherrypy
 import jinja2
+import urlparse
 
 from mgr_module import MgrModule, MgrStandbyModule, CommandResult
 
@@ -63,14 +64,22 @@ def recurse_refs(root, path):
     log.info("%s %d (%s)" % (path, sys.getrefcount(root), root.__class__))
 
 def get_prefixed_url(url):
-    return global_instance().url_prefix + url
+    return global_instance().url_prefix.rstrip('/') + url
 
 
 
+def prepare_url_prefix(url_prefix):
+    url_prefix = urlparse.urljoin('/', url_prefix)
+    if url_prefix[-1] != '/':
+        url_prefix = url_prefix + '/'
+    return url_prefix
+
 class StandbyModule(MgrStandbyModule):
     def serve(self):
         server_addr = self.get_localized_config('server_addr', '::')
         server_port = self.get_localized_config('server_port', '7000')
+        url_prefix = prepare_url_prefix(self.get_config('url_prefix', default=''))
+
         if server_addr is None:
             raise RuntimeError('no server_addr configured; try "ceph config-key set mgr/dashboard/server_addr <ip>"')
         log.info("server_addr: %s server_port: %s" % (server_addr, server_port))
@@ -88,16 +97,16 @@ class StandbyModule(MgrStandbyModule):
 
         class Root(object):
             @cherrypy.expose
-            def index(self):
+            def default(self, *args, **kwargs):
                 active_uri = module.get_active_uri()
                 if active_uri:
-                    log.info("Redirecting to active '{0}'".format(active_uri))
-                    raise cherrypy.HTTPRedirect(active_uri)
+                    log.info("Redirecting to active '{0}'".format(active_uri + "/".join(args)))
+                    raise cherrypy.HTTPRedirect(active_uri + "/".join(args))
                 else:
                     template = env.get_template("standby.html")
                     return template.render(delay=5)
 
-        cherrypy.tree.mount(Root(), "/", {})
+        cherrypy.tree.mount(Root(), url_prefix, {})
         log.info("Starting engine...")
         cherrypy.engine.start()
         log.info("Waiting for engine...")
@@ -888,15 +897,7 @@ class Module(MgrModule):
                         ret[k1][k2] = sorted_dict
                 return ret
 
-        url_prefix = self.get_config('url_prefix')
-        if url_prefix == None:
-            url_prefix = ''
-        else:
-            if len(url_prefix) != 0:
-                if url_prefix[0] != '/':
-                    url_prefix = '/'+url_prefix
-                if url_prefix[-1] == '/':
-                    url_prefix = url_prefix[:-1]
+        url_prefix = prepare_url_prefix(self.get_config('url_prefix', default=''))
         self.url_prefix = url_prefix
 
         server_addr = self.get_localized_config('server_addr', '::')
@@ -915,9 +916,10 @@ class Module(MgrModule):
 
         # Publish the URI that others may use to access the service we're
         # about to start serving
-        self.set_uri("http://{0}:{1}/".format(
+        self.set_uri("http://{0}:{1}{2}".format(
             socket.getfqdn() if server_addr == "::" else server_addr,
-            server_port
+            server_port,
+            url_prefix
         ))
 
         static_dir = os.path.join(current_dir, 'static')