@@ -188,7 +188,8 @@ int load_account_and_policies(const DoutPrefixProvider* dpp,
188188
189189static auto transform_old_authinfo (const RGWUserInfo& user,
190190 std::optional<RGWAccountInfo> account,
191- std::vector<IAM::Policy> policies)
191+ std::vector<IAM::Policy> policies,
192+ sal::Driver* driver)
192193 -> std::unique_ptr<rgw::auth::Identity>
193194{
194195 /* This class is not intended for public use. Should be removed altogether
@@ -198,6 +199,7 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
198199 /* For this particular case it's OK to use rgw_user structure to convey
199200 * the identity info as this was the policy for doing that before the
200201 * new auth. */
202+ sal::Driver* driver;
201203 const rgw_user id;
202204 const std::string display_name;
203205 const std::string path;
@@ -208,8 +210,10 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
208210 public:
209211 DummyIdentityApplier (const RGWUserInfo& user,
210212 std::optional<RGWAccountInfo> account,
211- std::vector<IAM::Policy> policies)
212- : id(user.user_id),
213+ std::vector<IAM::Policy> policies,
214+ sal::Driver* driver)
215+ : driver(driver),
216+ id (user.user_id),
213217 display_name(user.display_name),
214218 path(user.path),
215219 is_admin(user.admin),
@@ -294,9 +298,9 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
294298 << " , is_admin=" << is_admin << " )" ;
295299 }
296300
297- void load_acct_info (const DoutPrefixProvider* dpp,
298- RGWUserInfo& user_info) const override {
301+ auto load_acct_info (const DoutPrefixProvider* dpp) const -> std::unique_ptr<rgw::sal::User> override {
299302 // noop, this user info was passed in on construction
303+ return driver->get_user (id);
300304 }
301305
302306 void modify_request_state (const DoutPrefixProvider* dpp, req_state* s) const {
@@ -307,7 +311,7 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
307311 };
308312
309313 return std::make_unique<DummyIdentityApplier>(
310- user, std::move(account), std::move(policies));
314+ user, std::move(account), std::move(policies), driver );
311315}
312316
313317auto transform_old_authinfo (const DoutPrefixProvider* dpp,
@@ -332,7 +336,7 @@ auto transform_old_authinfo(const DoutPrefixProvider* dpp,
332336 if (policies_) { // return policies to caller if requested
333337 *policies_ = policies;
334338 }
335- return transform_old_authinfo (info, std::move (account), std::move (policies));
339+ return transform_old_authinfo (info, std::move (account), std::move (policies), driver );
336340}
337341
338342} /* namespace auth */
@@ -527,7 +531,7 @@ rgw::auth::Strategy::apply(const DoutPrefixProvider *dpp, const rgw::auth::Strat
527531
528532 /* Account used by a given RGWOp is decoupled from identity employed
529533 * in the authorization phase (RGWOp::verify_permissions). */
530- applier-> load_acct_info (dpp, s->user -> get_info () );
534+ s->user = applier-> load_acct_info (dpp );
531535 s->perm_mask = applier->get_perm_mask ();
532536
533537 /* This is the single place where we pass req_state as a pointer
@@ -635,36 +639,36 @@ void rgw::auth::WebIdentityApplier::create_account(const DoutPrefixProvider* dpp
635639 user_info = user->get_info ();
636640}
637641
638- void rgw::auth::WebIdentityApplier::load_acct_info (const DoutPrefixProvider* dpp, RGWUserInfo& user_info ) const {
642+ auto rgw::auth::WebIdentityApplier::load_acct_info (const DoutPrefixProvider* dpp) const -> std::unique_ptr<rgw::sal::User> {
639643 rgw_user federated_user;
640644 federated_user.id = this ->sub ;
641645 federated_user.tenant = role_tenant;
642646 federated_user.ns = " oidc" ;
643647
648+ std::unique_ptr<rgw::sal::User> user = driver->get_user (federated_user);
644649 if (account) {
645650 // we don't need shadow users for account roles because bucket ownership,
646651 // quota, and stats are tracked by the account instead of the user
647- user_info. user_id = std::move (federated_user );
652+ RGWUserInfo& user_info = user-> get_info ( );
648653 user_info.display_name = user_name;
649654 user_info.type = TYPE_WEB;
650- return ;
655+ // the user_info.user_id is initialized by driver->get_user(...)
656+ return user;
651657 }
652658
653- std::unique_ptr<rgw::sal::User> user = driver->get_user (federated_user);
654-
655659 // Check in oidc namespace
656660 if (user->load_user (dpp, null_yield) >= 0 ) {
657661 /* Succeeded. */
658- user_info = user-> get_info ();
659- return ;
662+ // the user_info in user is initialized by user->load_user(...)
663+ return user ;
660664 }
661665
662666 user->clear_ns ();
663667 // Check for old users which wouldn't have been created in oidc namespace
664668 if (user->load_user (dpp, null_yield) >= 0 ) {
665669 /* Succeeded. */
666- user_info = user-> get_info ();
667- return ;
670+ // the user_info in user is initialized by user->load_user(...)
671+ return user ;
668672 }
669673
670674 // Check if user_id.buckets already exists, may have been from the time, when shadow users didnt exist
@@ -675,7 +679,7 @@ void rgw::auth::WebIdentityApplier::load_acct_info(const DoutPrefixProvider* dpp
675679 last_synced, last_updated);
676680 if (ret < 0 && ret != -ENOENT) {
677681 ldpp_dout (dpp, 0 ) << " ERROR: reading stats for the user returned error " << ret << dendl;
678- return ;
682+ return user ;
679683 }
680684 if (ret == -ENOENT) { /* in case of ENOENT, which means user doesnt have buckets */
681685 // In this case user will be created in oidc namespace
@@ -688,7 +692,8 @@ void rgw::auth::WebIdentityApplier::load_acct_info(const DoutPrefixProvider* dpp
688692 }
689693
690694 ldpp_dout (dpp, 0 ) << " NOTICE: couldn't map oidc federated user " << federated_user << dendl;
691- create_account (dpp, federated_user, this ->user_name , user_info);
695+ create_account (dpp, federated_user, this ->user_name , user->get_info ());
696+ return user;
692697}
693698
694699void rgw::auth::WebIdentityApplier::modify_request_state (const DoutPrefixProvider *dpp, req_state* s) const
@@ -940,7 +945,7 @@ void rgw::auth::RemoteApplier::write_ops_log_entry(rgw_log_entry& entry) const
940945}
941946
942947/* TODO(rzarzynski): we need to handle display_name changes. */
943- void rgw::auth::RemoteApplier::load_acct_info (const DoutPrefixProvider* dpp, RGWUserInfo& user_info ) const /* out */
948+ auto rgw::auth::RemoteApplier::load_acct_info (const DoutPrefixProvider* dpp) const -> std::unique_ptr<rgw::sal::User> /* out */
944949{
945950 /* It's supposed that RGWRemoteAuthApplier tries to load account info
946951 * that belongs to the authenticated identity. Another policy may be
@@ -979,9 +984,9 @@ void rgw::auth::RemoteApplier::load_acct_info(const DoutPrefixProvider* dpp, RGW
979984 (void ) load_account_and_policies (dpp, null_yield, driver, user->get_info (),
980985 user->get_attrs (), account, policies);
981986
982- user_info = std::move (user->get_info ());
983987 owner_acct_user = std::move (tenanted_uid);
984- return ;
988+ // the user_info in user is initialized by user->load_user(...)
989+ return user;
985990 }
986991 }
987992
@@ -994,15 +999,16 @@ void rgw::auth::RemoteApplier::load_acct_info(const DoutPrefixProvider* dpp, RGW
994999 (void ) load_account_and_policies (dpp, null_yield, driver, user->get_info (),
9951000 user->get_attrs (), account, policies);
9961001
997- user_info = std::move (user->get_info ());
9981002 owner_acct_user = acct_user;
999- return ;
1003+ // the user_info in user is initialized by user->load_user(...)
1004+ return user;
10001005 }
10011006
10021007 ldpp_dout (dpp, 0 ) << " NOTICE: couldn't map swift user " << acct_user << dendl;
1003- create_account (dpp, acct_user, implicit_tenant, user_info );
1008+ create_account (dpp, acct_user, implicit_tenant, user-> get_info () );
10041009
10051010 /* Succeeded if we are here (create_account() hasn't throwed). */
1011+ return user;
10061012}
10071013
10081014void rgw::auth::RemoteApplier::modify_request_state (const DoutPrefixProvider* dpp, req_state* s) const
@@ -1102,11 +1108,11 @@ uint32_t rgw::auth::LocalApplier::get_perm_mask(const std::string& subuser_name,
11021108 }
11031109}
11041110
1105- void rgw::auth::LocalApplier::load_acct_info (const DoutPrefixProvider* dpp, RGWUserInfo& user_info ) const /* out */
1111+ auto rgw::auth::LocalApplier::load_acct_info (const DoutPrefixProvider* dpp) const -> std::unique_ptr<rgw::sal::User> /* out */
11061112{
11071113 /* Load the account that belongs to the authenticated identity. An extra call
11081114 * to RADOS may be safely skipped in this case. */
1109- user_info = this -> user_info ;
1115+ return std::unique_ptr<rgw::sal::User>(user. release ()) ;
11101116}
11111117
11121118void rgw::auth::LocalApplier::modify_request_state (const DoutPrefixProvider* dpp, req_state* s) const
@@ -1125,6 +1131,22 @@ void rgw::auth::LocalApplier::write_ops_log_entry(rgw_log_entry& entry) const
11251131 }
11261132}
11271133
1134+ rgw::auth::LocalApplier::LocalApplier (CephContext* const cct,
1135+ std::unique_ptr<rgw::sal::User> user,
1136+ std::optional<RGWAccountInfo> account,
1137+ std::vector<IAM::Policy> policies,
1138+ std::string subuser,
1139+ const std::optional<uint32_t >& perm_mask,
1140+ const std::string access_key_id)
1141+ : user_info(user->get_info ()),
1142+ user(std::move(user)),
1143+ account(std::move(account)),
1144+ policies(std::move(policies)),
1145+ subuser(std::move(subuser)),
1146+ perm_mask(perm_mask.value_or(RGW_PERM_INVALID)),
1147+ access_key_id(access_key_id) {
1148+ }
1149+
11281150ACLOwner rgw::auth::RoleApplier::get_aclowner () const
11291151{
11301152 ACLOwner owner;
@@ -1187,10 +1209,11 @@ bool rgw::auth::RoleApplier::is_identity(const Principal& p) const {
11871209 return false ;
11881210}
11891211
1190- void rgw::auth::RoleApplier::load_acct_info (const DoutPrefixProvider* dpp, RGWUserInfo& user_info ) const /* out */
1212+ auto rgw::auth::RoleApplier::load_acct_info (const DoutPrefixProvider* dpp) const -> std::unique_ptr<rgw::sal::User> /* out */
11911213{
11921214 /* Load the user id */
1193- user_info.user_id = this ->token_attrs .user_id ;
1215+ std::unique_ptr<rgw::sal::User> user = driver->get_user (this ->token_attrs .user_id );
1216+ return user;
11941217}
11951218
11961219void rgw::auth::RoleApplier::write_ops_log_entry (rgw_log_entry& entry) const
@@ -1271,9 +1294,10 @@ rgw::auth::AnonymousEngine::authenticate(const DoutPrefixProvider* dpp, const re
12711294 } else {
12721295 RGWUserInfo user_info;
12731296 rgw_get_anon_user (user_info);
1274-
1297+ std::unique_ptr<rgw::sal::User> user = s->user ->clone ();
1298+ user->get_info () = user_info;
12751299 auto apl = \
1276- apl_factory->create_apl_local (cct, s, user_info , std::nullopt , {},
1300+ apl_factory->create_apl_local (cct, s, std::move (user) , std::nullopt , {},
12771301 rgw::auth::LocalApplier::NO_SUBUSER,
12781302 std::nullopt , rgw::auth::LocalApplier::NO_ACCESS_KEY);
12791303 return result_t::grant (std::move (apl));
0 commit comments