Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ceph-dencoder: COMMON - Add missing types #52210

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/auth/Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define CEPH_AUTHTYPES_H

#include "Crypto.h"
#include "common/ceph_json.h"
#include "common/entity_name.h"

// The _MAX values are a bit wonky here because we are overloading the first
Expand Down Expand Up @@ -59,6 +60,14 @@ struct EntityAuth {
decode(pending_key, bl);
}
}
void dump(ceph::Formatter *f) const {
f->dump_object("key", key);
encode_json("caps", caps, f);
f->dump_object("pending_key", pending_key);
}
static void generate_test_instances(std::list<EntityAuth*>& ls) {
ls.push_back(new EntityAuth);
}
};
WRITE_CLASS_ENCODER(EntityAuth)

Expand Down Expand Up @@ -95,6 +104,19 @@ struct AuthCapsInfo {
allow_all = (bool)a;
decode(caps, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_bool("allow_all", allow_all);
encode_json("caps", caps, f);
f->dump_unsigned("caps_len", caps.length());
}
static void generate_test_instances(std::list<AuthCapsInfo*>& ls) {
ls.push_back(new AuthCapsInfo);
ls.push_back(new AuthCapsInfo);
ls.back()->allow_all = true;
ls.push_back(new AuthCapsInfo);
ls.back()->caps.append("foo");
ls.back()->caps.append("bar");
}
};
WRITE_CLASS_ENCODER(AuthCapsInfo)

Expand Down Expand Up @@ -147,6 +169,25 @@ struct AuthTicket {
decode(caps, bl);
decode(flags, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_object("name", name);
f->dump_unsigned("global_id", global_id);
f->dump_stream("created") << created;
f->dump_stream("renew_after") << renew_after;
f->dump_stream("expires") << expires;
f->dump_object("caps", caps);
f->dump_unsigned("flags", flags);
}
static void generate_test_instances(std::list<AuthTicket*>& ls) {
ls.push_back(new AuthTicket);
ls.push_back(new AuthTicket);
ls.back()->name.set_id("client.123");
ls.back()->global_id = 123;
ls.back()->init_timestamps(utime_t(123, 456), 7);
ls.back()->caps.caps.append("foo");
ls.back()->caps.caps.append("bar");
ls.back()->flags = 0x12345678;
}
};
WRITE_CLASS_ENCODER(AuthTicket)

Expand Down Expand Up @@ -231,6 +272,16 @@ struct ExpiringCryptoKey {
decode(key, bl);
decode(expiration, bl);
}
void dump(ceph::Formatter *f) const {
f->dump_object("key", key);
f->dump_stream("expiration") << expiration;
}
static void generate_test_instances(std::list<ExpiringCryptoKey*>& ls) {
ls.push_back(new ExpiringCryptoKey);
ls.push_back(new ExpiringCryptoKey);
ls.back()->key.set_secret(
CEPH_CRYPTO_AES, bufferptr("1234567890123456", 16), utime_t(123, 456));
}
};
WRITE_CLASS_ENCODER(ExpiringCryptoKey)

Expand Down Expand Up @@ -295,6 +346,15 @@ struct RotatingSecrets {
}

void dump();
void dump(ceph::Formatter *f) const {
encode_json("secrets", secrets, f);
}
static void generate_test_instances(std::list<RotatingSecrets*>& ls) {
ls.push_back(new RotatingSecrets);
ls.push_back(new RotatingSecrets);
auto eck = new ExpiringCryptoKey;
ls.back()->add(*eck);
}
};
WRITE_CLASS_ENCODER(RotatingSecrets)

Expand Down
17 changes: 17 additions & 0 deletions src/auth/Crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,23 @@ void CryptoKey::decode(bufferlist::const_iterator& bl)
throw ceph::buffer::malformed_input("malformed secret");
}

void CryptoKey::dump(Formatter *f) const
{
f->dump_int("type", type);
f->dump_stream("created") << created;
f->dump_int("secret.length", secret.length());
}

void CryptoKey::generate_test_instances(std::list<CryptoKey*>& ls)
{
ls.push_back(new CryptoKey);
ls.push_back(new CryptoKey);
ls.back()->type = CEPH_CRYPTO_AES;
ls.back()->set_secret(
CEPH_CRYPTO_AES, bufferptr("1234567890123456", 16), utime_t(123, 456));
ls.back()->created = utime_t(123, 456);
}

int CryptoKey::set_secret(int type, const bufferptr& s, utime_t c)
{
int r = _set_secret(type, s);
Expand Down
2 changes: 2 additions & 0 deletions src/auth/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class CryptoKey {

void encode(ceph::buffer::list& bl) const;
void decode(ceph::buffer::list::const_iterator& bl);
void dump(ceph::Formatter *f) const;
static void generate_test_instances(std::list<CryptoKey*>& ls);

void clear() {
*this = CryptoKey();
Expand Down
10 changes: 10 additions & 0 deletions src/auth/cephx/CephxKeyServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ std::map<EntityName,CryptoKey> KeyServer::get_used_pending_keys()
return ret;
}

void KeyServer::dump(Formatter *f) const
{
f->dump_object("data", data);
}

void KeyServer::generate_test_instances(std::list<KeyServer*>& ls)
{
ls.push_back(new KeyServer(nullptr, nullptr));
}

bool KeyServer::generate_secret(CryptoKey& secret)
{
bufferptr bp;
Expand Down
40 changes: 33 additions & 7 deletions src/auth/cephx/CephxKeyServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
#include "include/common_fwd.h"

struct KeyServerData {
version_t version;
version_t version{0};

/* for each entity */
std::map<EntityName, EntityAuth> secrets;
KeyRing *extra_secrets;
KeyRing *extra_secrets = nullptr;

/* for each service type */
version_t rotating_ver;
version_t rotating_ver{0};
std::map<uint32_t, RotatingSecrets> rotating_secrets;
KeyServerData() {}

explicit KeyServerData(KeyRing *extra)
: version(0),
Expand Down Expand Up @@ -70,7 +71,17 @@ struct KeyServerData {
decode(rotating_ver, iter);
decode(rotating_secrets, iter);
}

void dump(ceph::Formatter *f) const {
f->dump_unsigned("version", version);
f->dump_unsigned("rotating_version", rotating_ver);
encode_json("secrets", secrets, f);
encode_json("rotating_secrets", rotating_secrets, f);
}
static void generate_test_instances(std::list<KeyServerData*>& ls) {
ls.push_back(new KeyServerData);
ls.push_back(new KeyServerData);
ls.back()->version = 1;
}
bool contains(const EntityName& name) const {
return (secrets.find(name) != secrets.end());
}
Expand Down Expand Up @@ -159,8 +170,21 @@ struct KeyServerData {
decode(auth, bl);
}
}
void dump(ceph::Formatter *f) const {
f->dump_unsigned("op", op);
f->dump_object("name", name);
f->dump_object("auth", auth);
}
static void generate_test_instances(std::list<Incremental*>& ls) {
ls.push_back(new Incremental);
ls.back()->op = AUTH_INC_DEL;
ls.push_back(new Incremental);
ls.back()->op = AUTH_INC_ADD;
ls.push_back(new Incremental);
ls.back()->op = AUTH_INC_SET_ROTATING;
}
};

void apply_incremental(Incremental& inc) {
switch (inc.op) {
case AUTH_INC_ADD:
Expand Down Expand Up @@ -188,8 +212,6 @@ WRITE_CLASS_ENCODER(KeyServerData)
WRITE_CLASS_ENCODER(KeyServerData::Incremental)




class KeyServer : public KeyStore {
CephContext *cct;
KeyServerData data;
Expand All @@ -205,7 +227,9 @@ class KeyServer : public KeyStore {
bool _get_service_caps(const EntityName& name, uint32_t service_id,
AuthCapsInfo& caps) const;
public:
KeyServer() : lock{ceph::make_mutex("KeyServer::lock")} {}
KeyServer(CephContext *cct_, KeyRing *extra_secrets);
KeyServer& operator=(const KeyServer&) = delete;
bool generate_secret(CryptoKey& secret);

bool get_secret(const EntityName& name, CryptoKey& secret) const override;
Expand Down Expand Up @@ -248,6 +272,8 @@ class KeyServer : public KeyStore {
using ceph::decode;
decode(data, bl);
}
void dump(ceph::Formatter *f) const;
static void generate_test_instances(std::list<KeyServer*>& ls);
bool contains(const EntityName& name) const;
int encode_secrets(ceph::Formatter *f, std::stringstream *ds) const;
void encode_formatted(std::string label, ceph::Formatter *f, ceph::buffer::list &bl);
Expand Down