@@ -10,7 +10,6 @@ class Server: # type: ignore
1010import logging
1111import socket
1212import ssl
13- import tempfile
1413import threading
1514import time
1615
@@ -20,11 +19,12 @@ class Server: # type: ignore
2019from ceph .deployment .inventory import Devices
2120from ceph .deployment .service_spec import ServiceSpec , PlacementSpec
2221from cephadm .services .cephadmservice import CephadmDaemonDeploySpec
23- from cephadm .ssl_cert_utils import SSLCerts
2422from mgr_util import test_port_allocation , PortAlreadyInUse
23+ from mgr_util import verify_tls_files
24+ import tempfile
2525
2626from urllib .error import HTTPError , URLError
27- from typing import Any , Dict , List , Set , TYPE_CHECKING , Optional , MutableMapping
27+ from typing import Any , Dict , List , Set , TYPE_CHECKING , Optional , MutableMapping , IO
2828
2929if TYPE_CHECKING :
3030 from cephadm .module import CephadmOrchestrator
@@ -46,9 +46,10 @@ class AgentEndpoint:
4646
4747 def __init__ (self , mgr : "CephadmOrchestrator" ) -> None :
4848 self .mgr = mgr
49- self .ssl_certs = SSLCerts ()
5049 self .server_port = 7150
5150 self .server_addr = self .mgr .get_mgr_ip ()
51+ self .key_file : IO [bytes ]
52+ self .cert_file : IO [bytes ]
5253
5354 def configure_routes (self ) -> None :
5455 conf = {'/' : {'tools.trailing_slash.on' : False }}
@@ -57,19 +58,19 @@ def configure_routes(self) -> None:
5758 cherrypy .tree .mount (self .node_proxy_endpoint , '/node-proxy' , config = conf )
5859
5960 def configure_tls (self , server : Server ) -> None :
60- old_cert = self .mgr .cert_key_store .get_cert ('agent_endpoint_root_cert' )
61- old_key = self .mgr .cert_key_store .get_key ('agent_endpoint_key' )
61+ addr = self .mgr .get_mgr_ip ()
62+ host = self .mgr .get_hostname ()
63+ cert , key = self .mgr .cert_mgr .generate_cert (host , addr )
64+ self .cert_file = tempfile .NamedTemporaryFile ()
65+ self .cert_file .write (cert .encode ('utf-8' ))
66+ self .cert_file .flush () # cert_tmp must not be gc'ed
6267
63- if old_cert and old_key :
64- self .ssl_certs .load_root_credentials (old_cert , old_key )
65- else :
66- self .ssl_certs .generate_root_cert (self .mgr .get_mgr_ip ())
67- self .mgr .cert_key_store .save_cert ('agent_endpoint_root_cert' , self .ssl_certs .get_root_cert ())
68- self .mgr .cert_key_store .save_key ('agent_endpoint_key' , self .ssl_certs .get_root_key ())
68+ self .key_file = tempfile .NamedTemporaryFile ()
69+ self .key_file .write (key .encode ('utf-8' ))
70+ self .key_file .flush () # pkey_tmp must not be gc'ed
6971
70- host = self .mgr .get_hostname ()
71- addr = self .mgr .get_mgr_ip ()
72- server .ssl_certificate , server .ssl_private_key = self .ssl_certs .generate_cert_files (host , addr )
72+ verify_tls_files (self .cert_file .name , self .key_file .name )
73+ server .ssl_certificate , server .ssl_private_key = self .cert_file .name , self .key_file .name
7374
7475 def find_free_port (self ) -> None :
7576 max_port = self .server_port + 150
@@ -94,7 +95,7 @@ def configure(self) -> None:
9495class NodeProxyEndpoint :
9596 def __init__ (self , mgr : "CephadmOrchestrator" ):
9697 self .mgr = mgr
97- self .ssl_root_crt = self .mgr .http_server . agent . ssl_certs . get_root_cert ()
98+ self .ssl_root_crt = self .mgr .cert_mgr . get_root_ca ()
9899 self .ssl_ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
99100 self .ssl_ctx .check_hostname = False
100101 self .ssl_ctx .verify_mode = ssl .CERT_NONE
@@ -301,7 +302,7 @@ def led(self, **kw: Any) -> Dict[str, Any]:
301302 endpoint : List [Any ] = ['led' , led_type ]
302303 device : str = id_drive if id_drive else ''
303304
304- ssl_root_crt = self .mgr .http_server . agent . ssl_certs . get_root_cert ()
305+ ssl_root_crt = self .mgr .cert_mgr . get_root_ca ()
305306 ssl_ctx = ssl .create_default_context ()
306307 ssl_ctx .check_hostname = True
307308 ssl_ctx .verify_mode = ssl .CERT_REQUIRED
@@ -774,14 +775,13 @@ def run(self) -> None:
774775 self .mgr .agent_cache .sending_agent_message [self .host ] = True
775776 try :
776777 assert self .agent
777- root_cert = self .agent . ssl_certs . get_root_cert ()
778+ root_cert = self .mgr . cert_mgr . get_root_ca ()
778779 root_cert_tmp = tempfile .NamedTemporaryFile ()
779780 root_cert_tmp .write (root_cert .encode ('utf-8' ))
780781 root_cert_tmp .flush ()
781782 root_cert_fname = root_cert_tmp .name
782783
783- cert , key = self .agent .ssl_certs .generate_cert (
784- self .mgr .get_hostname (), self .mgr .get_mgr_ip ())
784+ cert , key = self .mgr .cert_mgr .generate_cert (self .mgr .get_hostname (), self .mgr .get_mgr_ip ())
785785
786786 cert_tmp = tempfile .NamedTemporaryFile ()
787787 cert_tmp .write (cert .encode ('utf-8' ))
@@ -950,7 +950,7 @@ def _check_agent(self, host: str) -> bool:
950950 down = False
951951 try :
952952 assert self .agent
953- assert self .agent . ssl_certs . get_root_cert ()
953+ assert self .mgr . cert_mgr . get_root_ca ()
954954 except Exception :
955955 self .mgr .log .debug (
956956 f'Delaying checking agent on { host } until cephadm endpoint finished creating root cert' )
@@ -974,7 +974,7 @@ def _check_agent(self, host: str) -> bool:
974974 # so it's necessary to check this one specifically
975975 root_cert_match = False
976976 try :
977- root_cert = self .agent . ssl_certs . get_root_cert ()
977+ root_cert = self .mgr . cert_mgr . get_root_ca ()
978978 if last_deps and root_cert in last_deps :
979979 root_cert_match = True
980980 except Exception :
0 commit comments