From: Casey Bodley Date: Sun, 27 Apr 2025 14:49:54 +0000 (-0400) Subject: rgw/multisite: forward_iam_request_to_master() preserves ErrorResponse responses X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d80cacab5d99ca89bc0b7af17ba0f823996a6348;p=ceph.git rgw/multisite: forward_iam_request_to_master() preserves ErrorResponse responses same changes as rgw_forward_request_to_master(), except the element is wrapped in a Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_rest_iam.cc b/src/rgw/rgw_rest_iam.cc index 5f9ae9c3a866d..e074706a9dc28 100644 --- a/src/rgw/rgw_rest_iam.cc +++ b/src/rgw/rgw_rest_iam.cc @@ -269,12 +269,39 @@ std::string iam_group_arn(const RGWGroupInfo& info) info.account_id, path, info.name); } +// try to parse the xml 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; } diff --git a/src/rgw/rgw_rest_iam.h b/src/rgw/rgw_rest_iam.h index 5a4a8329b2b5d..c90427ab5ac46 100644 --- a/src/rgw/rgw_rest_iam.h +++ b/src/rgw/rgw_rest_iam.h @@ -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 diff --git a/src/rgw/rgw_rest_iam_group.cc b/src/rgw/rgw_rest_iam_group.cc index 0fbe469ee07d4..5d7050a164822 100644 --- a/src/rgw/rgw_rest_iam_group.cc +++ b/src/rgw/rgw_rest_iam_group.cc @@ -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; diff --git a/src/rgw/rgw_rest_iam_user.cc b/src/rgw/rgw_rest_iam_user.cc index ae413e6d1856e..5698dc4c99316 100644 --- a/src/rgw/rgw_rest_iam_user.cc +++ b/src/rgw/rgw_rest_iam_user.cc @@ -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; diff --git a/src/rgw/rgw_rest_role.cc b/src/rgw/rgw_rest_role.cc index a3733c175cc3c..5a800a4aede30 100644 --- a/src/rgw/rgw_rest_role.cc +++ b/src/rgw/rgw_rest_role.cc @@ -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; diff --git a/src/rgw/rgw_rest_user_policy.cc b/src/rgw/rgw_rest_user_policy.cc index 3832b9a499370..d8aac4185abd8 100644 --- a/src/rgw/rgw_rest_user_policy.cc +++ b/src/rgw/rgw_rest_user_policy.cc @@ -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;