Skip to content

Commit 37869ee

Browse files
committed
mgr/cephadm: adding new comands to remvoe keys/certificates
Signed-off-by: Redouane Kachach <[email protected]>
1 parent 70e4e1c commit 37869ee

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

doc/cephadm/certmgr.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,32 @@ To update or set a new private key:
229229

230230
This command allows administrators to provide new private keys for services.
231231

232+
Removing a Certificate
233+
======================
234+
235+
To remove an existing certificate:
236+
237+
.. prompt:: bash #
238+
239+
ceph orch certmgr cert rm <certificate_name> [--service_name <value>] [--hostname <value>]
240+
241+
**Note:** For certificates with host or service scope, use the `--service-name` or `--hostname` option to specify the target.
242+
243+
``<certificate_name>`` must be a valid certificate name. Use ``ceph orch certmgr cert ls`` to list supported certificates.
244+
245+
Removing a Private Key
246+
======================
247+
248+
To remove an existing private key:
249+
250+
.. prompt:: bash #
251+
252+
ceph orch certmgr key rm <key-name> [--service_name <value>] [--hostname <value>]
253+
254+
**Note:** For keys with host or service scope, use the `--service-name` or `--hostname` option to specify the target.
255+
256+
``<key_name>`` must be a valid key name. Use ``ceph orch certmgr key ls`` to list supported keys.
257+
232258
Generating Certificates
233259
=======================
234260

src/pybind/mgr/cephadm/module.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from ceph.deployment.service_spec import PrometheusSpec
1919
from cephadm.cert_mgr import CertMgr
20-
from cephadm.tlsobject_store import TLSObjectScope
20+
from cephadm.tlsobject_store import TLSObjectScope, TLSObjectException
2121

2222
import string
2323
from typing import List, Dict, Optional, Callable, Tuple, TypeVar, \
@@ -3317,6 +3317,36 @@ def cert_store_set_key(
33173317
self.cert_mgr.save_key(key_name, key, service_name, hostname, True)
33183318
return f'Key for {key_name} set correctly'
33193319

3320+
@handle_orch_error
3321+
def cert_store_rm_cert(
3322+
self,
3323+
cert_name: str,
3324+
service_name: Optional[str] = None,
3325+
hostname: Optional[str] = None,
3326+
) -> str:
3327+
3328+
try:
3329+
self.cert_mgr.rm_cert(cert_name, service_name, hostname)
3330+
return f'Certificate for {cert_name} removed correctly'
3331+
except TLSObjectException:
3332+
raise OrchestratorError("Cannot delete the certificate. Please use 'ceph orch certmgr cert ls' to list available certificates. \n"
3333+
"Note: for certificates with host/service scope use --service-name or --hostname to specify the target.")
3334+
3335+
@handle_orch_error
3336+
def cert_store_rm_key(
3337+
self,
3338+
key_name: str,
3339+
service_name: Optional[str] = None,
3340+
hostname: Optional[str] = None,
3341+
) -> str:
3342+
3343+
try:
3344+
self.cert_mgr.rm_key(key_name, service_name, hostname)
3345+
return f'Key for {key_name} removed correctly'
3346+
except TLSObjectException:
3347+
raise OrchestratorError("Cannot delete the key. Please use 'ceph orch certmgr key ls' to list available keys. \n"
3348+
"Note: for keys with host/service scope use --service-name or --hostname to specify the target.")
3349+
33203350
@handle_orch_error
33213351
def apply_mon(self, spec: ServiceSpec) -> str:
33223352
return self._apply(spec)

src/pybind/mgr/orchestrator/_interface.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,22 @@ def cert_store_set_key(
623623
) -> OrchResult[str]:
624624
raise NotImplementedError()
625625

626+
def cert_store_rm_cert(
627+
self,
628+
cert_name: str,
629+
service_name: Optional[str] = None,
630+
hostname: Optional[str] = None,
631+
) -> OrchResult[str]:
632+
raise NotImplementedError()
633+
634+
def cert_store_rm_key(
635+
self,
636+
key_name: str,
637+
service_name: Optional[str] = None,
638+
hostname: Optional[str] = None,
639+
) -> OrchResult[str]:
640+
raise NotImplementedError()
641+
626642
@handle_orch_error
627643
def apply(
628644
self,

src/pybind/mgr/orchestrator/module.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,42 @@ def _cert_store_set_key(
13181318
output = raise_if_exception(completion)
13191319
return HandleCommandResult(stdout=output)
13201320

1321+
@_cli_write_command('orch certmgr cert rm')
1322+
def _cert_store_rm_cert(
1323+
self,
1324+
cert_name: str,
1325+
_end_positional_: int = 0,
1326+
service_name: Optional[str] = None,
1327+
hostname: Optional[str] = None,
1328+
inbuf: Optional[str] = None
1329+
) -> HandleCommandResult:
1330+
1331+
completion = self.cert_store_rm_cert(
1332+
cert_name,
1333+
service_name,
1334+
hostname,
1335+
)
1336+
output = raise_if_exception(completion)
1337+
return HandleCommandResult(stdout=output)
1338+
1339+
@_cli_write_command('orch certmgr key rm')
1340+
def _cert_store_rm_key(
1341+
self,
1342+
key_name: str,
1343+
_end_positional_: int = 0,
1344+
service_name: Optional[str] = None,
1345+
hostname: Optional[str] = None,
1346+
inbuf: Optional[str] = None
1347+
) -> HandleCommandResult:
1348+
1349+
completion = self.cert_store_rm_key(
1350+
key_name,
1351+
service_name,
1352+
hostname,
1353+
)
1354+
output = raise_if_exception(completion)
1355+
return HandleCommandResult(stdout=output)
1356+
13211357
def _get_credentials(self, username: Optional[str] = None, password: Optional[str] = None, inbuf: Optional[str] = None) -> Tuple[str, str]:
13221358

13231359
_username = username

0 commit comments

Comments
 (0)