From: Marcus Watts Date: Tue, 5 Jan 2021 02:21:33 +0000 (-0500) Subject: rgw/kms/vault - new transit logic - fix compat logic X-Git-Tag: v17.1.0~2697^2~5 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=eceb06022c435bfed0edde32ffb7297d55f7c252;p=ceph-ci.git rgw/kms/vault - new transit logic - fix compat logic Teuthology passes in a vault uri that ends in /export/encryption-key/ So: we need to handle (and ignore) trailing slashes when deciding to enable compatibility support. Fixes: http://tracker.ceph.com/issues/48746 Signed-off-by: Marcus Watts --- diff --git a/src/rgw/rgw_kms.cc b/src/rgw/rgw_kms.cc index 7e154a13ea1..a249deda782 100644 --- a/src/rgw/rgw_kms.cc +++ b/src/rgw/rgw_kms.cc @@ -115,6 +115,25 @@ static void concat_url(std::string &url, std::string path) { } } +/** + * Determine if a string (url) ends with a given suffix. + * Must deal with (ignore) trailing slashes. + */ +static bool string_ends_maybe_slash(std::string_view hay, + std::string_view needle) +{ + auto hay_len { hay.size() }; + auto needle_len { needle.size() }; + if (hay_len < needle_len) return false; + auto hay_suffix_start { hay.data() + (hay_len - needle_len) }; + while (hay_len > needle_len && hay[hay_len-1] == '/') { + --hay_len; + --hay_suffix_start; + } + std::string_view hay_suffix { hay_suffix_start, needle_len }; + return hay_suffix == needle; +} + template static inline void add_name_val_to_obj(std::string &n, std::string &v, rapidjson::GenericValue &d, @@ -319,7 +338,7 @@ public: } if (compat == COMPAT_UNSET) { std::string_view v { cct->_conf->rgw_crypt_vault_prefix }; - if (v.rfind("/export/encryption-key") == v.length() - 22) { + if (string_ends_maybe_slash(v,"/export/encryption-key")) { compat = COMPAT_ONLY_OLD; } else { compat = COMPAT_NEW_ONLY;