From 9989a86dd7a586d292cae0de32f7723b93147edc Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 7 Dec 2023 16:56:27 -0500 Subject: [PATCH] rgw/auth: initialize s->owner in Strategy::apply() for a common location that applies to all rest handlers that implement authorize() Signed-off-by: Casey Bodley --- src/rgw/rgw_auth.cc | 3 +++ src/rgw/rgw_common.h | 1 + src/rgw/rgw_rest_s3.cc | 11 +---------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_auth.cc b/src/rgw/rgw_auth.cc index 91107c60c99..dcf83599684 100644 --- a/src/rgw/rgw_auth.cc +++ b/src/rgw/rgw_auth.cc @@ -348,6 +348,9 @@ rgw::auth::Strategy::apply(const DoutPrefixProvider *dpp, const rgw::auth::Strat s->auth.identity = std::move(applier); s->auth.completer = std::move(completer); + /* Populate the owner info. */ + s->owner = s->auth.identity->get_aclowner(); + return 0; } catch (const int err) { ldpp_dout(dpp, 5) << "applier throwed err=" << err << dendl; diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index a70b043318d..24392bc0caa 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1138,6 +1138,7 @@ struct req_state : DoutPrefixProvider { std::string src_bucket_name; std::unique_ptr src_object; ACLOwner bucket_owner; + // Resource owner for the authenticated identity, initialized in authorize() ACLOwner owner; std::string zonegroup_name; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 13383b78c33..c2225589216 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3148,9 +3148,6 @@ int RGWPostObj_ObjStore_S3::get_policy(optional_yield y) if (ret != 0) { return -EACCES; } else { - /* Populate the owner info. */ - s->owner.id = s->user->get_id(); - s->owner.display_name = s->user->get_display_name(); ldpp_dout(this, 20) << "Successful Signature Verification!" << dendl; } @@ -5080,13 +5077,7 @@ int RGW_Auth_S3::authorize(const DoutPrefixProvider *dpp, return -EPERM; } - const auto ret = rgw::auth::Strategy::apply(dpp, auth_registry.get_s3_main(), s, y); - if (ret == 0) { - /* Populate the owner info. */ - s->owner.id = s->user->get_id(); - s->owner.display_name = s->user->get_display_name(); - } - return ret; + return rgw::auth::Strategy::apply(dpp, auth_registry.get_s3_main(), s, y); } int RGWHandler_Auth_S3::init(rgw::sal::Driver* driver, req_state *state, -- 2.39.5