]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
auth: improve programmability of key dumps
authorPatrick Donnelly <pdonnell@ibm.com>
Mon, 7 Jul 2025 18:55:57 +0000 (14:55 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Mon, 5 Jan 2026 21:23:35 +0000 (16:23 -0500)
Notably:

- improve names (avoid repeated "keys")
- output type_str

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
src/auth/Auth.h
src/auth/Crypto.cc
src/auth/cephx/CephxKeyServer.h

index e30c890676752433bd9c375a69ddf16cfb0d8b6e..bfc9635c4437bcd8592ab64529170e49dc007595 100644 (file)
@@ -81,8 +81,15 @@ struct EntityAuth {
   }
   void dump(ceph::Formatter *f) const {
     f->dump_object("key", key);
-    encode_json("caps", caps, f);
     f->dump_object("pending_key", pending_key);
+    f->open_array_section("caps");
+    for (auto const& [entity, cap] : caps) {
+      f->open_object_section("cap");
+      f->dump_string("service_name", entity);
+      f->dump_string("access_spec", cap.to_str());
+      f->close_section();
+    }
+    f->close_section();
   }
   static std::list<EntityAuth> generate_test_instances() {
     std::list<EntityAuth> ls;
@@ -362,7 +369,15 @@ struct RotatingSecrets {
 
   void dump();
   void dump(ceph::Formatter *f) const {
-    encode_json("secrets", secrets, f);
+    f->dump_int("max_ver", max_ver);
+    f->open_array_section("keys");
+    for (const auto& [id, key] : secrets) {
+      f->open_object_section("secret");
+      f->dump_int("id", id);
+      f->dump_object("expiring_key", key);
+      f->close_section();
+    }
+    f->close_section();
   }
   static std::list<RotatingSecrets> generate_test_instances() {
     std::list<RotatingSecrets> ls;
index da21fdad48dc6d1bce56171263a4e6464960eaf9..5a4f73b57a78042f75e9cbab41df9e57adaf6f61 100644 (file)
  * 
  */
 
-#include <array>
-#include <sstream>
-#include <limits>
-#include <fcntl.h>
-
-#include <openssl/aes.h>
-#include <openssl/core_names.h>
 
 #include "Crypto.h"
 
 #include "include/ceph_assert.h"
+#include "include/ceph_fs.h"
+#include "include/compat.h"
+
 #include "common/Clock.h"
+#include "common/Formatter.h"
 #include "common/armor.h"
 #include "common/ceph_context.h"
 #include "common/ceph_crypto.h"
+#include "common/debug.h"
 #include "common/hex.h"
 #include "common/safe_io.h"
 #include "include/ceph_fs.h"
 #include <errno.h>
 
 #include <boost/endian/conversion.hpp>
+#include <openssl/aes.h>
+#include <openssl/core_names.h>
+
+#include <array>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits>
+#include <sstream>
 
 #define dout_subsys ceph_subsys_auth
 
@@ -995,8 +1001,8 @@ void CryptoKey::decode(bufferlist::const_iterator& bl)
 void CryptoKey::dump(Formatter *f) const
 {
   f->dump_int("type", type);
+  f->dump_string("type_str", CryptoManager::get_key_type_name(type));
   f->dump_stream("created") << created;
-  f->dump_int("secret.length", secret.length());
 }
 
 std::list<CryptoKey> CryptoKey::generate_test_instances()
index 4ee769ce7ec466191814f3d2a301a9e22f2db277..a4ea05e45a846df48c157af409d006ed8f5629d1 100644 (file)
@@ -84,8 +84,23 @@ struct KeyServerData {
   void dump(ceph::Formatter *f) const {
     f->dump_unsigned("version", version);
     f->dump_unsigned("rotating_version", rotating_ver);
-    encode_json("secrets", secrets, f);
-    encode_json("rotating_secrets", rotating_secrets, f);
+    f->open_array_section("secrets");
+    for (auto const& [name, auth] : secrets) {
+      f->open_object_section("secret");
+      f->dump_object("entity", name);
+      f->dump_object("auth", auth);
+      f->close_section();
+    }
+    f->close_section();
+    f->open_array_section("rotating_secrets");
+    for (auto const& [entity_type, secrets] : rotating_secrets) {
+      f->open_object_section("rotating_secret");
+      auto name = EntityName(entity_type);
+      f->dump_object("entity", name);
+      f->dump_object("secrets", secrets);
+      f->close_section();
+    }
+    f->close_section();
   }
   static std::list<KeyServerData> generate_test_instances() {
     std::list<KeyServerData> ls;