]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: The RGW backend doesn't handle IPv6 properly 24222/head
authorVolker Theile <vtheile@suse.com>
Fri, 21 Sep 2018 15:05:54 +0000 (17:05 +0200)
committerVolker Theile <vtheile@suse.com>
Tue, 9 Oct 2018 07:42:32 +0000 (09:42 +0200)
Fixes: https://tracker.ceph.com/issues/36109
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/services/rgw_client.py

index 09d32fe951fdc9fbe18523c0100fa7268722d7c4..821949524d9527807aa301204b8825c2189007fc 100644 (file)
@@ -72,13 +72,67 @@ def _determine_rgw_addr():
         raise LookupError('No RGW daemon found.')
 
     addr = daemon['addr'].split(':')[0]
-    match = re.search(r'port=(\d+)', daemon['metadata']['frontend_config#0'])
-    if match:
-        port = int(match.group(1))
-    else:
-        raise LookupError('Failed to determine RGW port')
+    port, ssl = _parse_frontend_config(daemon['metadata']['frontend_config#0'])
+
+    return addr, port, ssl
+
+
+def _parse_frontend_config(config):
+    """
+    Get the port the RGW is running on. Due the complexity of the
+    syntax not all variations are supported.
+
+    Get more details about the configuration syntax here:
+    http://docs.ceph.com/docs/master/radosgw/frontends/
+    https://civetweb.github.io/civetweb/UserManual.html
+
+    >>> _parse_frontend_config('beast port=8000')
+    (8000, False)
+
+    >>> _parse_frontend_config('civetweb port=8000s')
+    (8000, True)
+
+    >>> _parse_frontend_config('beast port=192.0.2.3:80')
+    (80, False)
 
-    return addr, port
+    >>> _parse_frontend_config('civetweb port=172.5.2.51:8080s')
+    (8080, True)
+
+    >>> _parse_frontend_config('civetweb port=[::]:8080')
+    (8080, False)
+
+    >>> _parse_frontend_config('civetweb port=ip6-localhost:80s')
+    (80, True)
+
+    >>> _parse_frontend_config('civetweb port=[2001:0db8::1234]:80')
+    (80, False)
+
+    >>> _parse_frontend_config('civetweb port=[::1]:8443s')
+    (8443, True)
+
+    >>> _parse_frontend_config('civetweb port=xyz')
+    Traceback (most recent call last):
+    ...
+    LookupError: Failed to determine RGW port
+
+    >>> _parse_frontend_config('civetweb')
+    Traceback (most recent call last):
+    ...
+    LookupError: Failed to determine RGW port
+
+    :param config: The configuration string to parse.
+    :type config: str
+    :raises LookupError if parsing fails to determine the port.
+    :return: A tuple containing the port number and the information
+             whether SSL is used.
+    :rtype: (int, boolean)
+    """
+    match = re.search(r'port=(.*:)?(\d+)(s)?', config)
+    if match:
+        port = int(match.group(2))
+        ssl = match.group(3) == 's'
+        return port, ssl
+    raise LookupError('Failed to determine RGW port')
 
 
 class RgwClient(RestClient):
@@ -99,14 +153,17 @@ class RgwClient(RestClient):
             raise NoCredentialsException()
 
         if Options.has_default_value('RGW_API_HOST') and \
-                Options.has_default_value('RGW_API_PORT'):
-            host, port = _determine_rgw_addr()
+                Options.has_default_value('RGW_API_PORT') and \
+                Options.has_default_value('RGW_API_SCHEME'):
+            host, port, ssl = _determine_rgw_addr()
         else:
-            host, port = Settings.RGW_API_HOST, Settings.RGW_API_PORT
+            host = Settings.RGW_API_HOST
+            port = Settings.RGW_API_PORT
+            ssl = Settings.RGW_API_SCHEME == 'https'
 
         RgwClient._host = host
         RgwClient._port = port
-        RgwClient._ssl = Settings.RGW_API_SCHEME == 'https'
+        RgwClient._ssl = ssl
         RgwClient._ADMIN_PATH = Settings.RGW_API_ADMIN_RESOURCE
 
         # Create an instance using the configured settings.