]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: deny 'account rm' if not empty
authorCasey Bodley <cbodley@redhat.com>
Sat, 24 Feb 2024 21:32:53 +0000 (16:32 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 12 Apr 2024 19:34:29 +0000 (15:34 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit a4a3cf07cc7eacfdac9870c3b2bb6545b58b3603)

src/rgw/rgw_account.cc

index dc280ad87a4cd1c208257b493a6ad43cdaceb457..8afd42191f50af674cb3b379b5e1dd1b41fa581f 100644 (file)
@@ -21,6 +21,8 @@
 #include "common/random_string.h"
 #include "common/utf8.h"
 
+#include "rgw_oidc_provider.h"
+#include "rgw_role.h"
 #include "rgw_sal.h"
 
 #define dout_subsys ceph_subsys_rgw
@@ -279,6 +281,66 @@ int remove(const DoutPrefixProvider* dpp,
     return ret;
   }
 
+  // make sure the account is empty
+  constexpr std::string_view path_prefix; // empty
+  const std::string marker; // empty
+  constexpr uint32_t max_items = 1;
+
+  rgw::sal::UserList users;
+  ret = driver->list_account_users(dpp, y, info.id, info.tenant, path_prefix,
+                                   marker, max_items, users);
+  if (ret < 0) {
+    return ret;
+  }
+  if (!users.users.empty()) {
+    err_msg = "The account cannot be deleted until all users are removed.";
+    return -ENOTEMPTY;
+  }
+
+  constexpr bool need_stats = false;
+  rgw::sal::BucketList buckets;
+  ret = driver->list_buckets(dpp, info.id, info.tenant, marker, marker,
+                             max_items, need_stats, buckets, y);
+  if (ret < 0) {
+    return ret;
+  }
+  if (!buckets.buckets.empty()) {
+    err_msg = "The account cannot be deleted until all buckets are removed.";
+    return -ENOTEMPTY;
+  }
+
+  rgw::sal::RoleList roles;
+  ret = driver->list_account_roles(dpp, y, info.id, path_prefix,
+                                   marker, max_items, roles);
+  if (ret < 0) {
+    return ret;
+  }
+  if (!roles.roles.empty()) {
+    err_msg = "The account cannot be deleted until all roles are removed.";
+    return -ENOTEMPTY;
+  }
+
+  rgw::sal::GroupList groups;
+  ret = driver->list_account_groups(dpp, y, info.id, path_prefix,
+                                    marker, max_items, groups);
+  if (ret < 0) {
+    return ret;
+  }
+  if (!groups.groups.empty()) {
+    err_msg = "The account cannot be deleted until all groups are removed.";
+    return -ENOTEMPTY;
+  }
+
+  std::vector<RGWOIDCProviderInfo> providers;
+  ret = driver->get_oidc_providers(dpp, y, info.id, providers);
+  if (ret < 0) {
+    return ret;
+  }
+  if (!providers.empty()) {
+    err_msg = "The account cannot be deleted until all OpenIDConnectProviders are removed.";
+    return -ENOTEMPTY;
+  }
+
   return driver->delete_account(dpp, y, info, objv);
 }