]> git.proxmox.com Git - pve-manager.git/commitdiff
Fix #2053: OSD destroy only on specified node
authorDominic Jäger <d.jaeger@proxmox.com>
Mon, 11 Jan 2021 11:42:58 +0000 (12:42 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 20 Apr 2021 14:42:12 +0000 (16:42 +0200)
Allow destroying only OSDs that belong to the node that has been specified in
the API path.

So if
 - OSD 1 belongs to node A and
 - OSD 2 belongs to node B
then
 - pvesh delete nodes/A/ceph/osd/1 is allowed but
 - pvesh delete nodes/A/ceph/osd/2 is not

Destroying an OSD via GUI automatically inserts the correct node
into the API path.

pveceph automatically insert the local node into the API call, too.
Consequently, it can now only destroy local OSDs (fix #2053).
 - pveceph osd destroy 1 is allowed on node A but
 - pveceph osd destroy 2 is not

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
PVE/API2/Ceph/OSD.pm

index b81a80549f42eccb0e227734335db56df8715dc6..6763e95b93e400f7c598697b978c89a5f83903a3 100644 (file)
@@ -478,6 +478,22 @@ __PACKAGE__->register_method ({
        return $rpcenv->fork_worker('cephcreateosd', $devname,  $authuser, $worker);
     }});
 
+# Check if $osdid belongs to $nodename
+# $tree ... rados osd tree (passing the tree makes it easy to test)
+sub osd_belongs_to_node {
+    my ($tree, $nodename, $osdid) = @_;
+
+    die "No tree nodes found\n" if !($tree && $tree->{nodes});
+    my $allNodes = $tree->{nodes};
+
+    my @match = grep($_->{name} eq $nodename, @$allNodes);
+    my $node = shift @match; # contains rados information about $nodename
+    die "There must not be more than one such node in the list" if @match;
+
+    my $osds = $node->{children};
+    return grep($_ == $osdid, @$osds);
+}
+
 __PACKAGE__->register_method ({
     name => 'destroyosd',
     path => '{osdid}',
@@ -515,6 +531,15 @@ __PACKAGE__->register_method ({
        my $cleanup = $param->{cleanup};
 
        my $rados = PVE::RADOS->new();
+
+       my $osd_belongs_to_node = osd_belongs_to_node(
+           $rados->mon_command({ prefix => 'osd tree' }),
+           $param->{node},
+           $osdid,
+       );
+       die "OSD osd.$osdid does not belong to node $param->{node}!"
+           if !$osd_belongs_to_node;
+
        # dies if osdid is unknown
        my $osdstat = $get_osd_status->($rados, $osdid);