Skip to content

Commit 876bea1

Browse files
clwluvwcbodley
authored andcommitted
rgw: change is_admin_of() to is_admin()
As admin propery of a user is something global and nothing related to any other owner, we don't need any comparision. Signed-off-by: Seena Fallah <[email protected]> (cherry picked from commit 1a253ea)
1 parent 520ac01 commit 876bea1

File tree

12 files changed

+31
-31
lines changed

12 files changed

+31
-31
lines changed

src/rgw/driver/rados/rgw_rest_user.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void RGWOp_User_Info::execute(optional_yield y)
122122
// dump_keys is false if user-info-without-keys is 'read' and
123123
// the user is not the system user or an admin user
124124
int keys_perm = s->user->get_info().caps.check_cap("users", RGW_CAP_READ);
125-
if (keys_perm == 0 || op_state.system || s->auth.identity->is_admin_of(uid)) {
125+
if (keys_perm == 0 || op_state.system || s->auth.identity->is_admin()) {
126126
dump_keys = true;
127127
ldpp_dout(s, 20) << "dump_keys is set to true" << dendl;
128128
}

src/rgw/rgw_auth.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
203203
const rgw_user id;
204204
const std::string display_name;
205205
const std::string path;
206-
const bool is_admin;
206+
const bool user_is_admin;
207207
const uint32_t type;
208208
const std::optional<RGWAccountInfo> account;
209209
const std::vector<IAM::Policy> policies;
@@ -216,7 +216,7 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
216216
id(user.user_id),
217217
display_name(user.display_name),
218218
path(user.path),
219-
is_admin(user.admin),
219+
user_is_admin(user.admin),
220220
type(user.type),
221221
account(std::move(account)),
222222
policies(std::move(policies))
@@ -238,8 +238,8 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
238238
return rgw_perms_from_aclspec_default_strategy(id.to_str(), aclspec, dpp);
239239
}
240240

241-
bool is_admin_of(const rgw_owner& o) const override {
242-
return is_admin;
241+
bool is_admin() const override {
242+
return user_is_admin;
243243
}
244244

245245
bool is_owner_of(const rgw_owner& o) const override {
@@ -302,7 +302,7 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
302302

303303
void to_str(std::ostream& out) const override {
304304
out << "RGWDummyIdentityApplier(auth_id=" << id
305-
<< ", is_admin=" << is_admin << ")";
305+
<< ", is_admin=" << user_is_admin << ")";
306306
}
307307

308308
auto load_acct_info(const DoutPrefixProvider* dpp) const -> std::unique_ptr<rgw::sal::User> override {
@@ -817,7 +817,7 @@ uint32_t rgw::auth::RemoteApplier::get_perms_from_aclspec(const DoutPrefixProvid
817817
return perm;
818818
}
819819

820-
bool rgw::auth::RemoteApplier::is_admin_of(const rgw_owner& o) const
820+
bool rgw::auth::RemoteApplier::is_admin() const
821821
{
822822
return info.is_admin;
823823
}
@@ -1057,7 +1057,7 @@ uint32_t rgw::auth::LocalApplier::get_perms_from_aclspec(const DoutPrefixProvide
10571057
return mask;
10581058
}
10591059

1060-
bool rgw::auth::LocalApplier::is_admin_of(const rgw_owner& o) const
1060+
bool rgw::auth::LocalApplier::is_admin() const
10611061
{
10621062
return user_info.admin || user_info.system;
10631063
}

src/rgw/rgw_auth.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class Identity {
4848
* applier that is being used. */
4949
virtual uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const = 0;
5050

51-
/* Verify whether a given identity *can be treated as* an admin of rgw_owner
52-
* specified in @o. On error throws rgw::auth::Exception storing the reason. */
53-
virtual bool is_admin_of(const rgw_owner& o) const = 0;
51+
/* Verify whether a given identity *can be treated as* an admin.
52+
* On error throws rgw::auth::Exception storing the reason. */
53+
virtual bool is_admin() const = 0;
5454

5555
/* Verify whether a given identity is the rgw_owner specified in @o.
5656
* On internal error throws rgw::auth::Exception storing the reason. */
@@ -480,7 +480,7 @@ class WebIdentityApplier : public IdentityApplier {
480480
return RGW_PERM_NONE;
481481
}
482482

483-
bool is_admin_of(const rgw_owner& o) const override {
483+
bool is_admin() const override {
484484
return false;
485485
}
486486

@@ -664,7 +664,7 @@ class RemoteApplier : public IdentityApplier {
664664

665665
ACLOwner get_aclowner() const override;
666666
uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const override;
667-
bool is_admin_of(const rgw_owner& o) const override;
667+
bool is_admin() const override;
668668
bool is_owner_of(const rgw_owner& o) const override;
669669
bool is_root() const override;
670670
bool is_identity(const Principal& p) const override;
@@ -730,7 +730,7 @@ class LocalApplier : public IdentityApplier {
730730

731731
ACLOwner get_aclowner() const override;
732732
uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const override;
733-
bool is_admin_of(const rgw_owner& o) const override;
733+
bool is_admin() const override;
734734
bool is_owner_of(const rgw_owner& o) const override;
735735
bool is_root() const override;
736736
bool is_identity(const Principal& p) const override;
@@ -813,7 +813,7 @@ class RoleApplier : public IdentityApplier {
813813
uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const override {
814814
return 0;
815815
}
816-
bool is_admin_of(const rgw_owner& o) const override {
816+
bool is_admin() const override {
817817
return false;
818818
}
819819
bool is_owner_of(const rgw_owner& o) const override;
@@ -861,7 +861,7 @@ class ServiceIdentity : public Identity {
861861
return RGW_PERM_NONE;
862862
}
863863

864-
bool is_admin_of(const rgw_owner& o) const override {
864+
bool is_admin() const override {
865865
return false;
866866
}
867867

src/rgw/rgw_auth_filters.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class DecoratedApplier : public rgw::auth::IdentityApplier {
7373
return get_decoratee().get_perms_from_aclspec(dpp, aclspec);
7474
}
7575

76-
bool is_admin_of(const rgw_owner& o) const override {
77-
return get_decoratee().is_admin_of(o);
76+
bool is_admin() const override {
77+
return get_decoratee().is_admin();
7878
}
7979

8080
bool is_owner_of(const rgw_owner& o) const override {
@@ -281,12 +281,12 @@ class SysReqApplier : public DecoratedApplier<T> {
281281
return DecoratedApplier<T>::get_tenant();
282282
}
283283

284-
bool is_admin_of(const rgw_owner& o) const override {
284+
bool is_admin() const override {
285285
if (is_system && !is_impersonating) {
286286
return true;
287287
}
288288

289-
return DecoratedApplier<T>::is_admin_of(o);
289+
return DecoratedApplier<T>::is_admin();
290290
}
291291
};
292292

src/rgw/rgw_lib.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ namespace rgw {
283283
if (ret < 0) {
284284
if (s->system_request) {
285285
ldpp_dout(op, 2) << "overriding permissions due to system operation" << dendl;
286-
} else if (s->auth.identity->is_admin_of(s->user->get_id())) {
286+
} else if (s->auth.identity->is_admin()) {
287287
ldpp_dout(op, 2) << "overriding permissions due to admin operation" << dendl;
288288
} else {
289289
abort_req(s, op, ret);
@@ -420,7 +420,7 @@ namespace rgw {
420420
if (ret < 0) {
421421
if (s->system_request) {
422422
ldpp_dout(op, 2) << "overriding permissions due to system operation" << dendl;
423-
} else if (s->auth.identity->is_admin_of(s->user->get_id())) {
423+
} else if (s->auth.identity->is_admin()) {
424424
ldpp_dout(op, 2) << "overriding permissions due to admin operation" << dendl;
425425
} else {
426426
abort_req(s, op, ret);

src/rgw/rgw_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static int read_obj_policy(const DoutPrefixProvider *dpp,
428428
return ret;
429429
}
430430

431-
if (s->auth.identity->is_admin_of(bucket_policy.get_owner().id)) {
431+
if (s->auth.identity->is_admin()) {
432432
return -ENOENT;
433433
}
434434

@@ -1858,7 +1858,7 @@ int RGWGetObj::read_user_manifest_part(rgw::sal::Bucket* bucket,
18581858
* stored inside different accounts. */
18591859
if (s->system_request) {
18601860
ldpp_dout(this, 2) << "overriding permissions due to system operation" << dendl;
1861-
} else if (s->auth.identity->is_admin_of(s->user->get_id())) {
1861+
} else if (s->auth.identity->is_admin()) {
18621862
ldpp_dout(this, 2) << "overriding permissions due to admin operation" << dendl;
18631863
} else if (!verify_object_permission(this, s, part->get_obj(), s->user_acl,
18641864
bucket_acl, obj_policy, bucket_policy,

src/rgw/rgw_process.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ int rgw_process_authenticated(RGWHandler_REST * const handler,
228228
}
229229
if (ret == -EACCES || ret == -EPERM || ret == -ERR_AUTHORIZATION) {
230230
// system requests may impersonate another user/role for permission checks
231-
// so only rely on is_admin_of() to override permissions
232-
if (s->auth.identity->is_admin_of(s->user->get_id())) {
231+
// so only rely on is_admin() to override permissions
232+
if (s->auth.identity->is_admin()) {
233233
dout(2) << "overriding permissions due to admin operation" << dendl;
234234
} else {
235235
return ret;

src/rgw/rgw_rest_s3.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs,
417417
auto action = s->object->get_instance().empty() ? rgw::IAM::s3GetObjectTagging : rgw::IAM::s3GetObjectVersionTagging;
418418
// since we are already under s->system_request, if the request is not impersonating,
419419
// it can be assumed that it is not a user-mode replication.
420-
bool keep_tags = s->auth.identity->is_admin_of(s->user->get_id()) || verify_object_permission(this, s, action);
420+
bool keep_tags = s->auth.identity->is_admin() || verify_object_permission(this, s, action);
421421

422422
// remove tags from attrs if the user doesn't have permission
423423
bufferlist tags_bl;

src/rgw/rgw_sts.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int Credentials::generateCredentials(const DoutPrefixProvider *dpp,
124124
if (identity) {
125125
token.acct_name = identity->get_acct_name();
126126
token.perm_mask = identity->get_perm_mask();
127-
token.is_admin = identity->is_admin_of(token.user);
127+
token.is_admin = identity->is_admin();
128128
token.acct_type = identity->get_identity_type();
129129
} else {
130130
token.acct_name = {};

src/rgw/rgw_swift_auth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class SwiftAnonymousApplier : public rgw::auth::LocalApplier {
159159
: LocalApplier(cct, std::move(user), std::nullopt, {}, LocalApplier::NO_SUBUSER,
160160
std::nullopt, LocalApplier::NO_ACCESS_KEY) {
161161
}
162-
bool is_admin_of(const rgw_owner& o) const {return false;}
162+
bool is_admin() const {return false;}
163163
bool is_owner_of(const rgw_owner& o) const {
164164
auto* uid = std::get_if<rgw_user>(&o);
165165
return uid && uid->id == RGW_USER_ANON_ID;

0 commit comments

Comments
 (0)