Skip to content

Commit 5005144

Browse files
authored
Fix the store deletion ownership check (#8464)
* Fix the store deletion ownership check * Handle cases in which a pool has no owner * Change error type Signed-off-by: Ben <belimele@redhat.com>
1 parent b098403 commit 5005144

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/server/system_services/pool_server.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ function set_pool_controller_factory(pool_controller_factory) {
9292
// and only allows deletion in case that the owner is also the requester of the deletion
9393
function check_deletion_ownership(req, resource_owner_id) {
9494
if (config.RESTRICT_RESOURCE_DELETION) {
95+
if (!resource_owner_id) {
96+
dbg.error('check_deletion_ownership: pool has no owner');
97+
throw new RpcError('INTERNAL_ERROR', 'The pool has no owner, and thus cannot be deleted');
98+
}
9599
const requester_is_sys_owner = String(req.account._id) === String(req.system.owner._id);
96100
if (!requester_is_sys_owner && String(resource_owner_id) !== String(req.account._id)) {
97101
dbg.error('check_deletion_ownership: requester (', req.account._id, ') is not the owner (', resource_owner_id, ') of the resource');
@@ -652,7 +656,9 @@ async function update_hosts_pool(req) {
652656

653657
function delete_pool(req) {
654658
const pool = find_pool_by_name(req);
655-
check_deletion_ownership(req, pool.owner_id);
659+
// rebuild_object_links() resolves the pool's owner_id to the account object
660+
// which is why we have to access ._id to get the actual ID
661+
check_deletion_ownership(req, pool.owner_id?._id);
656662
if (pool.hosts_pool_info) {
657663
return delete_hosts_pool(req, pool);
658664
} else {
@@ -662,7 +668,7 @@ function delete_pool(req) {
662668

663669
function delete_namespace_resource(req) {
664670
const ns = find_namespace_resource_by_name(req);
665-
check_deletion_ownership(req, ns.account);
671+
check_deletion_ownership(req, ns.account._id);
666672
dbg.log0('Deleting namespace resource', ns.name);
667673
return P.resolve()
668674
.then(() => {

0 commit comments

Comments
 (0)