Skip to content

Commit

Permalink
mgr/cephadm/service: factor out get_auth_entity()
Browse files Browse the repository at this point in the history
Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas authored and rzarzynski committed Sep 12, 2022
1 parent 68abdc2 commit 2eedae9
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/pybind/mgr/cephadm/services/cephadmservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@
AuthEntity = NewType('AuthEntity', str)


def get_auth_entity(daemon_type: str, daemon_id: str, host: str = "") -> AuthEntity:
"""
Map the daemon id to a cephx keyring entity name
"""
# despite this mapping entity names to daemons, self.TYPE within
# the CephService class refers to service types, not daemon types
if daemon_type in ['rgw', 'rbd-mirror', 'cephfs-mirror', 'nfs', "iscsi", 'ingress']:
return AuthEntity(f'client.{daemon_type}.{daemon_id}')
elif daemon_type in ['crash', 'agent']:
if host == "":
raise OrchestratorError(
f'Host not provided to generate <{daemon_type}> auth entity name')
return AuthEntity(f'client.{daemon_type}.{host}')
elif daemon_type == 'mon':
return AuthEntity('mon.')
elif daemon_type in ['mgr', 'osd', 'mds']:
return AuthEntity(f'{daemon_type}.{daemon_id}')
else:
raise OrchestratorError(f"unknown daemon type {daemon_type}")


class CephadmDaemonDeploySpec:
# typing.NamedTuple + Generic is broken in py36
def __init__(self, host: str, daemon_id: str,
Expand Down Expand Up @@ -81,6 +102,9 @@ def __init__(self, host: str, daemon_id: str,
def name(self) -> str:
return '%s.%s' % (self.daemon_type, self.daemon_id)

def entity_name(self) -> str:
return get_auth_entity(self.daemon_type, self.daemon_id, host=self.host)

def config_get_files(self) -> Dict[str, Any]:
files = self.extra_files
if self.ceph_conf:
Expand Down Expand Up @@ -473,24 +497,7 @@ def post_remove(self, daemon: DaemonDescription, is_failed_deploy: bool) -> None
self.remove_keyring(daemon)

def get_auth_entity(self, daemon_id: str, host: str = "") -> AuthEntity:
"""
Map the daemon id to a cephx keyring entity name
"""
# despite this mapping entity names to daemons, self.TYPE within
# the CephService class refers to service types, not daemon types
if self.TYPE in ['rgw', 'rbd-mirror', 'cephfs-mirror', 'nfs', "iscsi", 'ingress']:
return AuthEntity(f'client.{self.TYPE}.{daemon_id}')
elif self.TYPE in ['crash', 'agent']:
if host == "":
raise OrchestratorError(
f'Host not provided to generate <{self.TYPE}> auth entity name')
return AuthEntity(f'client.{self.TYPE}.{host}')
elif self.TYPE == 'mon':
return AuthEntity('mon.')
elif self.TYPE in ['mgr', 'osd', 'mds']:
return AuthEntity(f'{self.TYPE}.{daemon_id}')
else:
raise OrchestratorError("unknown daemon type")
return get_auth_entity(self.TYPE, daemon_id, host=host)

def get_config_and_keyring(self,
daemon_type: str,
Expand Down Expand Up @@ -547,7 +554,7 @@ def prepare_create(self, daemon_spec: CephadmDaemonDeploySpec) -> CephadmDaemonD
# get mon. key
ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get',
'entity': self.get_auth_entity(name),
'entity': daemon_spec.entity_name(),
})

extra_config = '[mon.%s]\n' % name
Expand Down Expand Up @@ -1053,7 +1060,7 @@ def prepare_create(self, daemon_spec: CephadmDaemonDeploySpec) -> CephadmDaemonD

ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get-or-create',
'entity': self.get_auth_entity(daemon_spec.daemon_id),
'entity': daemon_spec.entity_name(),
'caps': ['mon', 'profile cephfs-mirror',
'mds', 'allow r',
'osd', 'allow rw tag cephfs metadata=*, allow r tag cephfs data=*',
Expand Down

0 comments on commit 2eedae9

Please sign in to comment.