Skip to content

Commit d80caca

Browse files
committed
rgw/multisite: forward_iam_request_to_master() preserves ErrorResponse responses
same changes as rgw_forward_request_to_master(), except the <Error> element is wrapped in a <ErrorResponse> Signed-off-by: Casey Bodley <[email protected]>
1 parent 637bdd7 commit d80caca

File tree

6 files changed

+67
-36
lines changed

6 files changed

+67
-36
lines changed

src/rgw/rgw_rest_iam.cc

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,39 @@ std::string iam_group_arn(const RGWGroupInfo& info)
269269
info.account_id, path, info.name);
270270
}
271271

272+
// try to parse the xml <ErrorResponse> response body
273+
bool parse_aws_error_response(const std::string& input, rgw_err& err)
274+
{
275+
RGWXMLParser parser;
276+
if (!parser.init()) {
277+
return false;
278+
}
279+
if (!parser.parse(input.c_str(), input.length(), 1)) {
280+
return false;
281+
}
282+
auto error_response = parser.find_first("ErrorResponse");
283+
if (!error_response) {
284+
return false;
285+
}
286+
auto error = error_response->find_first("Error");
287+
if (!error) {
288+
return false;
289+
}
290+
if (auto code = error->find_first("Code"); code) {
291+
err.err_code = code->get_data();
292+
}
293+
if (auto message = error->find_first("Message"); message) {
294+
err.message = message->get_data();
295+
}
296+
return true;
297+
}
298+
272299
int forward_iam_request_to_master(const DoutPrefixProvider* dpp,
273300
const rgw::SiteConfig& site,
274301
const RGWUserInfo& user,
275-
bufferlist& indata,
276-
RGWXMLDecoder::XMLParser& parser,
277-
req_info& req, optional_yield y)
302+
bufferlist& indata, RGWXMLParser& parser,
303+
const req_info& req, rgw_err& err,
304+
optional_yield y)
278305
{
279306
const auto& period = site.get_period();
280307
if (!period) {
@@ -309,7 +336,11 @@ int forward_iam_request_to_master(const DoutPrefixProvider* dpp,
309336
if (!result) {
310337
return result.error();
311338
}
312-
int ret = rgw_http_error_to_errno(*result);
339+
err.http_ret = *result;
340+
if (err.is_err() && outdata.length()) { // 4xx or 5xx
341+
std::ignore = parse_aws_error_response(rgw_bl_str(outdata), err);
342+
}
343+
int ret = rgw_http_error_to_errno(err.http_ret);
313344
if (ret < 0) {
314345
return ret;
315346
}

src/rgw/rgw_rest_iam.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ std::string iam_group_arn(const RGWGroupInfo& info);
3131
int forward_iam_request_to_master(const DoutPrefixProvider* dpp,
3232
const rgw::SiteConfig& site,
3333
const RGWUserInfo& user,
34-
bufferlist& indata,
35-
RGWXMLDecoder::XMLParser& parser,
36-
req_info& req, optional_yield y);
34+
bufferlist& indata, RGWXMLParser& parser,
35+
const req_info& req, rgw_err& err,
36+
optional_yield y);
3737

3838
/// Perform an atomic read-modify-write operation on the given user metadata.
3939
/// Racing writes are detected here as ECANCELED errors, where we reload the

src/rgw/rgw_rest_iam_group.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int RGWCreateGroup_IAM::forward_to_master(optional_yield y,
123123
s->info.args.remove("Version");
124124

125125
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
126-
post_body, parser, s->info, y);
126+
post_body, parser, s->info, s->err, y);
127127
if (r < 0) {
128128
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
129129
return r;
@@ -422,7 +422,7 @@ int RGWUpdateGroup_IAM::forward_to_master(optional_yield y, const rgw::SiteConfi
422422
s->info.args.remove("Version");
423423

424424
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
425-
post_body, parser, s->info, y);
425+
post_body, parser, s->info, s->err, y);
426426
if (r < 0) {
427427
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
428428
return r;
@@ -556,7 +556,7 @@ int RGWDeleteGroup_IAM::forward_to_master(optional_yield y, const rgw::SiteConfi
556556
s->info.args.remove("Version");
557557

558558
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
559-
post_body, parser, s->info, y);
559+
post_body, parser, s->info, s->err, y);
560560
if (r < 0) {
561561
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
562562
return r;
@@ -885,7 +885,7 @@ int RGWAddUserToGroup_IAM::forward_to_master(optional_yield y,
885885
s->info.args.remove("Version");
886886

887887
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
888-
post_body, parser, s->info, y);
888+
post_body, parser, s->info, s->err, y);
889889
if (r < 0) {
890890
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
891891
return r;
@@ -1022,7 +1022,7 @@ int RGWRemoveUserFromGroup_IAM::forward_to_master(optional_yield y,
10221022
s->info.args.remove("Version");
10231023

10241024
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
1025-
post_body, parser, s->info, y);
1025+
post_body, parser, s->info, s->err, y);
10261026
if (r < 0) {
10271027
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
10281028
return r;
@@ -1261,7 +1261,7 @@ int RGWPutGroupPolicy_IAM::forward_to_master(optional_yield y,
12611261
s->info.args.remove("Version");
12621262

12631263
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
1264-
post_body, parser, s->info, y);
1264+
post_body, parser, s->info, s->err, y);
12651265
if (r < 0) {
12661266
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
12671267
return r;
@@ -1508,7 +1508,7 @@ int RGWDeleteGroupPolicy_IAM::forward_to_master(optional_yield y,
15081508
s->info.args.remove("Version");
15091509

15101510
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
1511-
post_body, parser, s->info, y);
1511+
post_body, parser, s->info, s->err, y);
15121512
if (r < 0) {
15131513
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
15141514
return r;
@@ -1749,7 +1749,7 @@ int RGWAttachGroupPolicy_IAM::forward_to_master(optional_yield y,
17491749
s->info.args.remove("Version");
17501750

17511751
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
1752-
post_body, parser, s->info, y);
1752+
post_body, parser, s->info, s->err, y);
17531753
if (r < 0) {
17541754
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
17551755
return r;
@@ -1898,7 +1898,7 @@ int RGWDetachGroupPolicy_IAM::forward_to_master(optional_yield y,
18981898
s->info.args.remove("Version");
18991899

19001900
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
1901-
post_body, parser, s->info, y);
1901+
post_body, parser, s->info, s->err, y);
19021902
if (r < 0) {
19031903
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
19041904
return r;

src/rgw/rgw_rest_iam_user.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int RGWCreateUser_IAM::forward_to_master(optional_yield y,
123123
}
124124

125125
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
126-
post_body, parser, s->info, y);
126+
post_body, parser, s->info, s->err, y);
127127
if (r < 0) {
128128
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
129129
return r;
@@ -412,7 +412,7 @@ int RGWUpdateUser_IAM::forward_to_master(optional_yield y, const rgw::SiteConfig
412412
s->info.args.remove("Version");
413413

414414
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
415-
post_body, parser, s->info, y);
415+
post_body, parser, s->info, s->err, y);
416416
if (r < 0) {
417417
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
418418
return r;
@@ -551,7 +551,7 @@ int RGWDeleteUser_IAM::forward_to_master(optional_yield y, const rgw::SiteConfig
551551
s->info.args.remove("Version");
552552

553553
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
554-
post_body, parser, s->info, y);
554+
post_body, parser, s->info, s->err, y);
555555
if (r < 0) {
556556
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
557557
return r;
@@ -882,7 +882,7 @@ int RGWCreateAccessKey_IAM::forward_to_master(optional_yield y,
882882
s->info.args.remove("Version");
883883

884884
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
885-
post_body, parser, s->info, y);
885+
post_body, parser, s->info, s->err, y);
886886
if (r < 0) {
887887
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
888888
return r;
@@ -1106,7 +1106,7 @@ int RGWUpdateAccessKey_IAM::forward_to_master(optional_yield y,
11061106
s->info.args.remove("Version");
11071107

11081108
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
1109-
post_body, parser, s->info, y);
1109+
post_body, parser, s->info, s->err, y);
11101110
if (r < 0) {
11111111
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
11121112
return r;
@@ -1253,7 +1253,7 @@ int RGWDeleteAccessKey_IAM::forward_to_master(optional_yield y,
12531253
s->info.args.remove("Version");
12541254

12551255
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
1256-
post_body, parser, s->info, y);
1256+
post_body, parser, s->info, s->err, y);
12571257
if (r < 0) {
12581258
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
12591259
return r;

src/rgw/rgw_rest_role.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void RGWCreateRole::execute(optional_yield y)
269269
}
270270

271271
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
272-
bl_post_body, parser, s->info, y);
272+
bl_post_body, parser, s->info, s->err, y);
273273
if (op_ret < 0) {
274274
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
275275
return;
@@ -368,7 +368,7 @@ void RGWDeleteRole::execute(optional_yield y)
368368
s->info.args.remove("Version");
369369

370370
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
371-
bl_post_body, parser, s->info, y);
371+
bl_post_body, parser, s->info, s->err, y);
372372
if (op_ret < 0) {
373373
ldpp_dout(this, 0) << "forward_iam_request_to_master returned ret=" << op_ret << dendl;
374374
return;
@@ -479,7 +479,7 @@ void RGWModifyRoleTrustPolicy::execute(optional_yield y)
479479
s->info.args.remove("Version");
480480

481481
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
482-
bl_post_body, parser, s->info, y);
482+
bl_post_body, parser, s->info, s->err, y);
483483
if (op_ret < 0) {
484484
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
485485
return;
@@ -616,7 +616,7 @@ void RGWPutRolePolicy::execute(optional_yield y)
616616
s->info.args.remove("Version");
617617

618618
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
619-
bl_post_body, parser, s->info, y);
619+
bl_post_body, parser, s->info, s->err, y);
620620
if (op_ret < 0) {
621621
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
622622
return;
@@ -750,7 +750,7 @@ void RGWDeleteRolePolicy::execute(optional_yield y)
750750
s->info.args.remove("Version");
751751

752752
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
753-
bl_post_body, parser, s->info, y);
753+
bl_post_body, parser, s->info, s->err, y);
754754
if (op_ret < 0) {
755755
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
756756
return;
@@ -825,7 +825,7 @@ void RGWTagRole::execute(optional_yield y)
825825
}
826826

827827
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
828-
bl_post_body, parser, s->info, y);
828+
bl_post_body, parser, s->info, s->err, y);
829829
if (op_ret < 0) {
830830
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
831831
return;
@@ -934,7 +934,7 @@ void RGWUntagRole::execute(optional_yield y)
934934
}
935935

936936
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
937-
bl_post_body, parser, s->info, y);
937+
bl_post_body, parser, s->info, s->err, y);
938938
if (op_ret < 0) {
939939
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
940940
return;
@@ -997,7 +997,7 @@ void RGWUpdateRole::execute(optional_yield y)
997997
s->info.args.remove("Version");
998998

999999
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
1000-
bl_post_body, parser, s->info, y);
1000+
bl_post_body, parser, s->info, s->err, y);
10011001
if (op_ret < 0) {
10021002
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
10031003
return;
@@ -1107,7 +1107,7 @@ void RGWAttachRolePolicy_IAM::execute(optional_yield y)
11071107
s->info.args.remove("Version");
11081108

11091109
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
1110-
bl_post_body, parser, s->info, y);
1110+
bl_post_body, parser, s->info, s->err, y);
11111111
if (op_ret < 0) {
11121112
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
11131113
return;
@@ -1207,7 +1207,7 @@ void RGWDetachRolePolicy_IAM::execute(optional_yield y)
12071207
s->info.args.remove("Version");
12081208

12091209
op_ret = forward_iam_request_to_master(this, site, s->user->get_info(),
1210-
bl_post_body, parser, s->info, y);
1210+
bl_post_body, parser, s->info, s->err, y);
12111211
if (op_ret < 0) {
12121212
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << op_ret << dendl;
12131213
return;

src/rgw/rgw_rest_user_policy.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int RGWPutUserPolicy::forward_to_master(optional_yield y, const rgw::SiteConfig&
148148
s->info.args.remove("Version");
149149

150150
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
151-
post_body, parser, s->info, y);
151+
post_body, parser, s->info, s->err, y);
152152
if (r < 0) {
153153
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
154154
return r;
@@ -355,7 +355,7 @@ int RGWDeleteUserPolicy::forward_to_master(optional_yield y, const rgw::SiteConf
355355
s->info.args.remove("Version");
356356

357357
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
358-
post_body, parser, s->info, y);
358+
post_body, parser, s->info, s->err, y);
359359
if (r < 0) {
360360
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
361361
return r;
@@ -453,7 +453,7 @@ int RGWAttachUserPolicy_IAM::forward_to_master(optional_yield y, const rgw::Site
453453
s->info.args.remove("Version");
454454

455455
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
456-
post_body, parser, s->info, y);
456+
post_body, parser, s->info, s->err, y);
457457
if (r < 0) {
458458
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
459459
return r;
@@ -573,7 +573,7 @@ int RGWDetachUserPolicy_IAM::forward_to_master(optional_yield y, const rgw::Site
573573
s->info.args.remove("Version");
574574

575575
int r = forward_iam_request_to_master(this, site, s->user->get_info(),
576-
post_body, parser, s->info, y);
576+
post_body, parser, s->info, s->err, y);
577577
if (r < 0) {
578578
ldpp_dout(this, 20) << "ERROR: forward_iam_request_to_master failed with error code: " << r << dendl;
579579
return r;

0 commit comments

Comments
 (0)