Skip to content

Commit

Permalink
messaging: Move encryption options parsing to ms
Browse files Browse the repository at this point in the history
Main collects a bunch of local variables from config and passes
them as arguments to messaging service initialization helper.
This patch replaces all these args with const config reference.

The motivation is to facilitate next patching by providing the
server encryption options k:v set right in the m.s. init code.

Signed-off-by: Pavel Emelyanov <[email protected]>
  • Loading branch information
xemul committed Aug 20, 2021
1 parent 33c70e5 commit 2f5941c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
18 changes: 1 addition & 17 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,6 @@ int main(int ac, char** av) {
dbcfg.gossip_scheduling_group = make_sched_group("gossip", 1000);
dbcfg.available_memory = memory::stats().total_memory();

const auto& ssl_opts = cfg->server_encryption_options();
auto encrypt_what = utils::get_or_default(ssl_opts, "internode_encryption", "none");
auto trust_store = utils::get_or_default(ssl_opts, "truststore");
auto cert = utils::get_or_default(ssl_opts, "certificate", db::config::get_conf_sub("scylla.crt").string());
auto key = utils::get_or_default(ssl_opts, "keyfile", db::config::get_conf_sub("scylla.key").string());
auto prio = utils::get_or_default(ssl_opts, "priority_string", sstring());
auto clauth = utils::is_true(utils::get_or_default(ssl_opts, "require_client_auth", "false"));

netw::messaging_service::config mscfg;

mscfg.ip = gms::inet_address::lookup(listen_address, family).get0();
Expand All @@ -798,14 +790,6 @@ int main(int ac, char** av) {
mscfg.listen_on_broadcast_address = cfg->listen_on_broadcast_address();
mscfg.rpc_memory_limit = std::max<size_t>(0.08 * memory::stats().total_memory(), mscfg.rpc_memory_limit);

if (encrypt_what == "all") {
mscfg.encrypt = netw::messaging_service::encrypt_what::all;
} else if (encrypt_what == "dc") {
mscfg.encrypt = netw::messaging_service::encrypt_what::dc;
} else if (encrypt_what == "rack") {
mscfg.encrypt = netw::messaging_service::encrypt_what::rack;
}

const auto& seo = cfg->server_encryption_options();
if (utils::is_true(utils::get_or_default(seo, "require_client_auth", "false"))) {
auto encrypt = utils::get_or_default(seo, "internode_encryption", "none");
Expand Down Expand Up @@ -849,7 +833,7 @@ int main(int ac, char** av) {
scfg.gossip = dbcfg.gossip_scheduling_group;

debug::the_messaging_service = &messaging;
netw::init_messaging_service(messaging, std::move(mscfg), std::move(scfg), trust_store, cert, key, prio, clauth);
netw::init_messaging_service(messaging, std::move(mscfg), std::move(scfg), *cfg);
auto stop_ms = defer_verbose_shutdown("messaging service", [&messaging] {
netw::uninit_messaging_service(messaging).get();
});
Expand Down
19 changes: 17 additions & 2 deletions message/messaging_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1559,11 +1559,26 @@ future<> messaging_service::send_raft_timeout_now(msg_addr id, clock_type::time_


void init_messaging_service(sharded<messaging_service>& ms,
messaging_service::config mscfg, netw::messaging_service::scheduling_config scfg,
sstring ms_trust_store, sstring ms_cert, sstring ms_key, sstring ms_tls_prio, bool ms_client_auth) {
messaging_service::config mscfg, netw::messaging_service::scheduling_config scfg, const db::config& db_config) {
using encrypt_what = messaging_service::encrypt_what;
using namespace seastar::tls;

const auto& ssl_opts = db_config.server_encryption_options();
auto encrypt = utils::get_or_default(ssl_opts, "internode_encryption", "none");
auto ms_trust_store = utils::get_or_default(ssl_opts, "truststore");
auto ms_cert = utils::get_or_default(ssl_opts, "certificate", db::config::get_conf_sub("scylla.crt").string());
auto ms_key = utils::get_or_default(ssl_opts, "keyfile", db::config::get_conf_sub("scylla.key").string());
auto ms_tls_prio = utils::get_or_default(ssl_opts, "priority_string", sstring());
auto ms_client_auth = utils::is_true(utils::get_or_default(ssl_opts, "require_client_auth", "false"));

if (encrypt == "all") {
mscfg.encrypt = encrypt_what::all;
} else if (encrypt == "dc") {
mscfg.encrypt = encrypt_what::dc;
} else if (encrypt == "rack") {
mscfg.encrypt = encrypt_what::rack;
}

std::shared_ptr<credentials_builder> creds;

if (mscfg.encrypt != encrypt_what::none) {
Expand Down
4 changes: 2 additions & 2 deletions message/messaging_service.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace utils {

namespace db {
class seed_provider_type;
class config;
}

namespace db::view {
Expand Down Expand Up @@ -596,8 +597,7 @@ public:
};

void init_messaging_service(sharded<messaging_service>& ms,
messaging_service::config cfg, messaging_service::scheduling_config scheduling_config,
sstring ms_trust_store, sstring ms_cert, sstring ms_key, sstring ms_tls_prio, bool ms_client_auth);
messaging_service::config cfg, messaging_service::scheduling_config scheduling_config, const db::config& db_config);
future<> uninit_messaging_service(sharded<messaging_service>& ms);

} // namespace netw

0 comments on commit 2f5941c

Please sign in to comment.