diff --git a/PendingReleaseNotes b/PendingReleaseNotes index e7e24def808..e2c727bc348 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -100,3 +100,7 @@ * 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 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. diff --git a/qa/tasks/cephfs/test_admin.py b/qa/tasks/cephfs/test_admin.py index 661547e733f..7554684d162 100644 --- a/qa/tasks/cephfs/test_admin.py +++ b/qa/tasks/cephfs/test_admin.py @@ -1,4 +1,5 @@ import json +from io import StringIO from teuthology.orchestra.run import CommandFailedError @@ -16,6 +17,29 @@ class TestAdminCommands(CephFSTestCase): CLIENTS_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): """ That `ceph fs status` command functions. diff --git a/qa/tasks/cephfs/test_volumes.py b/qa/tasks/cephfs/test_volumes.py index e8098262597..f8452d51aee 100644 --- a/qa/tasks/cephfs/test_volumes.py +++ b/qa/tasks/cephfs/test_volumes.py @@ -3175,3 +3175,21 @@ class TestVolumes(CephFSTestCase): self.assertEqual(ce.exitstatus, errno.ENOENT) else: 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') diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index f1e429aef23..1ae7a1de6f9 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -363,7 +363,7 @@ COMMAND_WITH_FLAG("mds newfs " "make new filesystem using pools <metadata> and <data>", "mds", "rw", FLAG(OBSOLETE)) COMMAND("fs new " - "name=fs_name,type=CephString " + "name=fs_name,type=CephString,goodchars=[A-Za-z0-9-_.] " "name=metadata,type=CephString " "name=data,type=CephString " "name=force,type=CephBool,req=false " diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index c611a5df782..80b6300cd35 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -11,6 +11,8 @@ from .fs.nfs import NFSCluster, FSExport log = logging.getLogger(__name__) +goodchars = '[A-Za-z0-9-_.]' + class VolumesInfoWrapper(): def __init__(self, f, context): self.f = f @@ -42,7 +44,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): }, { 'cmd': 'fs volume create ' - 'name=name,type=CephString ' + f'name=name,type=CephString,goodchars={goodchars} ' 'name=placement,type=CephString,req=false ', 'desc': "Create a CephFS volume", 'perm': 'rw' @@ -63,7 +65,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): { 'cmd': 'fs subvolumegroup create ' '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=uid,type=CephInt,req=false ' 'name=gid,type=CephInt,req=false ' @@ -90,7 +92,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): { 'cmd': 'fs subvolume create ' '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=group_name,type=CephString,req=false ' 'name=pool_layout,type=CephString,req=false ' @@ -315,7 +317,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): { 'cmd': 'nfs cluster create ' '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 ', 'desc': "Create an NFS Cluster", 'perm': 'rw'