From: Jason Dillaman Date: Tue, 22 Dec 2020 18:34:51 +0000 (-0500) Subject: librbd: helper utility to retrieve config from the MON config store X-Git-Tag: v17.0.0~181^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9eb47021b8f72274ce27898e2b32afec28e90175;p=ceph.git librbd: helper utility to retrieve config from the MON config store A special "config://" URI prefix can be used to denote configuration settings that should be (securely) pulled from the MON config store. This will be first used in a follow-up commit to support storing the S3 access and secret keys in the MON config store. This "config://" syntax is already in-use by RGW and ceph-iscsi for pulling secrets when deployed via cephadm. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/Utils.cc b/src/librbd/Utils.cc index af2b165579700..dadf6ab8126ae 100644 --- a/src/librbd/Utils.cc +++ b/src/librbd/Utils.cc @@ -11,9 +11,11 @@ #include "include/neorados/RADOS.hpp" #include "include/rbd/features.h" #include "common/dout.h" +#include "common/errno.h" #include "librbd/ImageCtx.h" #include "librbd/Features.h" +#include #include #include @@ -23,6 +25,11 @@ namespace librbd { namespace util { +namespace { + +const std::string CONFIG_KEY_URI_PREFIX{"config://"}; + +} // anonymous namespace const std::string group_header_name(const std::string &group_id) { @@ -200,5 +207,37 @@ uint64_t reserve_async_request_id() { return ++async_request_seq; } +bool is_config_key_uri(const std::string& uri) { + return boost::starts_with(uri, CONFIG_KEY_URI_PREFIX); +} + +int get_config_key(librados::Rados& rados, const std::string& uri, + std::string* value) { + auto cct = reinterpret_cast(rados.cct()); + + if (!is_config_key_uri(uri)) { + return -EINVAL; + } + + std::string key = uri.substr(CONFIG_KEY_URI_PREFIX.size()); + std::string cmd = + "{" + "\"prefix\": \"config-key get\", " + "\"key\": \"" + key + "\"" + "}"; + + bufferlist in_bl; + bufferlist out_bl; + int r = rados.mon_command(cmd, in_bl, &out_bl, nullptr); + if (r < 0) { + lderr(cct) << "failed to retrieve MON config key " << key << ": " + << cpp_strerror(r) << dendl; + return r; + } + + *value = std::string(out_bl.c_str(), out_bl.length()); + return 0; +} + } // namespace util } // namespace librbd diff --git a/src/librbd/Utils.h b/src/librbd/Utils.h index 736a5063ac857..dee91feee5e61 100644 --- a/src/librbd/Utils.h +++ b/src/librbd/Utils.h @@ -276,6 +276,10 @@ SnapContext get_snap_context( uint64_t reserve_async_request_id(); +bool is_config_key_uri(const std::string& uri); +int get_config_key(librados::Rados& rados, const std::string& uri, + std::string* value); + } // namespace util } // namespace librbd