]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Correcting logic for signature calculation for non s3 ops.
authorPritha Srivastava <prsrivas@redhat.com>
Tue, 22 Jan 2019 04:31:10 +0000 (10:01 +0530)
committerPritha Srivastava <prsrivas@redhat.com>
Thu, 31 Jan 2019 04:44:25 +0000 (10:14 +0530)
Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
src/rgw/rgw_auth_s3.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_sts.cc
src/rgw/rgw_rest_sts.h

index 0beb023c6ebd6ab426d61ff5c4a743a0590bc856..e01876e21829539c4f341fbe4035b590049d0d28 100644 (file)
@@ -511,6 +511,14 @@ static inline std::string get_v4_canonical_uri(const req_info& info) {
   return canonical_uri;
 }
 
+static inline const string calc_v4_payload_hash(const string& payload)
+{
+  ceph::crypto::SHA256* sha256_hash = calc_hash_sha256_open_stream();
+  calc_hash_sha256_update_stream(sha256_hash, payload.c_str(), payload.length());
+  const auto payload_hash = calc_hash_sha256_close_stream(&sha256_hash);
+  return payload_hash;
+}
+
 static inline const char* get_v4_exp_payload_hash(const req_info& info)
 {
   /* In AWSv4 the hash of real, transferred payload IS NOT necessary to form
index c81de09a3e1ab6a7f259998dc3d71e3f2fc1cda3..424f42f87f06bc65e3a9ea38ca86b8967c957a96 100644 (file)
@@ -3930,8 +3930,23 @@ AWSGeneralAbstractor::get_auth_data_v4(const req_state* const s,
     throw -EPERM;
   }
 
-  /* Get the expected hash. */
-  auto exp_payload_hash = rgw::auth::s3::get_v4_exp_payload_hash(s->info);
+  bool is_non_s3_op = false;
+  if (s->op_type == RGW_STS_GET_SESSION_TOKEN ||
+      s->op_type == RGW_STS_ASSUME_ROLE ||
+      s->op_type == RGW_STS_ASSUME_ROLE_WEB_IDENTITY) {
+    is_non_s3_op = true;
+  }
+
+  const char* exp_payload_hash = nullptr;
+  string payload_hash;
+  if (is_non_s3_op) {
+    //For non s3 ops, we need to calculate the payload hash
+    payload_hash = s->info.args.get("PayloadHash");
+    exp_payload_hash = payload_hash.c_str();
+  } else {
+    /* Get the expected hash. */
+    exp_payload_hash = rgw::auth::s3::get_v4_exp_payload_hash(s->info);
+  }
 
   /* Craft canonical URI. Using std::move later so let it be non-const. */
   auto canonical_uri = rgw::auth::s3::get_v4_canonical_uri(s->info);
@@ -3974,7 +3989,7 @@ AWSGeneralAbstractor::get_auth_data_v4(const req_state* const s,
    * This means we have absolutely no business in spawning completer. Both
    * aws4_auth_needs_complete and aws4_auth_streaming_mode are set to false
    * by default. We don't need to change that. */
-  if (is_v4_payload_unsigned(exp_payload_hash) || is_v4_payload_empty(s)) {
+  if (is_v4_payload_unsigned(exp_payload_hash) || is_v4_payload_empty(s) || is_non_s3_op) {
     return {
       access_key_id,
       client_signature,
@@ -4010,8 +4025,6 @@ AWSGeneralAbstractor::get_auth_data_v4(const req_state* const s,
         case RGW_OP_PUT_OBJ_TAGGING:
         case RGW_OP_PUT_LC:
         case RGW_OP_SET_REQUEST_PAYMENT:
-        case RGW_STS_GET_SESSION_TOKEN:
-        case RGW_STS_ASSUME_ROLE:
           break;
         default:
           dout(10) << "ERROR: AWS4 completion for this operation NOT IMPLEMENTED" << dendl;
index bcbd9008c6b79028ad2819f537130ad54c6559a9..fab82b1e1ff2dc602561f1e1828a0f1eef317a32 100644 (file)
@@ -341,8 +341,8 @@ void RGWHandler_REST_STS::rgw_sts_parse_input()
   int ret = 0;
   bufferlist data;
   std::tie(ret, data) = rgw_rest_read_all_input(s, max_size, false);
+  string post_body = data.to_str();
   if (data.length() > 0) {
-    string post_body = data.to_str();
     ldout(s->cct, 10) << "Content of POST: " << post_body << dendl;
 
     if (post_body.find("Action") != string::npos) {
@@ -362,6 +362,8 @@ void RGWHandler_REST_STS::rgw_sts_parse_input()
        }
     }
   }
+  auto payload_hash = rgw::auth::s3::calc_v4_payload_hash(post_body);
+  s->info.args.append("PayloadHash", payload_hash);
 }
 
 RGWOp *RGWHandler_REST_STS::op_post()
index a7ec7ba26430b4069e7ec67239e703120970bcd9..a89c381d66efc49f8b5084109d2823ff5f14dad3 100644 (file)
@@ -148,7 +148,7 @@ public:
   void execute() override;
   int verify_permission() override;
   int get_params();
-  const char* name() const override { return "get_keystone_session_token"; }
+  const char* name() const override { return "get_session_token"; }
   RGWOpType get_type() override { return RGW_STS_GET_SESSION_TOKEN; }
 };