From: Patrick Donnelly Date: Tue, 18 Jun 2024 17:31:14 +0000 (-0400) Subject: mon/AuthMonitor: add `ceph auth rotate` command X-Git-Tag: v19.2.3~81^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f7b279bf23caf2d45927cf17f18090b0e26fc9b8;p=ceph.git mon/AuthMonitor: add `ceph auth rotate` command 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 (cherry picked from commit d57326fce6d78e4b92e318ce933ca39bf8e8fcc4) --- diff --git a/src/mon/AuthMonitor.cc b/src/mon/AuthMonitor.cc index b20eac8399ed..0a60ab6d26dd 100644 --- a/src/mon/AuthMonitor.cc +++ b/src/mon/AuthMonitor.cc @@ -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); diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 3c161dd3b2c0..81681a14b00c 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -163,6 +163,10 @@ COMMAND("auth add " "add auth info for 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",