Merge pull request #69080 from kginonredhat/issue-75365-Grafana-container-fails-to-start-reject-localhost

cephadm: set Grafana http_addr to 0.0.0.0 when unset

Reviewed-by: Redouane Kachach <rkachach@ibm.com>
Reviewed-by: Shweta Bhosale <Shweta.Bhosale1@ibm.com>
This commit is contained in:
Redouane Kachach 2026-06-12 12:34:42 +02:00 committed by GitHub
commit ace8eb0aaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 8 deletions

View File

@ -2,7 +2,6 @@ import errno
import logging
import os
from typing import List, Any, Tuple, Dict, Optional, cast, TYPE_CHECKING
import ipaddress
import time
import requests
@ -74,8 +73,15 @@ class GrafanaService(CephadmService):
if ip_to_bind_to:
daemon_spec.port_ips = {str(grafana_port): ip_to_bind_to}
grafana_ip = ip_to_bind_to
if ipaddress.ip_network(grafana_ip).version == 6:
grafana_ip = f"[{grafana_ip}]"
if not grafana_ip:
# Grafana 11.1+ validates http_addr with net.ParseIP; hostnames such as
# localhost fail in grafana-apiserver. Use a literal address (bind all IPv4).
# Check if the primary manager or orchestrator is configured for IPv6
if self.mgr.get_mgr_ip().startswith('::') or ':' in self.mgr.get_mgr_ip():
grafana_ip = '::'
else:
grafana_ip = '0.0.0.0'
domain = self.mgr.get_fqdn(daemon_spec.host)
mgmt_gw_ips = []

View File

@ -1329,7 +1329,7 @@ class TestMonitoring:
cert_file = /etc/grafana/certs/cert_file
cert_key = /etc/grafana/certs/cert_key
http_port = 3000
http_addr =
http_addr = ::
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
[snapshots]
@ -1490,7 +1490,7 @@ class TestMonitoring:
cert_file = /etc/grafana/certs/cert_file
cert_key = /etc/grafana/certs/cert_key
http_port = 3000
http_addr =
http_addr = ::
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true
[snapshots]
@ -1590,7 +1590,7 @@ class TestMonitoring:
cert_file = /etc/grafana/certs/cert_file
cert_key = /etc/grafana/certs/cert_key
http_port = 3000
http_addr =
http_addr = ::
[snapshots]
external_enabled = false
[security]
@ -1681,6 +1681,7 @@ class TestMonitoring:
)
@patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
@patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '192.0.2.1')
def test_grafana_initial_admin_pw(self, cephadm_module: CephadmOrchestrator):
with with_host(cephadm_module, 'test'):
with with_service(cephadm_module, ServiceSpec('mgr')) as _, \
@ -1705,7 +1706,7 @@ class TestMonitoring:
' cert_file = /etc/grafana/certs/cert_file\n'
' cert_key = /etc/grafana/certs/cert_key\n'
' http_port = 3000\n'
' http_addr = \n'
' http_addr = 0.0.0.0\n'
'[snapshots]\n'
' external_enabled = false\n'
'[security]\n'
@ -1750,6 +1751,33 @@ class TestMonitoring:
}}, ['certificate_source: cephadm-signed', 'secure_monitoring_stack:False'])
@patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
@patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '192.0.2.1')
def test_grafana_http_addr_binds_all_by_default_ipv4(self, cephadm_module: CephadmOrchestrator):
grafana_svc = service_registry.get_service('grafana')
with with_host(cephadm_module, 'test'):
with with_service(cephadm_module, GrafanaSpec()):
ini = grafana_svc.generate_grafana_ini(
CephadmDaemonDeploySpec('test', 'daemon', 'grafana'),
mgmt_gw_enabled=False,
oauth2_enabled=False,
)
assert 'http_addr = 0.0.0.0' in ini
@patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
@patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '1::4')
def test_grafana_http_addr_binds_all_by_default_ipv6(self, cephadm_module: CephadmOrchestrator):
grafana_svc = service_registry.get_service('grafana')
with with_host(cephadm_module, 'test'):
with with_service(cephadm_module, GrafanaSpec()):
ini = grafana_svc.generate_grafana_ini(
CephadmDaemonDeploySpec('test', 'daemon', 'grafana'),
mgmt_gw_enabled=False,
oauth2_enabled=False,
)
assert 'http_addr = ::' in ini
@patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
@patch("cephadm.module.CephadmOrchestrator.get_mgr_ip", lambda _: '192.0.2.1')
def test_grafana_no_anon_access(self, cephadm_module: CephadmOrchestrator):
# with anonymous_access set to False, expecting the [auth.anonymous] section
# to not be present in the grafana config. Note that we require an initial_admin_password
@ -1774,7 +1802,7 @@ class TestMonitoring:
' cert_file = /etc/grafana/certs/cert_file\n'
' cert_key = /etc/grafana/certs/cert_key\n'
' http_port = 3000\n'
' http_addr = \n'
' http_addr = 0.0.0.0\n'
'[snapshots]\n'
' external_enabled = false\n'
'[security]\n'