]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon/AuthMonitor: add `ceph auth rotate` command
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 18 Jun 2024 17:31:14 +0000 (13:31 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Wed, 30 Apr 2025 18:00:09 +0000 (14:00 -0400)
Add command to rotate the permanent key of an entity. This avoids the need to
delete / recreate the key when it is compromised, lost, or just scheduled for
rotation.

Fixes: https://tracker.ceph.com/issues/66509
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit d57326fce6d78e4b92e318ce933ca39bf8e8fcc4)

Conflicts:
    src/mon/AuthMonitor.cc: _encode_auth not in reef

src/mon/AuthMonitor.cc
src/mon/MonCommands.h

index 88627a81715388ed848efed2b5b164c599fd5e06..4a0a1e44640d0520d89b3716349fd2e138d19b13 100644 (file)
@@ -869,6 +869,7 @@ bool AuthMonitor::preprocess_command(MonOpRequestRef op)
   string prefix;
   cmd_getval(cmdmap, "prefix", prefix);
   if (prefix == "auth add" ||
+      prefix == "auth rotate" ||
       prefix == "auth del" ||
       prefix == "auth rm" ||
       prefix == "auth get-or-create" ||
@@ -1916,6 +1917,40 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
     wait_for_commit(op, new Monitor::C_Command(mon, op, 0, rs,
                                              get_last_committed() + 1));
     return true;
+  } else if (prefix == "auth rotate") {
+    if (entity_name.empty()) {
+      ss << "bad entity name";
+      err = -EINVAL;
+      goto done;
+    }
+
+    EntityAuth entity_auth;
+    if (!mon.key_server.get_auth(entity, entity_auth)) {
+      ss << "entity does not exist";
+      err = -ENOENT;
+      goto done;
+    }
+
+    entity_auth.key.create(g_ceph_context, CEPH_CRYPTO_AES);
+
+    KeyServerData::Incremental auth_inc;
+    auth_inc.op = KeyServerData::AUTH_INC_ADD;
+    auth_inc.name = entity;
+    auth_inc.auth = entity_auth;
+    push_cephx_inc(auth_inc);
+
+    {
+      KeyRing kr;
+      kr.add(entity, entity_auth);
+      if (f) {
+        kr.encode_formatted("auth", f.get(), rdata);
+      } else {
+        kr.encode_plaintext(rdata);
+      }
+    }
+    wait_for_commit(op, new Monitor::C_Command(mon, op, 0, rs, rdata,
+                                              get_last_committed() + 1));
+    return true;
   }
 done:
   rdata.append(ds);
index 662527de104408842e3c890be41fe54e03a5cdd3..527607ed2bd66f638d7461f2227ac339230d9a49 100644 (file)
@@ -163,6 +163,10 @@ COMMAND("auth add "
        "add auth info for <entity> from input file, or random key if no "
         "input is given, and/or any caps specified in the command",
        "auth", "rwx")
+COMMAND("auth rotate "
+       "name=entity,type=CephString",
+       "rotate entity key",
+       "auth", "rwx")
 COMMAND("auth get-or-create-key "
        "name=entity,type=CephString "
        "name=caps,type=CephString,n=N,req=false",