From: Michael Fritch Date: Mon, 26 Jul 2021 22:58:54 +0000 (-0600) Subject: cephadm: validate fsid during shell command X-Git-Tag: v16.2.6~54^2~26 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=69861d89916b402780ce69de2a2e9e5149bc856e;p=ceph.git cephadm: validate fsid during shell command Signed-off-by: Michael Fritch (cherry picked from commit 25febfd9e081eaa275faa786102d59522ddba405) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 48b94acf58c4..5f0fa84eb56d 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1642,6 +1642,16 @@ def is_fsid(s): return True +def validate_fsid(func): + @wraps(func) + def _validate_fsid(ctx: CephadmContext): + if 'fsid' in ctx and ctx.fsid: + if not is_fsid(ctx.fsid): + raise Error('not an fsid: %s' % ctx.fsid) + return func(ctx) + return _validate_fsid + + def infer_fsid(func): """ If we only find a single fsid in /var/lib/ceph/*, use that @@ -1649,7 +1659,7 @@ def infer_fsid(func): @infer_config @wraps(func) def _infer_fsid(ctx: CephadmContext): - if ctx.fsid: + if 'fsid' in ctx and ctx.fsid: logger.debug('Using specified fsid: %s' % ctx.fsid) return func(ctx) @@ -1695,7 +1705,7 @@ def infer_config(func): if ctx.config: logger.debug('Using specified config: %s' % ctx.config) return func(ctx) - if ctx.fsid: + if 'fsid' in ctx and ctx.fsid: name = ctx.name if 'name' in ctx else None if not name: daemon_list = list_daemons(ctx, detail=False) @@ -4474,6 +4484,7 @@ def command_run(ctx): @infer_fsid @infer_config @infer_image +@validate_fsid def command_shell(ctx): # type: (CephadmContext) -> int cp = read_config(ctx.config) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 37e276c207a0..6993214ac072 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1415,6 +1415,14 @@ class TestShell(object): assert retval == 0 assert ctx.fsid == fsid + cmd = ['shell', '--fsid', '00000000-0000-0000-0000-0000deadbeez'] + with with_cephadm_ctx(cmd) as ctx: + err = 'not an fsid' + with pytest.raises(cd.Error, match=err): + retval = cd.command_shell(ctx) + assert retval == 1 + assert ctx.fsid == None + s = get_ceph_conf(fsid=fsid) f = cephadm_fs.create_file('ceph.conf', contents=s)