Skip to content

Commit

Permalink
Merge pull request #56029 from asm0deuz/wip-64698-reef
Browse files Browse the repository at this point in the history
reef: mgr/cephadm: Allow idmap overrides in nfs-ganesha configuration

Reviewed-by: Adam King <adking@redhat.com>
  • Loading branch information
adk3798 committed Mar 15, 2024
2 parents a752c2f + 677fc83 commit 4a4f5a2
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cephadm/cephadm.py
Expand Up @@ -848,7 +848,7 @@ class NFSGanesha(object):
entrypoint = '/usr/bin/ganesha.nfsd'
daemon_args = ['-F', '-L', 'STDERR']

required_files = ['ganesha.conf']
required_files = ['ganesha.conf', 'idmap.conf']

port_map = {
'nfs': 2049,
Expand Down
1 change: 1 addition & 0 deletions src/cephadm/tests/test_nfs.py
Expand Up @@ -25,6 +25,7 @@ def nfs_json(**kwargs):
if kwargs.get("files"):
result["files"] = {
"ganesha.conf": "",
"idmap.conf": "",
}
if kwargs.get("rgw_content"):
result["rgw"] = dict(kwargs["rgw_content"])
Expand Down
20 changes: 20 additions & 0 deletions src/pybind/mgr/cephadm/services/nfs.py
Expand Up @@ -5,6 +5,8 @@
import subprocess
import tempfile
from typing import Dict, Tuple, Any, List, cast, Optional
from configparser import ConfigParser
from io import StringIO

from mgr_module import HandleCommandResult
from mgr_module import NFS_POOL_NAME as POOL_NAME
Expand Down Expand Up @@ -79,6 +81,8 @@ def generate_config(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[Dict[st

nodeid = f'{daemon_spec.service_name}.{daemon_spec.rank}'

nfs_idmap_conf = '/etc/ganesha/idmap.conf'

# create the RADOS recovery pool keyring
rados_user = f'{daemon_type}.{daemon_id}'
rados_keyring = self.create_keyring(daemon_spec)
Expand Down Expand Up @@ -115,12 +119,27 @@ def get_ganesha_conf() -> str:
"port": daemon_spec.ports[0] if daemon_spec.ports else 2049,
"bind_addr": bind_addr,
"haproxy_hosts": [],
"nfs_idmap_conf": nfs_idmap_conf,
}
if spec.enable_haproxy_protocol:
context["haproxy_hosts"] = self._haproxy_hosts()
logger.debug("selected haproxy_hosts: %r", context["haproxy_hosts"])
return self.mgr.template.render('services/nfs/ganesha.conf.j2', context)

# generate the idmap config
def get_idmap_conf() -> str:
idmap_conf = spec.idmap_conf
output = ''
if idmap_conf is not None:
cp = ConfigParser()
out = StringIO()
cp.read_dict(idmap_conf)
cp.write(out)
out.seek(0)
output = out.read()
out.close()
return output

# generate the cephadm config json
def get_cephadm_config() -> Dict[str, Any]:
config: Dict[str, Any] = {}
Expand All @@ -130,6 +149,7 @@ def get_cephadm_config() -> Dict[str, Any]:
config['extra_args'] = ['-N', 'NIV_EVENT']
config['files'] = {
'ganesha.conf': get_ganesha_conf(),
'idmap.conf': get_idmap_conf()
}
config.update(
self.get_config_and_keyring(
Expand Down
3 changes: 3 additions & 0 deletions src/pybind/mgr/cephadm/templates/services/nfs/ganesha.conf.j2
Expand Up @@ -16,6 +16,9 @@ NFSv4 {
Delegations = false;
RecoveryBackend = 'rados_cluster';
Minor_Versions = 1, 2;
{% if nfs_idmap_conf %}
IdmapConf = "{{ nfs_idmap_conf }}";
{% endif %}
}

RADOS_KV {
Expand Down
3 changes: 2 additions & 1 deletion src/pybind/mgr/cephadm/tests/test_services.py
Expand Up @@ -2451,6 +2451,7 @@ def fake_keys():
' Delegations = false;\n'
" RecoveryBackend = 'rados_cluster';\n"
' Minor_Versions = 1, 2;\n'
' IdmapConf = "/etc/ganesha/idmap.conf";\n'
'}\n'
'\n'
'RADOS_KV {\n'
Expand All @@ -2474,7 +2475,7 @@ def fake_keys():
"%url rados://.nfs/foo/conf-nfs.foo"
)
nfs_expected_conf = {
'files': {'ganesha.conf': nfs_ganesha_txt},
'files': {'ganesha.conf': nfs_ganesha_txt, 'idmap.conf': ''},
'config': '',
'extra_args': ['-N', 'NIV_EVENT'],
'keyring': (
Expand Down
2 changes: 2 additions & 0 deletions src/python-common/ceph/deployment/service_spec.py
Expand Up @@ -953,6 +953,7 @@ def __init__(self,
extra_container_args: Optional[GeneralArgList] = None,
extra_entrypoint_args: Optional[GeneralArgList] = None,
enable_haproxy_protocol: bool = False,
idmap_conf: Optional[Dict[str, Dict[str, str]]] = None,
custom_configs: Optional[List[CustomConfig]] = None,
):
assert service_type == 'nfs'
Expand All @@ -965,6 +966,7 @@ def __init__(self,
self.port = port
self.virtual_ip = virtual_ip
self.enable_haproxy_protocol = enable_haproxy_protocol
self.idmap_conf = idmap_conf

def get_port_start(self) -> List[int]:
if self.port:
Expand Down
6 changes: 6 additions & 0 deletions src/python-common/ceph/tests/test_service_spec.py
Expand Up @@ -384,6 +384,12 @@ def test_osd_unmanaged():
service_id: mynfs
service_name: nfs.mynfs
spec:
idmap_conf:
general:
local-realms: domain.org
mapping:
nobody-group: nfsnobody
nobody-user: nfsnobody
port: 1234
---
service_type: iscsi
Expand Down

0 comments on commit 4a4f5a2

Please sign in to comment.