]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/rest: enable iam UserPolicy apis against account users
authorCasey Bodley <cbodley@redhat.com>
Thu, 11 Jan 2024 23:45:55 +0000 (18:45 -0500)
committerCasey Bodley <cbodley@redhat.com>
Wed, 10 Apr 2024 17:09:15 +0000 (13:09 -0400)
when the authenticated user belongs to an account:
* operate only on that account's users
* match UserName to user's display_name instead of user_id

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_rest_user_policy.cc
src/rgw/rgw_rest_user_policy.h

index 6ef3ab04a1718a7653ebdc37753c70f5fcfdd5e4..e452369ccb7a2d5b10b9b37d41dc19bb6649c88f 100644 (file)
@@ -52,16 +52,36 @@ int RGWRestUserPolicy::init_processing(optional_yield y)
     return r;
   }
 
-  // interpret UserName as a uid with optional tenant
-  const auto uid = rgw_user{user_name};
-  // user ARN includes tenant and user id
-  user_arn = rgw::ARN{uid.id, "user", uid.tenant};
-
-  user = driver->get_user(uid);
-  r = user->load_user(this, y);
-  if (r == -ENOENT) {
-    s->err.message = "No such UserName in the tenant";
-    return -ERR_NO_SUCH_ENTITY;
+  if (const auto* id = std::get_if<rgw_account_id>(&s->owner.id); id) {
+    account_id = *id;
+
+    // look up account user by UserName
+    const std::string& tenant = s->auth.identity->get_tenant();
+    r = driver->load_account_user_by_name(this, y, account_id,
+                                          tenant, user_name, &user);
+
+    if (r == -ENOENT) {
+      s->err.message = "No such UserName in the account";
+      return -ERR_NO_SUCH_ENTITY;
+    }
+    if (r >= 0) {
+      // user ARN includes account id, path, and display name
+      const RGWUserInfo& info = user->get_info();
+      const std::string resource = string_cat_reserve(info.path, info.display_name);
+      user_arn = rgw::ARN{resource, "user", account_id, true};
+    }
+  } else {
+    // interpret UserName as a uid with optional tenant
+    const auto uid = rgw_user{user_name};
+    // user ARN includes tenant and user id
+    user_arn = rgw::ARN{uid.id, "user", uid.tenant};
+
+    user = driver->get_user(uid);
+    r = user->load_user(this, y);
+    if (r == -ENOENT) {
+      s->err.message = "No such UserName in the tenant";
+      return -ERR_NO_SUCH_ENTITY;
+    }
   }
 
   return r;
@@ -78,6 +98,7 @@ int RGWRestUserPolicy::verify_permission(optional_yield y)
     return -EACCES;
   }
 
+  // admin caps are required for non-account users
   if (check_caps(s->user->get_caps()) == 0) {
     return 0;
   }
index d14d2f5157392f946654a9995c95fc206c92f5fe..681dfd80065cee62d0fa01d4ae8c1e8b2d6425a8 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "rgw_arn.h"
 #include "rgw_rest.h"
+#include "rgw_user_types.h"
 #include "rgw_sal_fwd.h"
 
 class RGWRestUserPolicy : public RGWRESTOp {
@@ -13,6 +14,7 @@ protected:
 
   uint64_t action;
   uint32_t perm;
+  rgw_account_id account_id;
   std::unique_ptr<rgw::sal::User> user;
   rgw::ARN user_arn;
   std::string policy_name;