mgr/dashboard: add option to resolve ip addr

Add the option `redirect_resolve_ip_addr` to the dashboard module.
If the option is set to `True`, try to resolve the IP address before
redirecting from the passive to the active mgr instance.
If the option is set to `False`, follow the already known behavior.

Fixes: https://tracker.ceph.com/issues/56699
Signed-off-by: Tatjana Dehler <tdehler@suse.com>
This commit is contained in:
Tatjana Dehler 2022-07-25 18:04:58 +02:00
parent 279d37e640
commit 2e15f0f0d2
No known key found for this signature in database
GPG Key ID: EDC57C4C3C77CE61
2 changed files with 28 additions and 1 deletions

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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: