From 9118b08365b24c3fe26f3dcdc4bf88d8ccbcbce0 Mon Sep 17 00:00:00 2001 From: Daniel Pivonka Date: Wed, 10 Mar 2021 18:01:35 -0500 Subject: [PATCH] cephadm: validate fsid during cephadm shell command Signed-off-by: Daniel Pivonka --- src/cephadm/cephadm | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 81f876d689fcf..2b5072ed3dc8a 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -2217,14 +2217,20 @@ def get_config_and_keyring(ctx): keyring = d.get('keyring') if 'config' in ctx and ctx.config: - with open(ctx.config, 'r') as f: - config = f.read() + try: + with open(ctx.config, 'r') as f: + config = f.read() + except FileNotFoundError: + raise Error('config file: %s does not exist' % ctx.config) if 'key' in ctx and ctx.key: keyring = '[%s]\n\tkey = %s\n' % (ctx.name, ctx.key) elif 'keyring' in ctx and ctx.keyring: - with open(ctx.keyring, 'r') as f: - keyring = f.read() + try: + with open(ctx.keyring, 'r') as f: + keyring = f.read() + except FileNotFoundError: + raise Error('keyring file: %s does not exist' % ctx.keyring) return config, keyring @@ -4232,11 +4238,25 @@ def command_run(ctx): ################################## +def fsid_conf_mismatch(ctx): + # type: (CephadmContext) -> bool + (config, _) = get_config_and_keyring(ctx) + if config: + for c in config.split('\n'): + if 'fsid = ' in c.strip(): + if 'fsid = ' + ctx.fsid != c.strip(): + return True + return False + + @infer_fsid @infer_config @infer_image def command_shell(ctx): # type: (CephadmContext) -> int + if fsid_conf_mismatch(ctx): + raise Error('fsid does not match ceph conf') + if ctx.fsid: make_log_dir(ctx, ctx.fsid) if ctx.name: -- 2.47.3