]> git.apps.os.sepia.ceph.com Git - ceph.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@redhat.com>
Fri, 21 Jun 2024 01:31:12 +0000 (21:31 -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>
src/mon/AuthMonitor.cc
src/mon/MonCommands.h

index b20eac8399ed25b9ceede7e83d1f40058dbc12d7..0a60ab6d26dd3062003490b34fca6112759e4334 100644 (file)
@@ -858,6 +858,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" ||
@@ -1825,6 +1826,32 @@ 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);
+
+    _encode_auth(entity, entity_auth, rdata, f.get());
+    wait_for_commit(op, new Monitor::C_Command(mon, op, 0, rs, rdata,
+                                              get_last_committed() + 1));
+    return true;
   }
 done:
   rdata.append(ds);
index b2a678dff53c53bf3b07f9d8597403a14fb46ec4..ff03e6549edbeaa3b0937c1c04344eab5c5352ce 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",