]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/multisite: forward_iam_request_to_master() preserves ErrorResponse responses
authorCasey Bodley <cbodley@redhat.com>
Sun, 27 Apr 2025 14:49:54 +0000 (10:49 -0400)
committerCasey Bodley <cbodley@redhat.com>
Tue, 29 Apr 2025 15:17:31 +0000 (11:17 -0400)
same changes as rgw_forward_request_to_master(), except the <Error>
element is wrapped in a <ErrorResponse>

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_rest_iam.cc
src/rgw/rgw_rest_iam.h
src/rgw/rgw_rest_iam_group.cc
src/rgw/rgw_rest_iam_user.cc
src/rgw/rgw_rest_role.cc
src/rgw/rgw_rest_user_policy.cc

index 5f9ae9c3a866d432f49aca0c254bf06d08d1af8d..e074706a9dc28743d0f47c1624bc8c66f9e0fbc1 100644 (file)
@@ -269,12 +269,39 @@ std::string iam_group_arn(const RGWGroupInfo& info)
                      info.account_id, path, info.name);
 }
 
+// try to parse the xml <ErrorResponse> response body
+bool parse_aws_error_response(const std::string& input, rgw_err& err)
+{
+  RGWXMLParser parser;
+  if (!parser.init()) {
+    return false;
+  }
+  if (!parser.parse(input.c_str(), input.length(), 1)) {
+    return false;
+  }
+  auto error_response = parser.find_first("ErrorResponse");
+  if (!error_response) {
+    return false;
+  }
+  auto error = error_response->find_first("Error");
+  if (!error) {
+    return false;
+  }
+  if (auto code = error->find_first("Code"); code) {
+    err.err_code = code->get_data();
+  }
+  if (auto message = error->find_first("Message"); message) {
+    err.message = message->get_data();
+  }
+  return true;
+}
+
 int forward_iam_request_to_master(const DoutPrefixProvider* dpp,
                                   const rgw::SiteConfig& site,
                                   const RGWUserInfo& user,
-                                  bufferlist& indata,
-                                  RGWXMLDecoder::XMLParser& parser,
-                                  req_info& req, optional_yield y)
+                                  bufferlist& indata, RGWXMLParser& parser,
+                                  const req_info& req, rgw_err& err,
+                                  optional_yield y)
 {
   const auto& period = site.get_period();
   if (!period) {
@@ -309,7 +336,11 @@ int forward_iam_request_to_master(const DoutPrefixProvider* dpp,
   if (!result) {
     return result.error();
   }
-  int ret = rgw_http_error_to_errno(*result);
+  err.http_ret = *result;
+  if (err.is_err() && outdata.length()) { // 4xx or 5xx
+    std::ignore = parse_aws_error_response(rgw_bl_str(outdata), err);
+  }
+  int ret = rgw_http_error_to_errno(err.http_ret);
   if (ret < 0) {
     return ret;
   }
index 5a4a8329b2b5d27d2397992d17921370faff4f7f..c90427ab5ac468629884c403b5af097a5f1a713f 100644 (file)
@@ -31,9 +31,9 @@ std::string iam_group_arn(const RGWGroupInfo& info);
 int forward_iam_request_to_master(const DoutPrefixProvider* dpp,
                                   const rgw::SiteConfig& site,
                                   const RGWUserInfo& user,
-                                  bufferlist& indata,
-                                  RGWXMLDecoder::XMLParser& parser,
-                                  req_info& req, optional_yield y);
+                                  bufferlist& indata, RGWXMLParser& parser,
+                                  const req_info& req, rgw_err& err,
+                                  optional_yield y);
 
 /// Perform an atomic read-modify-write operation on the given user metadata.
 /// Racing writes are detected here as ECANCELED errors, where we reload the
index 0fbe469ee07d4ae7dc140710c112f43aedbe0dc2..5d7050a164822a0961b195fb27ad6234fcc0f813 100644 (file)
@@ -123,7 +123,7 @@ int RGWCreateGroup_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -422,7 +422,7 @@ int RGWUpdateGroup_IAM::forward_to_master(optional_yield y, const rgw::SiteConfi
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -556,7 +556,7 @@ int RGWDeleteGroup_IAM::forward_to_master(optional_yield y, const rgw::SiteConfi
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -885,7 +885,7 @@ int RGWAddUserToGroup_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -1022,7 +1022,7 @@ int RGWRemoveUserFromGroup_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -1261,7 +1261,7 @@ int RGWPutGroupPolicy_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -1508,7 +1508,7 @@ int RGWDeleteGroupPolicy_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -1749,7 +1749,7 @@ int RGWAttachGroupPolicy_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -1898,7 +1898,7 @@ int RGWDetachGroupPolicy_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
index ae413e6d1856e042fb93261217596491cb24fe37..5698dc4c993164afc035f313bb16734ed887e9f1 100644 (file)
@@ -123,7 +123,7 @@ int RGWCreateUser_IAM::forward_to_master(optional_yield y,
   }
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -412,7 +412,7 @@ int RGWUpdateUser_IAM::forward_to_master(optional_yield y, const rgw::SiteConfig
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -551,7 +551,7 @@ int RGWDeleteUser_IAM::forward_to_master(optional_yield y, const rgw::SiteConfig
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -882,7 +882,7 @@ int RGWCreateAccessKey_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -1106,7 +1106,7 @@ int RGWUpdateAccessKey_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -1253,7 +1253,7 @@ int RGWDeleteAccessKey_IAM::forward_to_master(optional_yield y,
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
index a3733c175cc3c1c0b5d50e9bcef6b2f050883830..5a800a4aede309ee987dadb4a68320df3331ee26 100644 (file)
@@ -269,7 +269,7 @@ void RGWCreateRole::execute(optional_yield y)
     }
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -368,7 +368,7 @@ void RGWDeleteRole::execute(optional_yield y)
     s->info.args.remove("Version");
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 0) << "forward_iam_request_to_master returned ret=" << op_ret << dendl;
       return;
@@ -479,7 +479,7 @@ void RGWModifyRoleTrustPolicy::execute(optional_yield y)
     s->info.args.remove("Version");
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -616,7 +616,7 @@ void RGWPutRolePolicy::execute(optional_yield y)
     s->info.args.remove("Version");
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -750,7 +750,7 @@ void RGWDeleteRolePolicy::execute(optional_yield y)
     s->info.args.remove("Version");
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -825,7 +825,7 @@ void RGWTagRole::execute(optional_yield y)
     }
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -934,7 +934,7 @@ void RGWUntagRole::execute(optional_yield y)
     }
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -997,7 +997,7 @@ void RGWUpdateRole::execute(optional_yield y)
     s->info.args.remove("Version");
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -1107,7 +1107,7 @@ void RGWAttachRolePolicy_IAM::execute(optional_yield y)
     s->info.args.remove("Version");
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
@@ -1207,7 +1207,7 @@ void RGWDetachRolePolicy_IAM::execute(optional_yield y)
     s->info.args.remove("Version");
 
     op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                           bl_post_body, parser, s->info, y);
+                                           bl_post_body, parser, s->info, s->err, y);
     if (op_ret < 0) {
       ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
       return;
index 3832b9a49937085f1483bf470ccc70180565cc00..d8aac4185abd80116bb8b8029deb5effb581d4fb 100644 (file)
@@ -148,7 +148,7 @@ int RGWPutUserPolicy::forward_to_master(optional_yield y, const rgw::SiteConfig&
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -355,7 +355,7 @@ int RGWDeleteUserPolicy::forward_to_master(optional_yield y, const rgw::SiteConf
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -453,7 +453,7 @@ int RGWAttachUserPolicy_IAM::forward_to_master(optional_yield y, const rgw::Site
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;
@@ -573,7 +573,7 @@ int RGWDetachUserPolicy_IAM::forward_to_master(optional_yield y, const rgw::Site
   s->info.args.remove("Version");
 
   int r = forward_iam_request_to_master(this, site, s->user->get_info(),
-                                        post_body, parser, s->info, y);
+                                        post_body, parser, s->info, s->err, y);
   if (r < 0) {
     ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
     return r;