Skip to content

Commit afac55e

Browse files
authored
Merge pull request ceph#56713 from adk3798/client-keyring-ceph-conf
mgr/cephadm: make client-keyring deploying ceph.conf optional Reviewed-by: John Mulligan <[email protected]>
2 parents 7ecd06a + 2741d94 commit afac55e

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

doc/cephadm/operations.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ The resulting keyring file is:
601601
602602
-rw-r-----. 1 qemu qemu 156 Apr 21 08:47 /etc/ceph/client.client.rbd.keyring
603603
604+
By default, cephadm will also manage ``/etc/ceph/ceph.conf`` on hosts where it writes the keyrings.
605+
This feature can be suppressed by passing ``--no-ceph-conf`` when setting the keyring.
606+
607+
.. prompt:: bash #
608+
609+
ceph orch client-keyring set client.foo label:foo 0:0 --no-ceph-conf
610+
604611
Disabling Management of a Keyring File
605612
--------------------------------------
606613

src/pybind/mgr/cephadm/inventory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,14 @@ def __init__(
406406
mode: Optional[int] = None,
407407
uid: Optional[int] = None,
408408
gid: Optional[int] = None,
409+
include_ceph_conf: bool = True,
409410
) -> None:
410411
self.entity = entity
411412
self.placement = placement
412413
self.mode = mode or 0o600
413414
self.uid = uid or 0
414415
self.gid = gid or 0
416+
self.include_ceph_conf = include_ceph_conf
415417

416418
def validate(self) -> None:
417419
pass
@@ -423,6 +425,7 @@ def to_json(self) -> Dict[str, Any]:
423425
'mode': self.mode,
424426
'uid': self.uid,
425427
'gid': self.gid,
428+
'include_ceph_conf': self.include_ceph_conf,
426429
}
427430

428431
@property

src/pybind/mgr/cephadm/module.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ def _client_keyring_ls(self, format: Format = Format.plain) -> HandleCommandResu
15211521
output = to_format(self.keys.keys.values(), format, many=True, cls=ClientKeyringSpec)
15221522
else:
15231523
table = PrettyTable(
1524-
['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH'],
1524+
['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH', 'INCLUDE_CEPH_CONF'],
15251525
border=False)
15261526
table.align = 'l'
15271527
table.left_padding_width = 0
@@ -1532,6 +1532,7 @@ def _client_keyring_ls(self, format: Format = Format.plain) -> HandleCommandResu
15321532
utils.file_mode_to_str(ks.mode),
15331533
f'{ks.uid}:{ks.gid}',
15341534
ks.path,
1535+
ks.include_ceph_conf
15351536
))
15361537
output = table.get_string()
15371538
return HandleCommandResult(stdout=output)
@@ -1543,6 +1544,7 @@ def _client_keyring_set(
15431544
placement: str,
15441545
owner: Optional[str] = None,
15451546
mode: Optional[str] = None,
1547+
no_ceph_conf: bool = False,
15461548
) -> HandleCommandResult:
15471549
"""
15481550
Add or update client keyring under cephadm management
@@ -1565,7 +1567,14 @@ def _client_keyring_set(
15651567
else:
15661568
imode = 0o600
15671569
pspec = PlacementSpec.from_string(placement)
1568-
ks = ClientKeyringSpec(entity, pspec, mode=imode, uid=uid, gid=gid)
1570+
ks = ClientKeyringSpec(
1571+
entity,
1572+
pspec,
1573+
mode=imode,
1574+
uid=uid,
1575+
gid=gid,
1576+
include_ceph_conf=(not no_ceph_conf)
1577+
)
15691578
self.keys.update(ks)
15701579
self._kick_serve_loop()
15711580
return HandleCommandResult()

src/pybind/mgr/cephadm/serve.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,12 @@ def _calc_client_files(self) -> Dict[str, Dict[str, Tuple[int, int, int, bytes,
12321232
if host not in client_files:
12331233
client_files[host] = {}
12341234
ceph_conf = (0o644, 0, 0, bytes(config), str(config_digest))
1235-
client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf
1236-
client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf
1237-
ceph_admin_key = (ks.mode, ks.uid, ks.gid, keyring.encode('utf-8'), digest)
1238-
client_files[host][ks.path] = ceph_admin_key
1239-
client_files[host][f'{cluster_cfg_dir}/{os.path.basename(ks.path)}'] = ceph_admin_key
1235+
if ks.include_ceph_conf:
1236+
client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf
1237+
client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf
1238+
client_key = (ks.mode, ks.uid, ks.gid, keyring.encode('utf-8'), digest)
1239+
client_files[host][ks.path] = client_key
1240+
client_files[host][f'{cluster_cfg_dir}/{os.path.basename(ks.path)}'] = client_key
12401241
except Exception as e:
12411242
self.log.warning(
12421243
f'unable to calc client keyring {ks.entity} placement {ks.placement}: {e}')

src/pybind/mgr/cephadm/tests/test_cephadm.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,21 @@ def test_dont_write_client_files_to_unreachable_hosts(self, _get_client_files, c
21112111
CephadmServe(cephadm_module)._write_client_files({}, 'host2')
21122112
CephadmServe(cephadm_module)._write_client_files({}, 'host3')
21132113

2114+
@mock.patch('cephadm.CephadmOrchestrator.mon_command')
2115+
@mock.patch("cephadm.inventory.HostCache.get_host_client_files")
2116+
def test_dont_write_etc_ceph_client_files_when_turned_off(self, _get_client_files, _mon_command, cephadm_module):
2117+
cephadm_module.keys.update(ClientKeyringSpec('keyring1', PlacementSpec(label='keyring1'), include_ceph_conf=False))
2118+
cephadm_module.inventory.add_host(HostSpec('host1', '1.2.3.1', labels=['keyring1']))
2119+
cephadm_module.cache.update_host_daemons('host1', {})
2120+
2121+
_mon_command.return_value = (0, 'my-keyring', '')
2122+
2123+
client_files = CephadmServe(cephadm_module)._calc_client_files()
2124+
2125+
assert 'host1' in client_files
2126+
assert '/etc/ceph/ceph.keyring1.keyring' in client_files['host1']
2127+
assert '/etc/ceph/ceph.conf' not in client_files['host1']
2128+
21142129
def test_etc_ceph_init(self):
21152130
with with_cephadm_module({'manage_etc_ceph_ceph_conf': True}) as m:
21162131
assert m.manage_etc_ceph_ceph_conf is True

0 commit comments

Comments
 (0)