@@ -188,7 +188,8 @@ int load_account_and_policies(const DoutPrefixProvider* dpp,
188
188
189
189
static auto transform_old_authinfo (const RGWUserInfo& user,
190
190
std::optional<RGWAccountInfo> account,
191
- std::vector<IAM::Policy> policies)
191
+ std::vector<IAM::Policy> policies,
192
+ sal::Driver* driver)
192
193
-> std::unique_ptr<rgw::auth::Identity>
193
194
{
194
195
/* This class is not intended for public use. Should be removed altogether
@@ -198,6 +199,7 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
198
199
/* For this particular case it's OK to use rgw_user structure to convey
199
200
* the identity info as this was the policy for doing that before the
200
201
* new auth. */
202
+ sal::Driver* driver;
201
203
const rgw_user id;
202
204
const std::string display_name;
203
205
const std::string path;
@@ -208,8 +210,10 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
208
210
public:
209
211
DummyIdentityApplier (const RGWUserInfo& user,
210
212
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),
213
217
display_name(user.display_name),
214
218
path(user.path),
215
219
is_admin(user.admin),
@@ -294,9 +298,9 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
294
298
<< " , is_admin=" << is_admin << " )" ;
295
299
}
296
300
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 {
299
302
// noop, this user info was passed in on construction
303
+ return driver->get_user (id);
300
304
}
301
305
302
306
void modify_request_state (const DoutPrefixProvider* dpp, req_state* s) const {
@@ -307,7 +311,7 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
307
311
};
308
312
309
313
return std::make_unique<DummyIdentityApplier>(
310
- user, std::move(account), std::move(policies));
314
+ user, std::move(account), std::move(policies), driver );
311
315
}
312
316
313
317
auto transform_old_authinfo (const DoutPrefixProvider* dpp,
@@ -332,7 +336,7 @@ auto transform_old_authinfo(const DoutPrefixProvider* dpp,
332
336
if (policies_) { // return policies to caller if requested
333
337
*policies_ = policies;
334
338
}
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 );
336
340
}
337
341
338
342
} /* namespace auth */
@@ -527,7 +531,7 @@ rgw::auth::Strategy::apply(const DoutPrefixProvider *dpp, const rgw::auth::Strat
527
531
528
532
/* Account used by a given RGWOp is decoupled from identity employed
529
533
* 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 );
531
535
s->perm_mask = applier->get_perm_mask ();
532
536
533
537
/* 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
635
639
user_info = user->get_info ();
636
640
}
637
641
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> {
639
643
rgw_user federated_user;
640
644
federated_user.id = this ->sub ;
641
645
federated_user.tenant = role_tenant;
642
646
federated_user.ns = " oidc" ;
643
647
648
+ std::unique_ptr<rgw::sal::User> user = driver->get_user (federated_user);
644
649
if (account) {
645
650
// we don't need shadow users for account roles because bucket ownership,
646
651
// 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 ( );
648
653
user_info.display_name = user_name;
649
654
user_info.type = TYPE_WEB;
650
- return ;
655
+ // the user_info.user_id is initialized by driver->get_user(...)
656
+ return user;
651
657
}
652
658
653
- std::unique_ptr<rgw::sal::User> user = driver->get_user (federated_user);
654
-
655
659
// Check in oidc namespace
656
660
if (user->load_user (dpp, null_yield) >= 0 ) {
657
661
/* Succeeded. */
658
- user_info = user-> get_info ();
659
- return ;
662
+ // the user_info in user is initialized by user->load_user(...)
663
+ return user ;
660
664
}
661
665
662
666
user->clear_ns ();
663
667
// Check for old users which wouldn't have been created in oidc namespace
664
668
if (user->load_user (dpp, null_yield) >= 0 ) {
665
669
/* Succeeded. */
666
- user_info = user-> get_info ();
667
- return ;
670
+ // the user_info in user is initialized by user->load_user(...)
671
+ return user ;
668
672
}
669
673
670
674
// 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
675
679
last_synced, last_updated);
676
680
if (ret < 0 && ret != -ENOENT) {
677
681
ldpp_dout (dpp, 0 ) << " ERROR: reading stats for the user returned error " << ret << dendl;
678
- return ;
682
+ return user ;
679
683
}
680
684
if (ret == -ENOENT) { /* in case of ENOENT, which means user doesnt have buckets */
681
685
// In this case user will be created in oidc namespace
@@ -688,7 +692,8 @@ void rgw::auth::WebIdentityApplier::load_acct_info(const DoutPrefixProvider* dpp
688
692
}
689
693
690
694
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;
692
697
}
693
698
694
699
void 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
940
945
}
941
946
942
947
/* 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 */
944
949
{
945
950
/* It's supposed that RGWRemoteAuthApplier tries to load account info
946
951
* 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
979
984
(void ) load_account_and_policies (dpp, null_yield, driver, user->get_info (),
980
985
user->get_attrs (), account, policies);
981
986
982
- user_info = std::move (user->get_info ());
983
987
owner_acct_user = std::move (tenanted_uid);
984
- return ;
988
+ // the user_info in user is initialized by user->load_user(...)
989
+ return user;
985
990
}
986
991
}
987
992
@@ -994,15 +999,16 @@ void rgw::auth::RemoteApplier::load_acct_info(const DoutPrefixProvider* dpp, RGW
994
999
(void ) load_account_and_policies (dpp, null_yield, driver, user->get_info (),
995
1000
user->get_attrs (), account, policies);
996
1001
997
- user_info = std::move (user->get_info ());
998
1002
owner_acct_user = acct_user;
999
- return ;
1003
+ // the user_info in user is initialized by user->load_user(...)
1004
+ return user;
1000
1005
}
1001
1006
1002
1007
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 () );
1004
1009
1005
1010
/* Succeeded if we are here (create_account() hasn't throwed). */
1011
+ return user;
1006
1012
}
1007
1013
1008
1014
void 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,
1102
1108
}
1103
1109
}
1104
1110
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 */
1106
1112
{
1107
1113
/* Load the account that belongs to the authenticated identity. An extra call
1108
1114
* 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 ()) ;
1110
1116
}
1111
1117
1112
1118
void 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
1125
1131
}
1126
1132
}
1127
1133
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
+
1128
1150
ACLOwner rgw::auth::RoleApplier::get_aclowner () const
1129
1151
{
1130
1152
ACLOwner owner;
@@ -1187,10 +1209,11 @@ bool rgw::auth::RoleApplier::is_identity(const Principal& p) const {
1187
1209
return false ;
1188
1210
}
1189
1211
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 */
1191
1213
{
1192
1214
/* 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;
1194
1217
}
1195
1218
1196
1219
void 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
1271
1294
} else {
1272
1295
RGWUserInfo user_info;
1273
1296
rgw_get_anon_user (user_info);
1274
-
1297
+ std::unique_ptr<rgw::sal::User> user = s->user ->clone ();
1298
+ user->get_info () = user_info;
1275
1299
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, {},
1277
1301
rgw::auth::LocalApplier::NO_SUBUSER,
1278
1302
std::nullopt, rgw::auth::LocalApplier::NO_ACCESS_KEY);
1279
1303
return result_t::grant (std::move (apl));
0 commit comments