]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw/kms/vault - new transit logic - fix compat logic
authorMarcus Watts <mwatts@redhat.com>
Tue, 5 Jan 2021 02:21:33 +0000 (21:21 -0500)
committerMarcus Watts <mwatts@redhat.com>
Sat, 6 Mar 2021 04:05:13 +0000 (23:05 -0500)
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 <mwatts@redhat.com>
src/rgw/rgw_kms.cc

index 7e154a13ea1a2fac34a370a2b50e72a882b305de..a249deda782a468ced4165214a187855def38944 100644 (file)
@@ -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<typename E, typename A = ZeroPoolAllocator>
 static inline void
 add_name_val_to_obj(std::string &n, std::string &v, rapidjson::GenericValue<E,A> &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;