From: Matan Breizman Date: Sat, 5 Feb 2022 16:50:17 +0000 (+0000) Subject: mon/OSDMonitor: Restrict pool names beggining with a dot X-Git-Tag: v18.0.0~1343^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1aaf24f50390f12eb9baa5981758bb91d84669e7;p=ceph.git mon/OSDMonitor: Restrict pool names beggining with a dot Signed-off-by: Matan Breizman --- diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 31a2d11aa49..67d67b6e377 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -1061,7 +1061,8 @@ COMMAND("osd pool create " "name=autoscale_mode,type=CephChoices,strings=on|off|warn,req=false " "name=bulk,type=CephBool,req=false " "name=target_size_bytes,type=CephInt,range=0,req=false " - "name=target_size_ratio,type=CephFloat,range=0|1,req=false",\ + "name=target_size_ratio,type=CephFloat,range=0|1,req=false "\ + "name=yes_i_really_mean_it,type=CephBool,req=false", "create pool", "osd", "rw") COMMAND_WITH_FLAG("osd pool delete " "name=pool,type=CephPoolname " @@ -1080,7 +1081,8 @@ COMMAND("osd pool rm " "osd", "rw") COMMAND("osd pool rename " "name=srcpool,type=CephPoolname " - "name=destpool,type=CephPoolname", + "name=destpool,type=CephPoolname " + "name=yes_i_really_mean_it,type=CephBool,req=false", "rename to ", "osd", "rw") COMMAND("osd pool get " "name=pool,type=CephPoolname " diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 3e59384a389..7a62573897d 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -12829,6 +12829,14 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, string poolstr; cmd_getval(cmdmap, "pool", poolstr); + bool confirm = false; + //confirmation may be set to true only by internal operations. + cmd_getval(cmdmap, "yes_i_really_mean_it", confirm); + if (poolstr[0] == '.' && !confirm) { + ss << "pool names beginning with . are not allowed"; + err = 0; + goto reply; + } int64_t pool_id = osdmap.lookup_pg_pool_name(poolstr); if (pool_id >= 0) { const pg_pool_t *p = osdmap.get_pg_pool(pool_id); @@ -13056,7 +13064,14 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, cmd_getval(cmdmap, "destpool", destpoolstr); int64_t pool_src = osdmap.lookup_pg_pool_name(srcpoolstr.c_str()); int64_t pool_dst = osdmap.lookup_pg_pool_name(destpoolstr.c_str()); - + bool confirm = false; + //confirmation may be set to true only by internal operations. + cmd_getval(cmdmap, "yes_i_really_mean_it", confirm); + if (destpoolstr[0] == '.' && !confirm) { + ss << "pool names beginning with . are not allowed"; + err = 0; + goto reply; + } if (pool_src < 0) { if (pool_dst >= 0) { // src pool doesn't exist, dst pool does exist: to ensure idempotency diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 30cd1fc5e4b..68ee4a57d03 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -1044,6 +1044,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): 'format': 'json', 'srcpool': srcpool, 'destpool': destpool, + 'yes_i_really_mean_it': True } self.check_mon_command(c) @@ -1057,6 +1058,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): 'pg_num': 1, 'pg_num_min': 1, 'pg_num_max': 32, + 'yes_i_really_mean_it': True } self.check_mon_command(c) diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 721eda2bdfe..b7700df375f 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -37,7 +37,9 @@ def resolve_ip(hostname: str) -> str: def create_ganesha_pool(mgr: 'MgrModule') -> None: pool_list = [p['pool_name'] for p in mgr.get_osdmap().dump().get('pools', [])] if POOL_NAME not in pool_list: - mgr.check_mon_command({'prefix': 'osd pool create', 'pool': POOL_NAME}) + mgr.check_mon_command({'prefix': 'osd pool create', + 'pool': POOL_NAME, + 'yes_i_really_mean_it': True}) mgr.check_mon_command({'prefix': 'osd pool application enable', 'pool': POOL_NAME, 'app': 'nfs'})