]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/sse-s3: save sse attributes in req_state->crypt_attribute_map
authorMarcus Watts <mwatts@redhat.com>
Sat, 18 Dec 2021 04:09:56 +0000 (23:09 -0500)
committerMarcus Watts <mwatts@redhat.com>
Tue, 19 Apr 2022 21:35:39 +0000 (17:35 -0400)
req_state->crypt_attribute_map to save sse-s3 cryptographic attributes
this is not quite a duplicate of x_meta_map because I think some of
        of its uses conflict with sse-s3. (for instance, bucketencryption vs. signatures)

Signed-off-by: Marcus Watts <mwatts@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h

index 5e30c14f3cc557f60b8746f53bf640b4dbb84225..5b5a1a60530ed896e03cda12587cd7fa78f5b06e 100644 (file)
@@ -393,6 +393,7 @@ struct str_len meta_prefixes[] = { STR_LEN_ENTRY("HTTP_X_AMZ"),
 void req_info::init_meta_info(const DoutPrefixProvider *dpp, bool *found_bad_meta)
 {
   x_meta_map.clear();
+  crypt_attribute_map.clear();
 
   for (const auto& kv: env->get_map()) {
     const char *prefix;
@@ -432,6 +433,9 @@ void req_info::init_meta_info(const DoutPrefixProvider *dpp, bool *found_bad_met
         } else {
           x_meta_map[name_low] = val;
         }
+        if (strncmp(name_low, "x-amz-server-side-encryption", 20) == 0) {
+          crypt_attribute_map[name_low] = val;
+        }
       }
     }
   }
@@ -463,6 +467,35 @@ void rgw_add_amz_meta_header(
   }
 }
 
+bool rgw_set_amz_meta_header(
+  meta_map_t& x_meta_map,
+  const std::string& k,
+  const std::string& v,
+  rgw_set_action_if_set a)
+{
+  auto it { x_meta_map.find(k) };
+  bool r { it != x_meta_map.end() };
+  switch(a) {
+  default:
+    ceph_assert(a == 0);
+  case DISCARD:
+    break;
+  case APPEND:
+    if (r) {
+       std::string old { it->second };
+       boost::algorithm::trim_right(old);
+       old.append(",");
+       old.append(v);
+       x_meta_map[k] = old;
+       break;
+    }
+    /* fall through */
+  case OVERWRITE:
+    x_meta_map[k] = v;
+  }
+  return r;
+}
+
 string rgw_string_unquote(const string& s)
 {
   if (s[0] != '"' || s.size() < 2)
index ddb455f041cf9e5cbe35c91d381aea07607c5666..a532fde1d176741c252ed97572f79f9b751281e2 100644 (file)
@@ -1225,6 +1225,7 @@ struct req_info {
   const RGWEnv *env;
   RGWHTTPArgs args;
   meta_map_t x_meta_map;
+  meta_map_t crypt_attribute_map;
 
   std::string host;
   const char *method;
@@ -2055,6 +2056,15 @@ void rgw_add_amz_meta_header(
   const std::string& k,
   const std::string& v);
 
+enum rgw_set_action_if_set {
+  DISCARD=0, OVERWRITE, APPEND
+};
+
+bool rgw_set_amz_meta_header(
+  meta_map_t& x_meta_map,
+  const std::string& k,
+  const std::string& v, rgw_set_action_if_set f);
+
 extern std::string rgw_string_unquote(const std::string& s);
 extern void parse_csv_string(const std::string& ival, std::vector<std::string>& ovals);
 extern int parse_key_value(std::string& in_str, std::string& key, std::string& val);