Skip to content

Commit 0efe88d

Browse files
committed
Merge PR ceph#58121 into main
* refs/pull/58121/head: doc: add documentation for `ceph auth rotate` PendingReleaseNotes: add note for new `auth rotate` qa: test `auth rotate` mon/AuthMonitor: add `ceph auth rotate` command Reviewed-by: Radoslaw Zarzynski <[email protected]>
2 parents 7b7a3ca + b871bbe commit 0efe88d

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

PendingReleaseNotes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
>=19.0.0
22

3+
* cephx: key rotation is now possible using `ceph auth rotate`. Previously,
4+
this was only possible by deleting and then recreating the key.
35
* ceph: a new --daemon-output-file switch is available for `ceph tell` commands
46
to dump output to a file local to the daemon. For commands which produce
57
large amounts of output, this avoids a potential spike in memory usage on the

doc/rados/operations/user-management.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,20 @@ You may also :ref:`Modify user capabilities<modify-user-capabilities>` directly
744744
results to a keyring file, and then import the keyring into your main
745745
``ceph.keyring`` file.
746746

747+
748+
Key rotation
749+
------------
750+
751+
To rotate the secret for an entity, use:
752+
753+
.. prompt:: bash #
754+
755+
ceph auth rotate <entity>
756+
757+
This avoids the need to delete and recreate the entity when its key is
758+
compromised, lost, or scheduled for rotation.
759+
760+
747761
Command Line Usage
748762
==================
749763

qa/workunits/cephtool/test.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,26 @@ function test_auth()
609609
ceph auth del client.xx
610610
expect_false ceph auth get client.xx
611611

612+
# test rotation
613+
ceph auth get-or-create client.admin2 mon 'allow *'
614+
ceph auth get client.admin2 >> keyring1
615+
env CEPH_KEYRING=keyring1 ceph -n client.admin2 auth get client.admin2 >> keyring2
616+
# they are the same:
617+
expect_true diff -au keyring1 keyring2
618+
# rotate itself
619+
env CEPH_KEYRING=keyring1 ceph -n client.admin2 auth rotate client.admin2 >> keyring3
620+
# only the key has changed:
621+
diff -au keyring1 keyring3 | grep -E '^[-+][^-+]' | expect_false grep -v key
622+
# the key in keyring1 no longer works:
623+
expect_false env CEPH_KEYRING=keyring1 ceph -n client.admin2 auth get client.admin2
624+
# the key in keyring3 should work:
625+
expect_true env CEPH_KEYRING=keyring3 ceph -n client.admin2 auth get client.admin2
626+
# now verify the key from `auth get` matches what rotate produced:
627+
expect_true ceph auth get client.admin2 >> keyring4
628+
expect_true diff -au keyring3 keyring4
629+
expect_true ceph auth rm client.admin2
630+
rm keyring[1234]
631+
612632
# (almost) interactive mode
613633
echo -e 'auth add client.xx mon "allow *" osd "allow *"\n' | ceph
614634
ceph auth get client.xx

src/mon/AuthMonitor.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ bool AuthMonitor::preprocess_command(MonOpRequestRef op)
858858
string prefix;
859859
cmd_getval(cmdmap, "prefix", prefix);
860860
if (prefix == "auth add" ||
861+
prefix == "auth rotate" ||
861862
prefix == "auth del" ||
862863
prefix == "auth rm" ||
863864
prefix == "auth get-or-create" ||
@@ -1825,6 +1826,32 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
18251826
wait_for_commit(op, new Monitor::C_Command(mon, op, 0, rs,
18261827
get_last_committed() + 1));
18271828
return true;
1829+
} else if (prefix == "auth rotate") {
1830+
if (entity_name.empty()) {
1831+
ss << "bad entity name";
1832+
err = -EINVAL;
1833+
goto done;
1834+
}
1835+
1836+
EntityAuth entity_auth;
1837+
if (!mon.key_server.get_auth(entity, entity_auth)) {
1838+
ss << "entity does not exist";
1839+
err = -ENOENT;
1840+
goto done;
1841+
}
1842+
1843+
entity_auth.key.create(g_ceph_context, CEPH_CRYPTO_AES);
1844+
1845+
KeyServerData::Incremental auth_inc;
1846+
auth_inc.op = KeyServerData::AUTH_INC_ADD;
1847+
auth_inc.name = entity;
1848+
auth_inc.auth = entity_auth;
1849+
push_cephx_inc(auth_inc);
1850+
1851+
_encode_auth(entity, entity_auth, rdata, f.get());
1852+
wait_for_commit(op, new Monitor::C_Command(mon, op, 0, rs, rdata,
1853+
get_last_committed() + 1));
1854+
return true;
18281855
}
18291856
done:
18301857
rdata.append(ds);

src/mon/MonCommands.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ COMMAND("auth add "
163163
"add auth info for <entity> from input file, or random key if no "
164164
"input is given, and/or any caps specified in the command",
165165
"auth", "rwx")
166+
COMMAND("auth rotate "
167+
"name=entity,type=CephString",
168+
"rotate entity key",
169+
"auth", "rwx")
166170
COMMAND("auth get-or-create-key "
167171
"name=entity,type=CephString "
168172
"name=caps,type=CephString,n=N,req=false",

0 commit comments

Comments
 (0)