]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
auth: add PendingKey to EntityAuth
authorSage Weil <sage@newdream.net>
Fri, 22 Oct 2021 16:38:20 +0000 (11:38 -0500)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 12 Sep 2022 17:02:53 +0000 (17:02 +0000)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/auth/Auth.h
src/auth/KeyRing.cc

index 845f56c9bd662424e39bdf952846308994c244ec..5521c8d3fcf0e719796846876205fcb73e6c9468 100644 (file)
@@ -34,14 +34,16 @@ enum {
 struct EntityAuth {
   CryptoKey key;
   std::map<std::string, ceph::buffer::list> caps;
+  CryptoKey pending_key; ///< new but uncommitted key
 
   void encode(ceph::buffer::list& bl) const {
-    __u8 struct_v = 2;
+    __u8 struct_v = 3;
     using ceph::encode;
     encode(struct_v, bl);
     encode((uint64_t)CEPH_AUTH_UID_DEFAULT, bl);
     encode(key, bl);
     encode(caps, bl);
+    encode(pending_key, bl);
   }
   void decode(ceph::buffer::list::const_iterator& bl) {
     using ceph::decode;
@@ -53,12 +55,21 @@ struct EntityAuth {
     }
     decode(key, bl);
     decode(caps, bl);
+    if (struct_v >= 3) {
+      decode(pending_key, bl);
+    }
   }
 };
 WRITE_CLASS_ENCODER(EntityAuth)
 
-inline std::ostream& operator<<(std::ostream& out, const EntityAuth& a) {
-  return out << "auth(key=" << a.key << ")";
+inline std::ostream& operator<<(std::ostream& out, const EntityAuth& a)
+{
+  out << "auth(key=" << a.key;
+  if (!a.pending_key.empty()) {
+    out << " pending_key=" << a.pending_key;
+  }
+  out << ")";
+  return out;
 }
 
 struct AuthCapsInfo {
index 0b28ff6106393fc8493759f6ece37f60e157cc55..eca429d0bd0489fcef351dd71eb2259f3ae2e217 100644 (file)
@@ -19,6 +19,7 @@
 #include <algorithm>
 #include <boost/algorithm/string/replace.hpp>
 #include "auth/KeyRing.h"
+#include "include/stringify.h"
 #include "common/ceph_context.h"
 #include "common/config.h"
 #include "common/debug.h"
@@ -136,24 +137,19 @@ void KeyRing::encode_plaintext(bufferlist& bl)
 void KeyRing::encode_formatted(string label, Formatter *f, bufferlist& bl)
 {
   f->open_array_section(label.c_str());
-  for (map<EntityName, EntityAuth>::iterator p = keys.begin();
-       p != keys.end();
-       ++p) {
-
+  for (const auto &[ename, eauth] : keys) {
     f->open_object_section("auth_entities");
-    f->dump_string("entity", p->first.to_str().c_str());
-    std::ostringstream keyss;
-    keyss << p->second.key;
-    f->dump_string("key", keyss.str());
+    f->dump_string("entity", ename.to_str().c_str());
+    f->dump_string("key", stringify(eauth.key));
+    if (!eauth.pending_key.empty()) {
+      f->dump_string("pending_key", stringify(eauth.pending_key));
+    }
     f->open_object_section("caps");
-    for (map<string, bufferlist>::iterator q = p->second.caps.begin();
-        q != p->second.caps.end();
-        ++q) {
-      auto dataiter = q->second.cbegin();
+    for (auto& [sys, capsbl] : eauth.caps) {
+      auto dataiter = capsbl.cbegin();
       string caps;
-      using ceph::decode;
-      decode(caps, dataiter);
-      f->dump_string(q->first.c_str(), caps);
+      ceph::decode(caps, dataiter);
+      f->dump_string(sys.c_str(), caps);
     }
     f->close_section();        /* caps */
     f->close_section();        /* auth_entities */
@@ -229,21 +225,19 @@ int KeyRing::load(CephContext *cct, const std::string &filename)
 
 void KeyRing::print(ostream& out)
 {
-  for (map<EntityName, EntityAuth>::iterator p = keys.begin();
-       p != keys.end();
-       ++p) {
-    out << "[" << p->first << "]" << std::endl;
-    out << "\tkey = " << p->second.key << std::endl;
+  for (auto& [ename, eauth] : keys) {
+    out << "[" << ename << "]" << std::endl;
+    out << "\tkey = " << eauth.key << std::endl;
+    if (!eauth.pending_key.empty()) {
+      out << "\tpending key = " << eauth.pending_key << std::endl;
+    }
 
-    for (map<string, bufferlist>::iterator q = p->second.caps.begin();
-        q != p->second.caps.end();
-        ++q) {
-      auto dataiter = q->second.cbegin();
+    for (auto& [sys, capbl] : eauth.caps) {
+      auto dataiter = capbl.cbegin();
       string caps;
-      using ceph::decode;
-      decode(caps, dataiter);
+      ceph::decode(caps, dataiter);
       boost::replace_all(caps, "\"", "\\\"");
-      out << "\tcaps " << q->first << " = \"" << caps << '"' << std::endl;
+      out << "\tcaps " << sys << " = \"" << caps << '"' << std::endl;
     }
   }
 }