From: Yehuda Sadeh Date: Tue, 18 Feb 2020 02:18:47 +0000 (-0800) Subject: rgw: beast ssl: enable use of meta variable for cert config X-Git-Tag: v15.1.1~123^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=63c1428966bbbf31521b02edd25fe771aa4c8227;p=ceph.git rgw: beast ssl: enable use of meta variable for cert config Add the following variables: $realm, $realm_id, $zonegroup, $zonegroup_id, $zone, $zone_id Variables can also be passed in with curly braces, e.g., ${realm} Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_asio_frontend.cc b/src/rgw/rgw_asio_frontend.cc index 2118a2ce54ce..6855a18c403b 100644 --- a/src/rgw/rgw_asio_frontend.cc +++ b/src/rgw/rgw_asio_frontend.cc @@ -22,6 +22,10 @@ #include #include "services/svc_config_key.h" +#include "services/svc_zone.h" + +#include "rgw_zone.h" + #endif #include "rgw_dmclock_async_scheduler.h" @@ -512,6 +516,83 @@ int AsioFrontend::init() static string config_val_prefix = "config://"; +namespace { + +class ExpandMetaVar { + map meta_map; + +public: + ExpandMetaVar(RGWSI_Zone *zone_svc) { + meta_map["realm"] = zone_svc->get_realm().get_name(); + meta_map["realm_id"] = zone_svc->get_realm().get_id(); + meta_map["zonegroup"] = zone_svc->get_zonegroup().get_name(); + meta_map["zonegroup_id"] = zone_svc->get_zonegroup().get_id(); + meta_map["zone"] = zone_svc->zone_name(); + meta_map["zone_id"] = zone_svc->zone_id().id; + } + + string process_str(const string& in); +}; + +string ExpandMetaVar::process_str(const string& in) +{ + if (meta_map.empty()) { + return in; + } + + auto pos = in.find('$'); + if (pos == std::string::npos) { + return in; + } + + string out; + decltype(pos) last_pos = 0; + + while (pos != std::string::npos) { + if (pos > last_pos) { + out += in.substr(last_pos, pos - last_pos); + } + + string var; + const char *valid_chars = "abcdefghijklmnopqrstuvwxyz_"; + + size_t endpos = 0; + if (in[pos+1] == '{') { + // ...${foo_bar}... + endpos = in.find_first_not_of(valid_chars, pos + 2); + if (endpos != std::string::npos && + in[endpos] == '}') { + var = in.substr(pos + 2, endpos - pos - 2); + endpos++; + } + } else { + // ...$foo... + endpos = in.find_first_not_of(valid_chars, pos + 1); + if (endpos != std::string::npos) + var = in.substr(pos + 1, endpos - pos - 1); + else + var = in.substr(pos + 1); + } + string var_source = in.substr(pos, endpos - pos); + last_pos = endpos; + + auto iter = meta_map.find(var); + if (iter != meta_map.end()) { + out += iter->second; + } else { + out += var_source; + } + pos = in.find('$', last_pos); + } + if (last_pos != std::string::npos) { + out += in.substr(last_pos); + } + + return out; +} + +} /* anonymous namespace */ + int AsioFrontend::get_config_key_val(string name, const string& type, bufferlist *pbl) @@ -617,6 +698,11 @@ int AsioFrontend::init_ssl() key_is_cert = true; } + ExpandMetaVar emv(env.store->svc()->zone); + + cert = emv.process_str(*cert); + key = emv.process_str(*key); + int r = ssl_set_private_key(*key, key_is_cert); bool have_private_key = (r >= 0); if (r < 0) {