|
14 | 14 | from ceph.deployment.service_spec import AlertManagerSpec, GrafanaSpec, ServiceSpec, \ |
15 | 15 | SNMPGatewaySpec, PrometheusSpec, MgmtGatewaySpec |
16 | 16 | from cephadm.services.cephadmservice import CephadmService, CephadmDaemonDeploySpec, get_dashboard_urls |
17 | | -from mgr_util import verify_tls, ServerConfigException, build_url, get_cert_issuer_info, password_hash |
| 17 | +from mgr_util import build_url, password_hash |
18 | 18 | from ceph.deployment.utils import wrap_ipv6 |
19 | 19 | from .. import utils |
20 | 20 |
|
@@ -143,13 +143,24 @@ def get_loki_host(self) -> str: |
143 | 143 | def generate_config(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[Dict[str, Any], List[str]]: |
144 | 144 | assert self.TYPE == daemon_spec.daemon_type |
145 | 145 |
|
146 | | - cert, pkey = self.prepare_certificates(daemon_spec) |
| 146 | + host_fqdns = [socket.getfqdn(daemon_spec.host), 'grafana_servers'] |
| 147 | + host_ips = self.mgr.inventory.get_addr(daemon_spec.host) |
| 148 | + cert, pkey = self.mgr.cert_mgr.prepare_certificate('grafana_cert', 'grafana_key', host_fqdns, host_ips, target_host=daemon_spec.host) |
| 149 | + if not cert or not pkey: |
| 150 | + logger.error(f'Cannot generate the needed certificates to deploy Grafana on {daemon_spec.host}') |
| 151 | + cert, pkey = ('', '') # this will lead to an error in the daemon as certificates are needed |
| 152 | + |
147 | 153 | security_enabled, mgmt_gw_enabled, oauth2_enabled = self.mgr._get_security_config() |
148 | 154 | grafana_ini = self.generate_grafana_ini(daemon_spec, mgmt_gw_enabled, oauth2_enabled) |
149 | 155 | grafana_data_sources = self.generate_data_sources(security_enabled, mgmt_gw_enabled, cert, pkey) |
150 | 156 | # the path of the grafana dashboards are assumed from the providers.yml.j2 file by grafana |
151 | 157 | grafana_dashboards_path = self.mgr.grafana_dashboards_path or '/etc/grafana/dashboards/ceph-dashboard/' |
152 | 158 |
|
| 159 | + if 'dashboard' in self.mgr.get('mgr_map')['modules']: |
| 160 | + self.mgr.check_mon_command({ |
| 161 | + 'prefix': 'dashboard set-grafana-api-ssl-verify', |
| 162 | + 'value': 'false'}) |
| 163 | + |
153 | 164 | config_file = { |
154 | 165 | 'files': { |
155 | 166 | "grafana.ini": grafana_ini, |
@@ -178,61 +189,6 @@ def generate_config(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[Dict[st |
178 | 189 |
|
179 | 190 | return config_file, self.get_dependencies(self.mgr) |
180 | 191 |
|
181 | | - def prepare_certificates(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[str, str]: |
182 | | - cert = self.mgr.cert_mgr.get_cert('grafana_cert', host=daemon_spec.host) |
183 | | - pkey = self.mgr.cert_mgr.get_key('grafana_key', host=daemon_spec.host) |
184 | | - certs_present = (cert and pkey) |
185 | | - is_valid_certificate = False |
186 | | - (org, cn) = (None, None) |
187 | | - if certs_present: |
188 | | - try: |
189 | | - (org, cn) = get_cert_issuer_info(cert) |
190 | | - verify_tls(cert, pkey) |
191 | | - is_valid_certificate = True |
192 | | - except ServerConfigException as e: |
193 | | - logger.warning(f'Provided grafana TLS certificates are invalid: {e}') |
194 | | - |
195 | | - if is_valid_certificate: |
196 | | - # let's clear health error just in case it was set |
197 | | - self.mgr.remove_health_warning('CEPHADM_CERT_ERROR') |
198 | | - return cert, pkey |
199 | | - |
200 | | - # certificate is not valid, to avoid overwriting user generated |
201 | | - # certificates we only re-generate in case of self signed certificates |
202 | | - # that were originally generated by cephadm or in case cert/key are empty. |
203 | | - if not certs_present or (org == 'Ceph' and cn == 'cephadm'): |
204 | | - logger.info('Regenerating cephadm self-signed grafana TLS certificates') |
205 | | - host_fqdn = socket.getfqdn(daemon_spec.host) |
206 | | - node_ip = self.mgr.inventory.get_addr(daemon_spec.host) |
207 | | - cert, pkey = self.mgr.cert_mgr.generate_cert([host_fqdn, "grafana_servers"], node_ip) |
208 | | - # cert, pkey = create_self_signed_cert('Ceph', host_fqdn) |
209 | | - self.mgr.cert_mgr.save_cert('grafana_cert', cert, host=daemon_spec.host) |
210 | | - self.mgr.cert_mgr.save_key('grafana_key', pkey, host=daemon_spec.host) |
211 | | - if 'dashboard' in self.mgr.get('mgr_map')['modules']: |
212 | | - self.mgr.check_mon_command({ |
213 | | - 'prefix': 'dashboard set-grafana-api-ssl-verify', |
214 | | - 'value': 'false', |
215 | | - }) |
216 | | - self.mgr.remove_health_warning('CEPHADM_CERT_ERROR') # clear if any |
217 | | - else: |
218 | | - # the certificate was not generated by cephadm, we cannot overwrite |
219 | | - # it by new self-signed ones. Let's warn the user to fix the issue |
220 | | - err_msg = """ |
221 | | - Detected invalid grafana certificates. Set mgr/cephadm/grafana_crt |
222 | | - and mgr/cephadm/grafana_key to valid certificates or reset their value |
223 | | - to an empty string in case you want cephadm to generate self-signed Grafana |
224 | | - certificates. |
225 | | -
|
226 | | - Once done, run the following command to reconfig the daemon: |
227 | | -
|
228 | | - > ceph orch daemon reconfig <grafana-daemon> |
229 | | -
|
230 | | - """ |
231 | | - self.mgr.set_health_warning( |
232 | | - 'CEPHADM_CERT_ERROR', 'Invalid grafana certificate: ', 1, [err_msg]) |
233 | | - |
234 | | - return cert, pkey |
235 | | - |
236 | 192 | def get_active_daemon(self, daemon_descrs: List[DaemonDescription]) -> DaemonDescription: |
237 | 193 | # Use the least-created one as the active daemon |
238 | 194 | if daemon_descrs: |
|
0 commit comments