From: Vikhyat Umrao Date: Thu, 16 Feb 2017 18:21:11 +0000 (+0530) Subject: auth: 'ceph auth import -i' overwrites caps, if caps are not specified X-Git-Tag: v12.0.1~336^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=90144aa64c11a685b6a7cb3aafea75d427f569be;p=ceph.git auth: 'ceph auth import -i' overwrites caps, if caps are not specified in given keyring file, should alert user and should not allow this import. Because in 'ceph auth list' we keep all the keyrings with caps and importing 'client.admin' user keyring without caps locks the cluster with error[1] because admin keyring caps are missing in 'ceph auth'. [1] Error connecting to cluster: PermissionDeniedError Fixes: http://tracker.ceph.com/issues/18932 Signed-off-by: Vikhyat Umrao --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 2165f154ca3..804eaafdcc8 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -518,6 +518,9 @@ function test_auth() # local auid=444 ceph-authtool --create-keyring --name client.TEST --gen-key --set-uid $auid TEST-keyring + expect_false ceph auth import --in-file TEST-keyring + rm TEST-keyring + ceph-authtool --create-keyring --name client.TEST --gen-key --cap mon "allow r" --set-uid $auid TEST-keyring ceph auth import --in-file TEST-keyring rm TEST-keyring ceph auth get client.TEST > $TMPFILE diff --git a/src/mon/AuthMonitor.cc b/src/mon/AuthMonitor.cc index 93b73493823..7ff20371b06 100644 --- a/src/mon/AuthMonitor.cc +++ b/src/mon/AuthMonitor.cc @@ -647,11 +647,15 @@ void AuthMonitor::export_keyring(KeyRing& keyring) mon->key_server.export_keyring(keyring); } -void AuthMonitor::import_keyring(KeyRing& keyring) +int AuthMonitor::import_keyring(KeyRing& keyring) { for (map::iterator p = keyring.get_keys().begin(); p != keyring.get_keys().end(); ++p) { + if (p->second.caps.empty()) { + dout(0) << "import: no caps supplied" << dendl; + return -EINVAL; + } KeyServerData::Incremental auth_inc; auth_inc.name = p->first; auth_inc.auth = p->second; @@ -660,6 +664,7 @@ void AuthMonitor::import_keyring(KeyRing& keyring) dout(30) << " " << auth_inc.auth << dendl; push_cephx_inc(auth_inc); } + return 0; } bool AuthMonitor::prepare_command(MonOpRequestRef op) @@ -726,7 +731,13 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op) err = -EINVAL; goto done; } - import_keyring(keyring); + err = import_keyring(keyring); + if (err < 0) { + ss << "auth import: no caps supplied"; + getline(ss, rs); + mon->reply_command(op, -EINVAL, rs, get_last_committed()); + return true; + } ss << "imported keyring"; getline(ss, rs); err = 0; diff --git a/src/mon/AuthMonitor.h b/src/mon/AuthMonitor.h index f92697dcdd1..76e4dc85f21 100644 --- a/src/mon/AuthMonitor.h +++ b/src/mon/AuthMonitor.h @@ -112,7 +112,7 @@ private: void upgrade_format(); void export_keyring(KeyRing& keyring); - void import_keyring(KeyRing& keyring); + int import_keyring(KeyRing& keyring); void push_cephx_inc(KeyServerData::Incremental& auth_inc) { Incremental inc;