cephfs: allow only "good" characters

Allow only [A-Za-z0-9-_.] characters for FS, volume, subvolume and
subvolume group names and add test for the same.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
This commit is contained in:
Rishabh Dave 2020-07-31 18:31:57 +05:30
parent 35b0261818
commit 4022e2ba7d
5 changed files with 53 additions and 5 deletions

View File

@ -100,3 +100,7 @@
* Alpine build related script, documentation and test have been removed since * Alpine build related script, documentation and test have been removed since
the most updated APKBUILD script of Ceph is already included by Alpine Linux's the most updated APKBUILD script of Ceph is already included by Alpine Linux's
aports repository. aports repository.
* fs: Names of new FSs, volumes, subvolumes and subvolume groups can only
contain alphanumeric and ``-``, ``_`` and ``.`` characters. Some commands
or CephX credentials may not work with old FSs with non-conformant names.

View File

@ -1,4 +1,5 @@
import json import json
from io import StringIO
from teuthology.orchestra.run import CommandFailedError from teuthology.orchestra.run import CommandFailedError
@ -16,6 +17,29 @@ class TestAdminCommands(CephFSTestCase):
CLIENTS_REQUIRED = 1 CLIENTS_REQUIRED = 1
MDSS_REQUIRED = 1 MDSS_REQUIRED = 1
def test_fsnames_can_only_by_goodchars(self):
n = 'test_fsnames_can_only_by_goodchars'
metapoolname, datapoolname = n+'-testmetapool', n+'-testdatapool'
badname = n+'badname@#'
self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'create',
n+metapoolname)
self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'create',
n+datapoolname)
# test that fsname not with "goodchars" fails
args = ['fs', 'new', badname, metapoolname, datapoolname]
proc = self.fs.mon_manager.run_cluster_cmd(args=args,stderr=StringIO(),
check_status=False)
self.assertIn('invalid chars', proc.stderr.getvalue().lower())
self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'rm', metapoolname,
metapoolname,
'--yes-i-really-really-mean-it-not-faking')
self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'rm', datapoolname,
datapoolname,
'--yes-i-really-really-mean-it-not-faking')
def test_fs_status(self): def test_fs_status(self):
""" """
That `ceph fs status` command functions. That `ceph fs status` command functions.

View File

@ -3175,3 +3175,21 @@ class TestVolumes(CephFSTestCase):
self.assertEqual(ce.exitstatus, errno.ENOENT) self.assertEqual(ce.exitstatus, errno.ENOENT)
else: else:
self.fail("expected the 'fs subvolumegroup snapshot {0}' command to fail".format(op)) self.fail("expected the 'fs subvolumegroup snapshot {0}' command to fail".format(op))
def test_names_can_only_be_goodchars(self):
"""
Test the creating vols, subvols subvolgroups fails when their names uses
characters beyond [a-zA-Z0-9 -_.].
"""
volname, badname = 'testvol', 'abcd@#'
with self.assertRaises(CommandFailedError):
self._fs_cmd('volume', 'create', badname)
self._fs_cmd('volume', 'create', volname)
with self.assertRaises(CommandFailedError):
self._fs_cmd('subvolumegroup', 'create', volname, badname)
with self.assertRaises(CommandFailedError):
self._fs_cmd('subvolume', 'create', volname, badname)
self._fs_cmd('volume', 'rm', volname, '--yes-i-really-mean-it')

View File

@ -363,7 +363,7 @@ COMMAND_WITH_FLAG("mds newfs "
"make new filesystem using pools <metadata> and <data>", "make new filesystem using pools <metadata> and <data>",
"mds", "rw", FLAG(OBSOLETE)) "mds", "rw", FLAG(OBSOLETE))
COMMAND("fs new " COMMAND("fs new "
"name=fs_name,type=CephString " "name=fs_name,type=CephString,goodchars=[A-Za-z0-9-_.] "
"name=metadata,type=CephString " "name=metadata,type=CephString "
"name=data,type=CephString " "name=data,type=CephString "
"name=force,type=CephBool,req=false " "name=force,type=CephBool,req=false "

View File

@ -11,6 +11,8 @@ from .fs.nfs import NFSCluster, FSExport
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
goodchars = '[A-Za-z0-9-_.]'
class VolumesInfoWrapper(): class VolumesInfoWrapper():
def __init__(self, f, context): def __init__(self, f, context):
self.f = f self.f = f
@ -42,7 +44,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
}, },
{ {
'cmd': 'fs volume create ' 'cmd': 'fs volume create '
'name=name,type=CephString ' f'name=name,type=CephString,goodchars={goodchars} '
'name=placement,type=CephString,req=false ', 'name=placement,type=CephString,req=false ',
'desc': "Create a CephFS volume", 'desc': "Create a CephFS volume",
'perm': 'rw' 'perm': 'rw'
@ -63,7 +65,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
{ {
'cmd': 'fs subvolumegroup create ' 'cmd': 'fs subvolumegroup create '
'name=vol_name,type=CephString ' 'name=vol_name,type=CephString '
'name=group_name,type=CephString ' f'name=group_name,type=CephString,goodchars={goodchars} '
'name=pool_layout,type=CephString,req=false ' 'name=pool_layout,type=CephString,req=false '
'name=uid,type=CephInt,req=false ' 'name=uid,type=CephInt,req=false '
'name=gid,type=CephInt,req=false ' 'name=gid,type=CephInt,req=false '
@ -90,7 +92,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
{ {
'cmd': 'fs subvolume create ' 'cmd': 'fs subvolume create '
'name=vol_name,type=CephString ' 'name=vol_name,type=CephString '
'name=sub_name,type=CephString ' f'name=sub_name,type=CephString,goodchars={goodchars} '
'name=size,type=CephInt,req=false ' 'name=size,type=CephInt,req=false '
'name=group_name,type=CephString,req=false ' 'name=group_name,type=CephString,req=false '
'name=pool_layout,type=CephString,req=false ' 'name=pool_layout,type=CephString,req=false '
@ -315,7 +317,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
{ {
'cmd': 'nfs cluster create ' 'cmd': 'nfs cluster create '
'name=type,type=CephString ' 'name=type,type=CephString '
'name=clusterid,type=CephString,goodchars=[A-Za-z0-9-_.] ' f'name=clusterid,type=CephString,goodchars={goodchars} '
'name=placement,type=CephString,req=false ', 'name=placement,type=CephString,req=false ',
'desc': "Create an NFS Cluster", 'desc': "Create an NFS Cluster",
'perm': 'rw' 'perm': 'rw'