Skip to content

Commit

Permalink
Merge pull request ceph#57037 from adk3798/cephadm-limit-shell-mounts
Browse files Browse the repository at this point in the history
cephadm: limit mounts for shell and ceph-volume commands
  • Loading branch information
guits committed Aug 8, 2024
2 parents e656af9 + 8164efe commit 1924efd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
14 changes: 12 additions & 2 deletions qa/tasks/cephadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,18 @@ def ceph_osds(ctx, config):
short_dev = dev
log.info('Deploying %s on %s with %s...' % (
osd, remote.shortname, dev))
_shell(ctx, cluster_name, remote, [
'ceph-volume', 'lvm', 'zap', dev])
remote.run(
args=[
'sudo',
ctx.cephadm,
'--image', ctx.ceph[cluster_name].image,
'ceph-volume',
'-c', '/etc/ceph/{}.conf'.format(cluster_name),
'-k', '/etc/ceph/{}.client.admin.keyring'.format(cluster_name),
'--fsid', ctx.ceph[cluster_name].fsid,
'--', 'lvm', 'zap', dev
]
)
add_osd_args = ['ceph', 'orch', 'daemon', 'add', 'osd',
remote.shortname + ':' + short_dev]
osd_method = config.get('osd_method')
Expand Down
4 changes: 2 additions & 2 deletions src/cephadm/cephadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3172,7 +3172,7 @@ def command_shell(ctx):
daemon_type = ctx.name
daemon_id = None
else:
daemon_type = 'osd' # get the most mounts
daemon_type = 'shell' # get limited set of mounts
daemon_id = None

if ctx.fsid and daemon_type in ceph_daemons():
Expand Down Expand Up @@ -3310,7 +3310,7 @@ def command_ceph_volume(ctx):
lock.acquire()

(uid, gid) = (0, 0) # ceph-volume runs as root
mounts = get_container_mounts_for_type(ctx, ctx.fsid, 'osd')
mounts = get_container_mounts_for_type(ctx, ctx.fsid, 'ceph-volume')

tmp_config = None
tmp_keyring = None
Expand Down
21 changes: 17 additions & 4 deletions src/cephadm/cephadmlib/daemons/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,17 @@ def get_ceph_mounts_for_type(
"""
mounts = dict()

if daemon_type in ceph_daemons():
if daemon_type in ceph_daemons() or daemon_type in [
'ceph-volume',
'shell',
]:
if fsid:
run_path = os.path.join('/var/run/ceph', fsid)
if os.path.exists(run_path):
mounts[run_path] = '/var/run/ceph:z'
log_dir = os.path.join(ctx.log_dir, fsid)
if not os.path.exists(log_dir):
os.mkdir(log_dir)
mounts[log_dir] = '/var/log/ceph:z'
crash_dir = '/var/lib/ceph/%s/crash' % fsid
if os.path.exists(crash_dir):
Expand All @@ -438,14 +443,19 @@ def get_ceph_mounts_for_type(
journald_sock_dir = '/run/systemd/journal'
mounts[journald_sock_dir] = journald_sock_dir

if daemon_type in ['mon', 'osd', 'clusterless-ceph-volume']:
if daemon_type in [
'mon',
'osd',
'ceph-volume',
'clusterless-ceph-volume',
]:
mounts['/dev'] = '/dev' # FIXME: narrow this down?
mounts['/run/udev'] = '/run/udev'
if daemon_type in ['osd', 'clusterless-ceph-volume']:
if daemon_type in ['osd', 'ceph-volume', 'clusterless-ceph-volume']:
mounts['/sys'] = '/sys' # for numa.cc, pick_address, cgroups, ...
mounts['/run/lvm'] = '/run/lvm'
mounts['/run/lock/lvm'] = '/run/lock/lvm'
if daemon_type == 'osd':
if daemon_type in ['osd', 'ceph-volume']:
# selinux-policy in the container may not match the host.
if HostFacts(ctx).selinux_enabled:
cluster_dir = f'{ctx.data_dir}/{fsid}'
Expand All @@ -458,7 +468,10 @@ def get_ceph_mounts_for_type(
logger.error(
f'Cluster direcotry {cluster_dir} does not exist.'
)
if daemon_type == 'osd':
mounts['/'] = '/rootfs'
elif daemon_type == 'ceph-volume':
mounts['/'] = '/rootfs:rslave'

try:
if (
Expand Down
1 change: 1 addition & 0 deletions src/cephadm/tests/test_cephadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ def test_mon_crush_location(self, funkypatch):
_deploy_daemon = funkypatch.patch('cephadm.deploy_daemon')
funkypatch.patch('cephadm.make_var_run')
funkypatch.patch('cephadmlib.file_utils.make_run_dir')
funkypatch.patch('os.mkdir')
_migrate_sysctl = funkypatch.patch('cephadm.migrate_sysctl_dir')
funkypatch.patch(
'cephadm.check_unit',
Expand Down

0 comments on commit 1924efd

Please sign in to comment.