diff --git a/doc/mgr/dashboard.rst b/doc/mgr/dashboard.rst index c513f768d4e..228e03a7d0a 100644 --- a/doc/mgr/dashboard.rst +++ b/doc/mgr/dashboard.rst @@ -1104,6 +1104,23 @@ code of standby dashboards. To do so you need to run the command:: $ ceph config set mgr mgr/dashboard/standby_error_status_code 503 +Resolve IP address to hostname before redirect +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The redirect from a standby to the active dashboard is done via the IP +address. This is done because resolving IP addresses to hostnames can be error +prone in containerized environments. It is also the reason why the option is +disabled by default. +However, in some situations it might be helpful to redirect via the hostname. +For example if the configured TLS certificate matches only the hostnames. To +activate the redirection via the hostname run the following command:: + + $ ceph config set mgr mgr/dashboard/redirect_resolve_ip_addr True + +You can disable it again by:: + + $ ceph config set mgr mgr/dashboard/redirect_resolve_ip_addr False + HAProxy example configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 946c853f880..c82df154136 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -6,12 +6,14 @@ import collections import errno import logging import os +import socket import ssl import sys import tempfile import threading import time from typing import TYPE_CHECKING, Optional +from urllib.parse import urlparse if TYPE_CHECKING: if sys.version_info >= (3, 8): @@ -268,7 +270,8 @@ class Module(MgrModule, CherryPyConfig): Option(name='standby_behaviour', type='str', default='redirect', enum_allowed=['redirect', 'error']), Option(name='standby_error_status_code', type='int', default=500, - min=400, max=599) + min=400, max=599), + Option(name='redirect_resolve_ip_addr', type='bool', default=False) ] MODULE_OPTIONS.extend(options_schema_list()) for options in PLUGIN_MANAGER.hook.get_options() or []: @@ -525,6 +528,13 @@ class StandbyModule(MgrStandbyModule, CherryPyConfig): return None if active_uri: + if module.get_module_option('redirect_resolve_ip_addr'): + p_result = urlparse(active_uri) + hostname = str(p_result.hostname) + fqdn_netloc = p_result.netloc.replace( + hostname, socket.getfqdn(hostname)) + active_uri = p_result._replace(netloc=fqdn_netloc).geturl() + module.log.info("Redirecting to active '%s'", active_uri) raise cherrypy.HTTPRedirect(active_uri) else: