]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
auth: 'ceph auth import -i' overwrites caps, if caps are not specified
authorVikhyat Umrao <vumrao@redhat.com>
Thu, 16 Feb 2017 18:21:11 +0000 (23:51 +0530)
committerVikhyat Umrao <vumrao@redhat.com>
Sun, 19 Feb 2017 22:18:31 +0000 (03:48 +0530)
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 <vumrao@redhat.com>
qa/workunits/cephtool/test.sh
src/mon/AuthMonitor.cc
src/mon/AuthMonitor.h

index 2165f154ca392d2c495b2dbbc68a35d926edff84..804eaafdcc80bb785f13c25556313b044e0a4961 100755 (executable)
@@ -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
index 93b7349382332b7b907a667c8c57b451c18e3ef3..7ff20371b0616a9e6e90023a19a1753e861e1f42 100644 (file)
@@ -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<EntityName, EntityAuth>::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;
index f92697dcdd1f502492c61c488ce8898821a6bbd4..76e4dc85f216da1963788cb9a152a7d6feb98981 100644 (file)
@@ -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;