]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon: provide emergency mechanism to use mon keyring
authorPatrick Donnelly <pdonnell@ibm.com>
Thu, 29 May 2025 15:04:00 +0000 (11:04 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Wed, 1 Oct 2025 18:47:09 +0000 (14:47 -0400)
If they key is lost for the `mon.` credential, it's very inconvenient to get it
out of the "auth" database in the mon store. So, allow the operator to create a
new keyring for the mons and use it instead to get mons in quorum again.

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
doc/man/8/ceph-mon.rst
src/ceph_mon.cc
src/mon/Monitor.cc
src/mon/Monitor.h

index 640c842d605af22ccc8f8ac8d31aac5071836dd8..0166236438e1ee6a0dff42dc7d5c2904ae17ae42 100644 (file)
@@ -77,6 +77,11 @@ Options
 
    Specify a keyring for use with ``--mkfs``.
 
+.. option:: --use-mon-keyring
+
+   Use the mon's keyring file as authoritative for the "mon." secret. Normally
+   the key in the mons' auth database is used.
+
 .. option:: --no-config-file
 
     Signal that we don't want to rely on a *ceph.conf*, either user provided
index e2c261d477ece81a2849b0cad968e551e1f7c331..b30085585cff6098173ed579fea6766294c23382 100644 (file)
@@ -219,6 +219,8 @@ static void usage()
        << "        write the <filename> monmap to the local monitor store and exit\n"
        << "  --extract-monmap <filename>\n"
        << "        extract the monmap from the local monitor store and exit\n"
+       << "  --use-mon-keyring\n"
+       << "        use the mon keyring as authoritative for the mon. secret\n"
        << "  --mon-data <directory>\n"
        << "        where the mon store and keyring are located\n"
        << "  --set-crush-location <bucket>=<foo>"
@@ -262,6 +264,7 @@ int main(int argc, const char **argv)
   bool compact = false;
   bool force_sync = false;
   bool yes_really = false;
+  bool use_mon_keyring = false;
   std::string osdmapfn, inject_monmap, extract_monmap, crush_loc;
 
   auto args = argv_to_vec(argc, argv);
@@ -327,6 +330,8 @@ int main(int argc, const char **argv)
       force_sync = true;
     } else if (ceph_argparse_flag(args, i, "--yes-i-really-mean-it", (char*)NULL)) {
       yes_really = true;
+    } else if (ceph_argparse_flag(args, i, "--use-mon-keyring", (char*)NULL)) {
+      use_mon_keyring = true;
     } else if (ceph_argparse_witharg(args, i, &val, "--osdmap", (char*)NULL)) {
       osdmapfn = val;
     } else if (ceph_argparse_witharg(args, i, &val, "--inject_monmap", (char*)NULL)) {
@@ -863,6 +868,10 @@ int main(int argc, const char **argv)
     *_dout << dendl;
   }
 
+  if (use_mon_keyring) {
+    mon->use_keyring_as_authoritative();
+  }
+
   err = mon->preinit();
   if (err < 0) {
     derr << "failed to initialize" << dendl;
index 745af40f86dc8ddd002d9c6721b6ffcfd04f3cc4..654383ee33fa6fc1017049485b217b8a732443a1 100644 (file)
@@ -6497,7 +6497,7 @@ int Monitor::handle_auth_request(
     dout(20) << __func__ << ": verify authorizer was_challenge=" << was_challenge << dendl;
     bool isvalid = ah->verify_authorizer(
       cct,
-      key_server,
+      use_mon_keyring ? static_cast<KeyStore&>(keyring) : static_cast<KeyStore&>(key_server),
       payload,
       auth_meta->get_connection_secret_length(),
       reply,
index 4f54c729efe8b022413f51a9d19cd7fb1558b3ee..716a05abfd6ed6b83890c2188ba3174602aed17f 100644 (file)
@@ -1130,6 +1130,13 @@ public:
     return std::chrono::duration_cast<std::chrono::milliseconds>(now-starttime);
   }
 
+private:
+  bool use_mon_keyring = false;
+public:
+  void use_keyring_as_authoritative() {
+    use_mon_keyring = true;
+  }
+
 private:
   ceph::coarse_mono_time const starttime = coarse_mono_clock::now();
   epoch_t probe_epoch = 0;