From e3a26f77c090076eb76bf67af659ce88af9eee8e Mon Sep 17 00:00:00 2001 From: Ali Maredia Date: Tue, 18 Oct 2022 14:23:57 -0400 Subject: [PATCH] rgw: set keys from from master zone on admin api user create When users were being created via the admin_api on a secondary zone the keys returned in the json output are not correct. This commit ensures the proper keys are set to be returned to the user via the json output. fixes: https://tracker.ceph.com/issues/57724 Signed-off-by: Ali Maredia --- src/rgw/driver/rados/rgw_rest_user.cc | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/rgw/driver/rados/rgw_rest_user.cc b/src/rgw/driver/rados/rgw_rest_user.cc index c2aeece247d..0befc1ee43a 100644 --- a/src/rgw/driver/rados/rgw_rest_user.cc +++ b/src/rgw/driver/rados/rgw_rest_user.cc @@ -206,9 +206,6 @@ void RGWOp_User_Create::execute(optional_yield y) if (s->info.args.exists("exclusive")) op_state.set_exclusive(exclusive); - if (gen_key) - op_state.set_generate_key(); - if (!default_placement_str.empty()) { rgw_placement_rule target_rule; target_rule.from_str(default_placement_str); @@ -226,13 +223,28 @@ void RGWOp_User_Create::execute(optional_yield y) op_state.set_placement_tags(placement_tags_list); } - bufferlist data; - op_ret = driver->forward_request_to_master(s, s->user.get(), nullptr, data, nullptr, s->info, y); - if (op_ret < 0) { - ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; - return; + if(!(store->is_meta_master())) { + bufferlist data; + JSONParser jp; + RGWUserInfo ui; + op_ret = store->forward_request_to_master(s, s->user.get(), nullptr, data, &jp, s->info, y); + if (op_ret < 0) { + ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl; + return; + } + ui.decode_json(&jp); + std::map keys = ui.access_keys; + auto keys_itr = keys.begin(); + RGWAccessKey first_key = keys_itr->second; + op_state.id = first_key.id; + op_state.key = first_key.key; } - op_ret = RGWUserAdminOp_User::create(s, driver, op_state, flusher, y); + + if (gen_key) { + op_state.set_generate_key(); + } + + op_ret = RGWUserAdminOp_User::create(s, store, op_state, flusher, y); } class RGWOp_User_Modify : public RGWRESTOp { -- 2.39.5