]> git.proxmox.com Git - qemu-server.git/commitdiff
reassign disk: fix permission checks
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 10 Nov 2021 10:20:20 +0000 (11:20 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 10 Nov 2021 10:49:36 +0000 (11:49 +0100)
with `storage` being optional (and not allowed for reassign operations),
the ACL path in the schema can end up as `/storage/-`, which is wrong.
replace it with an explicit check:

- target `storage` for move disk
- storage from source disk for reassign disk (we only rename here, but
  it's still a new volume on that storage after all)

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
PVE/API2/Qemu.pm

index c3cbf9495c20e14c58e95d5c241a1c9ad1d6433b..df8d946f3a0d529a4c636ed69ced500d11646101 100644 (file)
@@ -3288,10 +3288,7 @@ __PACKAGE__->register_method({
        description => "You need 'VM.Config.Disk' permissions on /vms/{vmid}, " .
            "and 'Datastore.AllocateSpace' permissions on the storage. To move ".
            "a disk to another VM, you need the permissions on the target VM as well.",
-       check => [ 'and',
-                  ['perm', '/vms/{vmid}', [ 'VM.Config.Disk' ]],
-                  ['perm', '/storage/{storage}', [ 'Datastore.AllocateSpace' ]],
-           ],
+       check => ['perm', '/vms/{vmid}', [ 'VM.Config.Disk' ]],
     },
     parameters => {
        additionalProperties => 0,
@@ -3381,8 +3378,7 @@ __PACKAGE__->register_method({
            my $conf = PVE::QemuConfig->load_config($vmid);
            PVE::QemuConfig->check_lock($conf);
 
-           die "VM config checksum missmatch (file change by other user?)\n"
-               if $digest && $digest ne $conf->{digest};
+           PVE::Tools::assert_if_modified($digest, $conf->{digest});
 
            die "disk '$disk' does not exist\n" if !$conf->{$disk};
 
@@ -3649,7 +3645,10 @@ __PACKAGE__->register_method({
            raise_param_exc({ 'target-vmid' => "must be different than source VMID to reassign disk" })
                if $vmid eq $target_vmid;
 
-           &$load_and_check_reassign_configs();
+           my (undef, undef, $drive) = &$load_and_check_reassign_configs();
+           my $storeid = PVE::Storage::parse_volume_id($drive->{file});
+           $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
+
            return $rpcenv->fork_worker(
                'qmmove',
                "${vmid}-${disk}>${target_vmid}-${target_disk}",
@@ -3657,6 +3656,8 @@ __PACKAGE__->register_method({
                $disk_reassignfn
            );
        } elsif ($storeid) {
+           $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
+
            die "cannot move disk '$disk', only configured disks can be moved to another storage\n"
                if $disk =~ m/^unused\d+$/;
            return PVE::QemuConfig->lock_config($vmid, $move_updatefn);