Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/cephadm/cephadm
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class NFSGanesha(object):
self.userid = dict_get(config_json, 'userid')
self.extra_args = dict_get(config_json, 'extra_args', [])
self.files = dict_get(config_json, 'files', {})
self.rgw = dict_get(config_json, 'rgw', {})

# validate the supplied args
self.validate()
Expand All @@ -248,13 +249,17 @@ class NFSGanesha(object):
# type: (str, Union[int, str]) -> NFSGanesha
return cls(fsid, daemon_id, get_parm(args.config_json), args.image)

@staticmethod
def get_container_mounts(data_dir):
def get_container_mounts(self, data_dir):
# type: (str) -> Dict[str, str]
mounts = dict()
mounts[os.path.join(data_dir, 'config')] = '/etc/ceph/ceph.conf:z'
mounts[os.path.join(data_dir, 'keyring')] = '/etc/ceph/keyring:z'
mounts[os.path.join(data_dir, 'etc/ganesha')] = '/etc/ganesha:z'
if self.rgw:
cluster = self.rgw.get('cluster', 'ceph')
rgw_user = self.rgw.get('user', 'admin')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we do this elsewhere? I don't think we should use the admin credential as a default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a NoneType be better here? At this point, we've already generated a client keyring and the input validation should have raised an exception if no keyring was provided ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a NoneType be better here?

Yes, I think so.

mounts[os.path.join(data_dir, 'keyring.rgw')] = \
'/var/lib/ceph/radosgw/%s-%s/keyring:z' % (cluster, rgw_user)
return mounts

@staticmethod
Expand Down Expand Up @@ -293,6 +298,13 @@ class NFSGanesha(object):
if fname not in self.files:
raise Error('required file missing from config-json: %s' % fname)

# check for an RGW config
if self.rgw:
if not self.rgw.get('keyring'):
raise Error('RGW keyring is missing')
if not self.rgw.get('user'):
raise Error('RGW user is missing')

def get_daemon_name(self):
# type: () -> str
return '%s.%s' % (self.daemon_type, self.daemon_id)
Expand Down Expand Up @@ -330,6 +342,14 @@ class NFSGanesha(object):
os.fchmod(f.fileno(), 0o600)
f.write(config_content)

# write the RGW keyring
if self.rgw:
keyring_path = os.path.join(data_dir, 'keyring.rgw')
with open(keyring_path, 'w') as f:
os.fchmod(f.fileno(), 0o600)
os.fchown(f.fileno(), uid, gid)
f.write(self.rgw.get('keyring', ''))

def get_rados_grace_container(self, action):
# type: (str) -> CephContainer
"""Container for a ganesha action on the grace db"""
Expand Down Expand Up @@ -1931,7 +1951,8 @@ def get_container_mounts(fsid, daemon_type, daemon_id,
if daemon_type == NFSGanesha.daemon_type:
assert daemon_id
data_dir = get_data_dir(fsid, daemon_type, daemon_id)
mounts.update(NFSGanesha.get_container_mounts(data_dir))
nfs_ganesha = NFSGanesha.init(fsid, daemon_id)
mounts.update(nfs_ganesha.get_container_mounts(data_dir))

if daemon_type == CephIscsi.daemon_type:
assert daemon_id
Expand Down
93 changes: 65 additions & 28 deletions src/pybind/mgr/cephadm/services/nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from orchestrator import OrchestratorError, DaemonDescription

from cephadm import utils
from cephadm.services.cephadmservice import CephadmDaemonSpec, CephService
from cephadm.services.cephadmservice import AuthEntity, CephadmDaemonSpec, CephService

if TYPE_CHECKING:
from cephadm.module import CephadmOrchestrator
Expand Down Expand Up @@ -49,19 +49,24 @@ def generate_config(self, daemon_spec: CephadmDaemonSpec[NFSServiceSpec]) -> Tup

deps: List[str] = []

# create the keyring
user = f'{daemon_type}.{daemon_id}'
keyring = self.create_keyring(daemon_spec)
# create the RADOS recovery pool keyring
rados_user = f'{daemon_type}.{daemon_id}'
rados_keyring = self.create_keyring(daemon_spec)

# create the rados config object
self.create_rados_config_obj(spec)

# create the RGW keyring
rgw_user = f'{rados_user}-rgw'
rgw_keyring = self.create_rgw_keyring(daemon_spec)

# generate the ganesha config
def get_ganesha_conf() -> str:
context = dict(user=user,
context = dict(user=rados_user,
nodeid=daemon_spec.name(),
pool=spec.pool,
namespace=spec.namespace if spec.namespace else '',
rgw_user=rgw_user,
url=spec.rados_config_location())
return self.mgr.template.render('services/nfs/ganesha.conf.j2', context)

Expand All @@ -71,44 +76,28 @@ def get_cephadm_config() -> Dict[str, Any]:
config['pool'] = spec.pool
if spec.namespace:
config['namespace'] = spec.namespace
config['userid'] = user
config['userid'] = rados_user
config['extra_args'] = ['-N', 'NIV_EVENT']
config['files'] = {
'ganesha.conf': get_ganesha_conf(),
}
config.update(
self.get_config_and_keyring(
daemon_type, daemon_id,
keyring=keyring,
keyring=rados_keyring,
host=host
)
)
config['rgw'] = {
'cluster': 'ceph',
'user': rgw_user,
'keyring': rgw_keyring,
}
logger.debug('Generated cephadm config-json: %s' % config)
return config

return get_cephadm_config(), deps

def create_keyring(self, daemon_spec: CephadmDaemonSpec) -> str:
assert daemon_spec.spec
daemon_id = daemon_spec.daemon_id
spec = daemon_spec.spec

entity = self.get_auth_entity(daemon_id)
logger.info('Create keyring: %s' % entity)

osd_caps = 'allow rw pool=%s' % (spec.pool)
if spec.namespace:
osd_caps = '%s namespace=%s' % (osd_caps, spec.namespace)

ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get-or-create',
'entity': entity,
'caps': ['mon', 'allow r',
'osd', osd_caps],
})

return keyring

def create_rados_config_obj(self,
spec: NFSServiceSpec,
clobber: bool = False) -> None:
Expand All @@ -130,3 +119,51 @@ def create_rados_config_obj(self,
# Create an empty config object
logger.info('Creating rados config object: %s' % obj)
ioctx.write_full(obj, ''.encode('utf-8'))

def create_keyring(self, daemon_spec: CephadmDaemonSpec[NFSServiceSpec]) -> str:
assert daemon_spec.spec
daemon_id = daemon_spec.daemon_id
spec = daemon_spec.spec
entity: AuthEntity = self.get_auth_entity(daemon_id)

osd_caps = 'allow rw pool=%s' % (spec.pool)
if spec.namespace:
osd_caps = '%s namespace=%s' % (osd_caps, spec.namespace)

logger.info('Create keyring: %s' % entity)
ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get-or-create',
'entity': entity,
'caps': ['mon', 'allow r',
'osd', osd_caps],
})

return keyring

def create_rgw_keyring(self, daemon_spec: CephadmDaemonSpec[NFSServiceSpec]) -> str:
daemon_id = daemon_spec.daemon_id
entity: AuthEntity = self.get_auth_entity(f'{daemon_id}-rgw')

logger.info('Create keyring: %s' % entity)
ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get-or-create',
'entity': entity,
'caps': ['mon', 'allow r',
'osd', 'allow rwx tag rgw *=*'],
})

return keyring

def remove_rgw_keyring(self, daemon: DaemonDescription) -> None:
daemon_id: str = daemon.daemon_id
entity: AuthEntity = self.get_auth_entity(f'{daemon_id}-rgw')

logger.info(f'Remove keyring: {entity}')
ret, out, err = self.mgr.check_mon_command({
'prefix': 'auth rm',
'entity': entity,
})

def post_remove(self, daemon: DaemonDescription) -> None:
super().post_remove(daemon)
self.remove_rgw_keyring(daemon)
5 changes: 5 additions & 0 deletions src/pybind/mgr/cephadm/templates/services/nfs/ganesha.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ RADOS_URLS {
watch_url = "{{ url }}";
}

RGW {
cluster = "ceph";
name = "client.{{ rgw_user }}";
}

Comment on lines 34 to 38

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding RGW block by default. It would be good to have export type option in ceph orch apply nfs or let higher level interfaces modify the ganesha conf according to export type. And we have cluster type option in volumes/nfs interface ceph nfs cluster create <type> <clusterid> [<placement>] for the purpose of modifying minimal ganesha conf according to export type. @batrick @jtlayton

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally agree our goal is to minimize ganesha.conf into a very simple bootstrap config, but we do need to manage the keyrings (both add/remove) and also mount the keyring into each daemon container.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is that once defined here you can't add other options to the RGW section from another RADOS config. cephadm can setup the keys but I think it'd be better for the higher level config to write the RGW section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been able to overwrite this block from the higher level config, but the entire block is replaced, which is problematic because this would require the higher level workflow to also have knowledge of the keyring entity.

%url {{ url }}