]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: handle aws4 completion when reading all op data 39678/head
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 11 Mar 2021 15:09:20 +0000 (07:09 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 11 Mar 2021 15:12:51 +0000 (07:12 -0800)
and add a few ops to the list of ops that complete aws4 signature.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
12 files changed:
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_op_type.h
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h
src/rgw/rgw_rest_bucket.cc
src/rgw/rgw_rest_log.cc
src/rgw/rgw_rest_log.h
src/rgw/rgw_rest_pubsub.cc
src/rgw/rgw_rest_realm.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_user.cc

index 43844e59ba694a23ffa35dc7326a7eaedd97ac9f..f2822e372dafe6e0ba08258482cab2f5653e2d13 100644 (file)
@@ -7557,7 +7557,7 @@ int RGWPutBucketPolicy::get_params(optional_yield y)
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
   // At some point when I have more time I want to make a version of
   // rgw_rest_read_all_input that doesn't use malloc.
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
 
   // And throws exceptions.
   return op_ret;
@@ -8002,7 +8002,7 @@ int RGWPutBucketPublicAccessBlock::verify_permission(optional_yield y)
 int RGWPutBucketPublicAccessBlock::get_params(optional_yield y)
 {
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
   return op_ret;
 }
 
index 8df15c42e4183d672d286f0cbdb86ac4c6114826..673ce92f691df4dc46f0332f1d7a92d6e3df3abc 100644 (file)
@@ -124,6 +124,47 @@ void rgw_bucket_object_pre_exec(struct req_state *s);
 
 namespace dmc = rgw::dmclock;
 
+std::tuple<int, bufferlist > rgw_rest_read_all_input(struct req_state *s,
+                                        const uint64_t max_len,
+                                        const bool allow_chunked=true);
+
+template <class T>
+int rgw_rest_get_json_input(CephContext *cct, req_state *s, T& out,
+                           uint64_t max_len, bool *empty)
+{
+  if (empty)
+    *empty = false;
+
+  int rv = 0;
+  bufferlist data;
+  std::tie(rv, data) = rgw_rest_read_all_input(s, max_len);
+  if (rv < 0) {
+    return rv;
+  }
+
+  if (!data.length()) {
+    if (empty) {
+      *empty = true;
+    }
+
+    return -EINVAL;
+  }
+
+  JSONParser parser;
+
+  if (!parser.parse(data.c_str(), data.length())) {
+    return -EINVAL;
+  }
+
+  try {
+      decode_json_obj(out, &parser);
+  } catch (JSONDecoder::err& e) {
+      return -EINVAL;
+  }
+
+  return 0;
+}
+
 /**
  * Provide the base class for all ops.
  */
@@ -141,6 +182,30 @@ protected:
 
   virtual int init_quota();
 
+  std::tuple<int, bufferlist> read_all_input(struct req_state *s,
+                                             const uint64_t max_len,
+                                             const bool allow_chunked=true) {
+
+    int rv = 0;
+    bufferlist data;
+    std::tie(rv, data) = rgw_rest_read_all_input(s, max_len);
+    if (rv >= 0) {
+      do_aws4_auth_completion();
+    }
+
+    return std::make_tuple(rv, std::move(data));
+  }
+
+  template <class T>
+  int get_json_input(CephContext *cct, req_state *s, T& out,
+                     uint64_t max_len, bool *empty) {
+    int r = rgw_rest_get_json_input(cct, s, out, max_len, empty);
+    if (r >= 0) {
+      do_aws4_auth_completion();
+    }
+    return r;
+  }
+
 public:
   RGWOp()
     : s(nullptr),
index ff474f00728afff4e7a5f0ce23851c34e4b1fe13..f25cbcf265e4701b85b6ea570dcc9cf954e996e0 100644 (file)
@@ -85,6 +85,9 @@ enum RGWOpType {
   RGW_OP_CONFIG_BUCKET_META_SEARCH,
   RGW_OP_GET_BUCKET_META_SEARCH,
   RGW_OP_DEL_BUCKET_META_SEARCH,
+  RGW_OP_SYNC_DATALOG_NOTIFY,
+  RGW_OP_SYNC_MDLOG_NOTIFY,
+  RGW_OP_PERIOD_POST,
   /* sts specific*/
   RGW_STS_ASSUME_ROLE,
   RGW_STS_GET_SESSION_TOKEN,
index a8fb3262ce45b451dcc236ce0d2c40fcadfac547..3e517e995674e74bbf7820e4f877e2ed09a02da3 100644 (file)
@@ -1437,7 +1437,7 @@ int RGWPostObj_ObjStore::get_params(optional_yield y)
 int RGWPutACLs_ObjStore::get_params(optional_yield y)
 {
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
   ldpp_dout(s, 0) << "RGWPutACLs_ObjStore::get_params read data is: " << data.c_str() << dendl;
   return op_ret;
 }
@@ -1445,21 +1445,21 @@ int RGWPutACLs_ObjStore::get_params(optional_yield y)
 int RGWPutLC_ObjStore::get_params(optional_yield y)
 {
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
   return op_ret;
 }
 
 int RGWPutBucketObjectLock_ObjStore::get_params(optional_yield y)
 {
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
   return op_ret;
 }
 
 int RGWPutObjLegalHold_ObjStore::get_params(optional_yield y)
 {
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
   return op_ret;
 }
 
@@ -1554,7 +1554,7 @@ int RGWCompleteMultipart_ObjStore::get_params(optional_yield y)
   }
 
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size);
+  std::tie(op_ret, data) = read_all_input(s, max_size);
   if (op_ret < 0)
     return op_ret;
 
@@ -1630,7 +1630,7 @@ int RGWDeleteMultiObj_ObjStore::get_params(optional_yield y)
   bucket = s->bucket.get();
 
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
   return op_ret;
 }
 
index b2c6ed00e8b68e9e0f89711f98fa7516278e8083..e39abbc029be48e7ebbe59bd9c20c6616b90993d 100644 (file)
@@ -24,10 +24,6 @@ extern void rgw_flush_formatter_and_reset(struct req_state *s,
 extern void rgw_flush_formatter(struct req_state *s,
                                ceph::Formatter *formatter);
 
-std::tuple<int, bufferlist > rgw_rest_read_all_input(struct req_state *s,
-                                        const uint64_t max_len,
-                                        const bool allow_chunked=true);
-
 inline std::string_view rgw_sanitized_hdrval(ceph::buffer::list& raw)
 {
   /* std::string and thus std::string_view ARE OBLIGED to carry multiple
@@ -48,43 +44,6 @@ inline std::string_view rgw_sanitized_hdrval(ceph::buffer::list& raw)
   return std::string_view(data, len);
 }
 
-template <class T>
-int rgw_rest_get_json_input(CephContext *cct, req_state *s, T& out,
-                           uint64_t max_len, bool *empty)
-{
-  if (empty)
-    *empty = false;
-
-  int rv = 0;
-  bufferlist data;
-  std::tie(rv, data) = rgw_rest_read_all_input(s, max_len);
-  if (rv < 0) {
-    return rv;
-  }
-
-  if (!data.length()) {
-    if (empty) {
-      *empty = true;
-    }
-
-    return -EINVAL;
-  }
-
-  JSONParser parser;
-
-  if (!parser.parse(data.c_str(), data.length())) {
-    return -EINVAL;
-  }
-
-  try {
-      decode_json_obj(out, &parser);
-  } catch (JSONDecoder::err& e) {
-      return -EINVAL;
-  }
-
-  return 0;
-}
-
 template <class T>
 std::tuple<int, bufferlist > rgw_rest_get_json_input_keep_data(CephContext *cct, req_state *s, T& out, uint64_t max_len)
 {
@@ -543,6 +502,7 @@ public:
 class RGWRESTOp : public RGWOp {
 protected:
   RGWRESTFlusher flusher;
+
 public:
   void init(rgw::sal::RGWStore *store, struct req_state *s,
             RGWHandler *dialect_handler) override {
index ba58b24af066fda686b54a91cacbc10b0070c9f1..8817c6b10eb45213105760a0132dc69f20aad60f 100644 (file)
@@ -273,7 +273,7 @@ void RGWOp_Set_Bucket_Quota::execute(optional_yield y)
   RGWQuotaInfo quota;
   if (!use_http_params) {
     bool empty;
-    op_ret = rgw_rest_get_json_input(store->ctx(), s, quota, QUOTA_INPUT_MAX_LEN, &empty);
+    op_ret = get_json_input(store->ctx(), s, quota, QUOTA_INPUT_MAX_LEN, &empty);
     if (op_ret < 0) {
       if (!empty)
         return;
index 62dab9b5d54b9bcb3fca5b7c3977178876e6af06..a354b97c63451425d9714128d18e9532bd487261 100644 (file)
@@ -322,7 +322,7 @@ void RGWOp_MDLog_Notify::execute(optional_yield y) {
 
   int r = 0;
   bufferlist data;
-  std::tie(r, data) = rgw_rest_read_all_input(s, LARGE_ENOUGH_BUF);
+  std::tie(r, data) = read_all_input(s, LARGE_ENOUGH_BUF);
   if (r < 0) {
     op_ret = r;
     return;
@@ -665,7 +665,7 @@ void RGWOp_DATALog_Notify::execute(optional_yield y) {
 
   int r = 0;
   bufferlist data;
-  std::tie(r, data) = rgw_rest_read_all_input(s, LARGE_ENOUGH_BUF);
+  std::tie(r, data) = read_all_input(s, LARGE_ENOUGH_BUF);
   if (r < 0) {
     op_ret = r;
     return;
index b316effb82a80cb2d1b6a333a3a5cd90f0eb6bc7..9b1f4f2d9d3b0be8f29c21de7b9d6735d471900d 100644 (file)
@@ -178,6 +178,7 @@ public:
   const char* name() const override {
     return "mdlog_notify";
   }
+  RGWOpType get_type() override { return RGW_OP_SYNC_MDLOG_NOTIFY; }
 };
 
 class RGWOp_MDLog_Delete : public RGWRESTOp {
@@ -266,6 +267,7 @@ public:
   const char* name() const override {
     return "datalog_notify";
   }
+  RGWOpType get_type() override { return RGW_OP_SYNC_DATALOG_NOTIFY; }
 };
 
 class RGWOp_DATALog_Delete : public RGWRESTOp {
index 05668ba4f1a1bcce7e7946d3a1d3b49572204541..a8597b3da380e42d6293b8546c01f64318e21b38 100644 (file)
@@ -431,7 +431,7 @@ class RGWPSCreateNotif_ObjStore_S3 : public RGWPSCreateNotifOp {
     const auto max_size = s->cct->_conf->rgw_max_put_param_size;
     int r;
     bufferlist data;
-    std::tie(r, data) = rgw_rest_read_all_input(s, max_size, false);
+    std::tie(r, data) = read_all_input(s, max_size, false);
 
     if (r < 0) {
       ldout(s->cct, 1) << "failed to read XML payload" << dendl;
index 8c1cf57d2c74b33cbca6cf2ab280208cd67b4f8b..6669fd660508cddbea2bbcdca7be7e9e34656488 100644 (file)
@@ -89,6 +89,7 @@ class RGWOp_Period_Post : public RGWOp_Period_Base {
     return check_caps(s->user->get_caps());
   }
   const char* name() const override { return "post_period"; }
+  RGWOpType get_type() override { return RGW_OP_PERIOD_POST; }
 };
 
 void RGWOp_Period_Post::execute(optional_yield y)
@@ -101,7 +102,7 @@ void RGWOp_Period_Post::execute(optional_yield y)
   // decode the period from input
   const auto max_size = cct->_conf->rgw_max_put_param_size;
   bool empty;
-  op_ret = rgw_rest_get_json_input(cct, s, period, max_size, &empty);
+  op_ret = get_json_input(cct, s, period, max_size, &empty);
   if (op_ret < 0) {
     lderr(cct) << "failed to decode period" << dendl;
     return;
index 6562708e9aa8374afc9808ad04b5e2511bf46899..6acda8689428d059abb3c5334c94d5b4bac939f8 100644 (file)
@@ -537,7 +537,7 @@ int RGWPutObjTags_ObjStore_S3::get_params(optional_yield y)
 
   int r = 0;
   bufferlist data;
-  std::tie(r, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(r, data) = read_all_input(s, max_size, false);
 
   if (r < 0)
     return r;
@@ -630,7 +630,7 @@ int RGWPutBucketTags_ObjStore_S3::get_params(optional_yield y)
   int r = 0;
   bufferlist data;
 
-  std::tie(r, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(r, data) = read_all_input(s, max_size, false);
 
   if (r < 0)
     return r;
@@ -1198,7 +1198,7 @@ int RGWPutBucketReplication_ObjStore_S3::get_params(optional_yield y)
   int r = 0;
   bufferlist data;
 
-  std::tie(r, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(r, data) = read_all_input(s, max_size, false);
 
   if (r < 0)
     return r;
@@ -1966,12 +1966,7 @@ int RGWSetBucketVersioning_ObjStore_S3::get_params(optional_yield y)
   int r = 0;
   bufferlist data;
   std::tie(r, data) =
-    rgw_rest_read_all_input(s, s->cct->_conf->rgw_max_put_param_size, false);
-  if (r < 0) {
-    return r;
-  }
-
-  r = do_aws4_auth_completion();
+    read_all_input(s, s->cct->_conf->rgw_max_put_param_size, false);
   if (r < 0) {
     return r;
   }
@@ -2039,13 +2034,8 @@ int RGWSetBucketWebsite_ObjStore_S3::get_params(optional_yield y)
 
   int r = 0;
   bufferlist data;
-  std::tie(r, data) = rgw_rest_read_all_input(s, max_size, false);
-
-  if (r < 0) {
-    return r;
-  }
+  std::tie(r, data) = read_all_input(s, max_size, false);
 
-  r = do_aws4_auth_completion();
   if (r < 0) {
     return r;
   }
@@ -2255,16 +2245,11 @@ int RGWCreateBucket_ObjStore_S3::get_params(optional_yield y)
 
   int op_ret = 0;
   bufferlist data;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
 
   if ((op_ret < 0) && (op_ret != -ERR_LENGTH_REQUIRED))
     return op_ret;
 
-  const int auth_ret = do_aws4_auth_completion();
-  if (auth_ret < 0) {
-    return auth_ret;
-  }
-
   in_data.append(data);
 
   if (data.length()) {
@@ -3461,12 +3446,7 @@ int RGWPutCORS_ObjStore_S3::get_params(optional_yield y)
 
   int r = 0;
   bufferlist data;
-  std::tie(r, data) = rgw_rest_read_all_input(s, max_size, false);
-  if (r < 0) {
-    return r;
-  }
-
-  r = do_aws4_auth_completion();
+  std::tie(r, data) = read_all_input(s, max_size, false);
   if (r < 0) {
     return r;
   }
@@ -3614,7 +3594,7 @@ int RGWSetRequestPayment_ObjStore_S3::get_params(optional_yield y)
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
 
   int r = 0;
-  std::tie(r, in_data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(r, in_data) = read_all_input(s, max_size, false);
 
   if (r < 0) {
     return r;
@@ -4137,7 +4117,7 @@ int RGWPutObjRetention_ObjStore_S3::get_params(optional_yield y)
   }
 
   const auto max_size = s->cct->_conf->rgw_max_put_param_size;
-  std::tie(op_ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(op_ret, data) = read_all_input(s, max_size, false);
   return op_ret;
 }
 
@@ -5482,6 +5462,9 @@ AWSGeneralAbstractor::get_auth_data_v4(const req_state* const s,
         case RGW_OP_SET_BUCKET_VERSIONING:
         case RGW_OP_DELETE_MULTI_OBJ:
         case RGW_OP_ADMIN_SET_METADATA:
+        case RGW_OP_SYNC_DATALOG_NOTIFY:
+        case RGW_OP_SYNC_MDLOG_NOTIFY:
+        case RGW_OP_PERIOD_POST:
         case RGW_OP_SET_BUCKET_WEBSITE:
         case RGW_OP_PUT_BUCKET_POLICY:
         case RGW_OP_PUT_OBJ_TAGGING:
@@ -6120,7 +6103,7 @@ int RGWSelectObj_ObjStore_S3::get_params(optional_yield y)
   bufferlist data;
   int ret;
   int max_size = 4096;
-  std::tie(ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  std::tie(ret, data) = read_all_input(s, max_size, false);
   if (ret != 0) {
     ldout(s->cct, 10) << "s3-select query: failed to retrieve query; ret = " << ret << dendl;
     return ret;
index a24d5c859302d9ec40b184d452c1e67348904b6c..f373d0f1d5a2cb261660cdeffb2d1bd3d4fdc57c 100644 (file)
@@ -994,7 +994,7 @@ void RGWOp_Quota_Set::execute(optional_yield y)
   if (set_all) {
     UserQuotas quotas;
 
-    if ((op_ret = rgw_rest_get_json_input(store->ctx(), s, quotas, QUOTA_INPUT_MAX_LEN, NULL)) < 0) {
+    if ((op_ret = get_json_input(store->ctx(), s, quotas, QUOTA_INPUT_MAX_LEN, NULL)) < 0) {
       ldpp_dout(this, 20) << "failed to retrieve input" << dendl;
       return;
     }
@@ -1006,7 +1006,7 @@ void RGWOp_Quota_Set::execute(optional_yield y)
 
     if (!use_http_params) {
       bool empty;
-      op_ret = rgw_rest_get_json_input(store->ctx(), s, quota, QUOTA_INPUT_MAX_LEN, &empty);
+      op_ret = get_json_input(store->ctx(), s, quota, QUOTA_INPUT_MAX_LEN, &empty);
       if (op_ret < 0) {
         ldpp_dout(this, 20) << "failed to retrieve input" << dendl;
         if (!empty)