From: Volker Theile Date: Fri, 21 Sep 2018 15:05:54 +0000 (+0200) Subject: mgr/dashboard: The RGW backend doesn't handle IPv6 properly X-Git-Tag: v14.0.1~66^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9164e810b49c9ba5f199a286b701da8d088221bc;p=ceph.git mgr/dashboard: The RGW backend doesn't handle IPv6 properly Fixes: https://tracker.ceph.com/issues/36109 Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/services/rgw_client.py b/src/pybind/mgr/dashboard/services/rgw_client.py index 09d32fe951fd..821949524d95 100644 --- a/src/pybind/mgr/dashboard/services/rgw_client.py +++ b/src/pybind/mgr/dashboard/services/rgw_client.py @@ -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.