Skip to content

Commit 01caaa3

Browse files
committed
rgw/auth: add is_root and is_root_of to identities
The is_root() function helps to make sure the identity is either the root account of the account if there is any ccount linked to the user, or is the user has full control permission. The is_root_of() will check whether whether a given identity is the rgw_owner and is also is_root(). Signed-off-by: Seena Fallah <[email protected]>
1 parent 98fc589 commit 01caaa3

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

src/rgw/rgw_auth.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ static auto transform_old_authinfo(const RGWUserInfo& user,
246246
return match_owner(o, id, account);
247247
}
248248

249+
bool is_root() const override {
250+
if (account)
251+
return get_identity_type() == TYPE_ROOT;
252+
253+
return get_perm_mask() == RGW_PERM_FULL_CONTROL;
254+
}
255+
249256
bool is_identity(const Principal& p) const override {
250257
if (p.is_wildcard()) {
251258
return true;
@@ -838,6 +845,11 @@ bool rgw::auth::RemoteApplier::is_owner_of(const rgw_owner& o) const
838845
return info.acct_user == *uid;
839846
}
840847

848+
bool rgw::auth::RemoteApplier::is_root() const
849+
{
850+
return get_perm_mask() == RGW_PERM_FULL_CONTROL;
851+
}
852+
841853
bool rgw::auth::RemoteApplier::is_identity(const Principal& p) const {
842854
// We also need to cover cases where rgw_keystone_implicit_tenants
843855
// was enabled.
@@ -1062,6 +1074,14 @@ bool rgw::auth::LocalApplier::is_owner_of(const rgw_owner& o) const
10621074
return match_owner(o, user_info.user_id, account);
10631075
}
10641076

1077+
bool rgw::auth::LocalApplier::is_root() const
1078+
{
1079+
if (account)
1080+
return get_identity_type() == TYPE_ROOT;
1081+
1082+
return get_perm_mask() == RGW_PERM_FULL_CONTROL;
1083+
}
1084+
10651085
bool rgw::auth::LocalApplier::is_identity(const Principal& p) const {
10661086
if (p.is_wildcard()) {
10671087
return true;

src/rgw/rgw_auth.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ class Identity {
5656
* On internal error throws rgw::auth::Exception storing the reason. */
5757
virtual bool is_owner_of(const rgw_owner& o) const = 0;
5858

59+
/* Verify whether a given identity is the root user. */
60+
virtual bool is_root() const = 0;
61+
62+
/* Verify whether a given identity is the root user and the owner of the
63+
* rgw_owner specified in @o. */
64+
virtual bool is_root_of(const rgw_owner& o) const {
65+
return is_root() && is_owner_of(o);
66+
}
67+
5968
/* Return the permission mask that is used to narrow down the set of
6069
* operations allowed for a given identity. This method reflects the idea
6170
* of subuser tied to RGWUserInfo. On error throws rgw::auth::Exception
@@ -477,6 +486,10 @@ class WebIdentityApplier : public IdentityApplier {
477486

478487
bool is_owner_of(const rgw_owner& o) const override;
479488

489+
bool is_root() const override {
490+
return false;
491+
}
492+
480493
uint32_t get_perm_mask() const override {
481494
return RGW_PERM_NONE;
482495
}
@@ -653,6 +666,7 @@ class RemoteApplier : public IdentityApplier {
653666
uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const override;
654667
bool is_admin_of(const rgw_owner& o) const override;
655668
bool is_owner_of(const rgw_owner& o) const override;
669+
bool is_root() const override;
656670
bool is_identity(const Principal& p) const override;
657671

658672
uint32_t get_perm_mask() const override { return info.perm_mask; }
@@ -718,6 +732,7 @@ class LocalApplier : public IdentityApplier {
718732
uint32_t get_perms_from_aclspec(const DoutPrefixProvider* dpp, const aclspec_t& aclspec) const override;
719733
bool is_admin_of(const rgw_owner& o) const override;
720734
bool is_owner_of(const rgw_owner& o) const override;
735+
bool is_root() const override;
721736
bool is_identity(const Principal& p) const override;
722737
uint32_t get_perm_mask() const override {
723738
if (this->perm_mask == RGW_PERM_INVALID) {
@@ -798,6 +813,9 @@ class RoleApplier : public IdentityApplier {
798813
return false;
799814
}
800815
bool is_owner_of(const rgw_owner& o) const override;
816+
bool is_root() const override {
817+
return false;
818+
}
801819
bool is_identity(const Principal& p) const override;
802820
uint32_t get_perm_mask() const override {
803821
return RGW_PERM_NONE;

src/rgw/rgw_auth_filters.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ class DecoratedApplier : public rgw::auth::IdentityApplier {
8181
return get_decoratee().is_owner_of(o);
8282
}
8383

84+
bool is_root() const override {
85+
return get_decoratee().is_root();
86+
}
87+
8488
bool is_anonymous() const override {
8589
return get_decoratee().is_anonymous();
8690
}

src/test/rgw/test_rgw_iam_policy.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ class FakeIdentity : public Identity {
168168
return false;
169169
}
170170

171+
bool is_root() const override {
172+
ceph_abort();
173+
return false;
174+
}
175+
171176
virtual uint32_t get_perm_mask() const override {
172177
ceph_abort();
173178
return 0;

src/test/rgw/test_rgw_lua.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class FakeIdentity : public Identity {
5050
return false;
5151
}
5252

53+
bool is_root() const override {
54+
return false;
55+
}
56+
5357
virtual uint32_t get_perm_mask() const override {
5458
return 0;
5559
}

0 commit comments

Comments
 (0)