From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 58CBA61E2F for ; Thu, 10 Feb 2022 16:29:46 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 56B661F181 for ; Thu, 10 Feb 2022 16:29:46 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 703EC1F178 for ; Thu, 10 Feb 2022 16:29:44 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4A50846DCB for ; Thu, 10 Feb 2022 16:29:44 +0100 (CET) Date: Thu, 10 Feb 2022 16:29:36 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20220208131011.752134-1-o.bektas@proxmox.com> <20220208131011.752134-6-o.bektas@proxmox.com> In-Reply-To: <<20220208131011.752134-6-o.bektas@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1644502029.ym22kzn5hp.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.194 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, qemu.pm] Subject: Re: [pve-devel] [PATCH v1 qemu-server 5/5] add SuperUser privilege checks for root-only options X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Feb 2022 15:29:46 -0000 this needs a rebase anyhow, I reviewed it on HEAD~3 where it still=20 applies ;) there's one check for 'root@pam' that looks okay same for the one in the move disk API endpoint it might be worth it to mention that you checked those and not switched=20 them to superuser since they are only a shortcut for skipping the=20 permission check for root, and not limiting access to some root-only=20 action (or maybe even add a comment so that future people looking at it=20 don't have to remember that). On February 8, 2022 2:10 pm, Oguz Bektas wrote: > analogous to the changes in container. >=20 > we now allow users with SU privilege to edit real device configurations, > provided that they also have the necessary VM privileges. >=20 > note that root@pam is still able to do everything as usual >=20 > --- > PVE/API2/Qemu.pm | 119 +++++++++++++++++++++++++++++------------------ > 1 file changed, 73 insertions(+), 46 deletions(-) >=20 > diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm > index 6992f6f..9d403b4 100644 > --- a/PVE/API2/Qemu.pm > +++ b/PVE/API2/Qemu.pm > @@ -352,7 +352,7 @@ my $cloudinitoptions =3D { > my $check_vm_create_serial_perm =3D sub { > my ($rpcenv, $authuser, $vmid, $pool, $param) =3D @_; > =20 > - return 1 if $authuser eq 'root@pam'; > + return 1 if $authuser eq 'root@pam' || $rpcenv->check($authuser, "/v= ms/$vmid", ['SuperUser'], 1); nope - this still needs to check VM.Config.HWType in the SuperUser=20 case.. e.g., should look like this: my $check_vm_create_serial_perm =3D sub { my ($rpcenv, $authuser, $vmid, $pool, $param) =3D @_; return 1 if $authuser eq 'root@pam'; my $is_superuser =3D $rpcenv->check($authuser, "/vms/$vmid", ['SuperUse= r'], 1); foreach my $opt (keys %{$param}) { next if $opt !~ m/^serial\d+$/; $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.HWType']); die "only superusers can set '$opt' config for real devices\n" if !($param->{$opt} eq 'socket' || $is_superuser); } return 1; }; > =20 > foreach my $opt (keys %{$param}) { > next if $opt !~ m/^serial\d+$/; > @@ -370,7 +370,7 @@ my $check_vm_create_serial_perm =3D sub { > my $check_vm_create_usb_perm =3D sub { > my ($rpcenv, $authuser, $vmid, $pool, $param) =3D @_; > =20 > - return 1 if $authuser eq 'root@pam'; > + return 1 if $authuser eq 'root@pam' || $rpcenv->check($authuser, "/v= ms/$vmid", ['SuperUser'], 1); same here, but with spice instead of socket > =20 > foreach my $opt (keys %{$param}) { > next if $opt !~ m/^usb\d+$/; > @@ -388,7 +388,7 @@ my $check_vm_create_usb_perm =3D sub { > my $check_vm_modify_config_perm =3D sub { > my ($rpcenv, $authuser, $vmid, $pool, $key_list) =3D @_; > =20 > - return 1 if $authuser eq 'root@pam'; > + return 1 if $authuser eq 'root@pam' || $rpcenv->check($authuser, "/v= ms/$vmid", ['SuperUser'], 1); completely wrong, like in pve-container! this effectively skips most=20 checks for SuperUser, instead of only skipping the root-only parts.. only the else part of $check_vm_modify_config_perm should check for=20 superuser and die otherwise.. > =20 > foreach my $opt (@$key_list) { > # some checks (e.g., disk, serial port, usb) need to be done somewhere > @@ -1117,9 +1117,10 @@ my $update_vm_api =3D sub { > push @paramarr, "-$key", $value; > } > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($auth= user, "/vms/$vmid", ['SuperUser'], 1); > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option= ." }) > + if $skiplock && !$is_superuser; > =20 > my $delete_str =3D extract_param($param, 'delete'); > =20 > @@ -1340,16 +1341,18 @@ my $update_vm_api =3D sub { > } elsif ($opt =3D~ m/^serial\d+$/) { > if ($val eq 'socket') { > $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > - } elsif ($authuser ne 'root@pam') { > - die "only root can delete '$opt' config for real devices\n"; > + } elsif (!$is_superuser) { > + die "only superusers can delete '$opt' config for real devices\n" > + if !$rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.H= WType']); same as with check_vm_create_serial_perm above.. > } > PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force); > PVE::QemuConfig->write_config($vmid, $conf); > } elsif ($opt =3D~ m/^usb\d+$/) { > if ($val =3D~ m/spice/) { > $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > - } elsif ($authuser ne 'root@pam') { > - die "only root can delete '$opt' config for real devices\n"; > + } elsif (!$is_superuser) { > + die "only superusers can delete '$opt' config for real devices\n" > + if !$rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.H= WType']); also same, but with check_vm_create_usb_perm.. > } > PVE::QemuConfig->add_to_pending_delete($conf, $opt, $force); > PVE::QemuConfig->write_config($vmid, $conf); > @@ -1392,15 +1395,17 @@ my $update_vm_api =3D sub { > } elsif ($opt =3D~ m/^serial\d+/) { > if ((!defined($conf->{$opt}) || $conf->{$opt} eq 'socket') && $par= am->{$opt} eq 'socket') { > $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > - } elsif ($authuser ne 'root@pam') { > - die "only root can modify '$opt' config for real devices\n"; > + } elsif (!$is_superuser) { > + die "only superuser can modify '$opt' config for real devices\n" > + if !$rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.H= WType']); again > } > $conf->{pending}->{$opt} =3D $param->{$opt}; > } elsif ($opt =3D~ m/^usb\d+/) { > if ((!defined($conf->{$opt}) || $conf->{$opt} =3D~ m/spice/) && $p= aram->{$opt} =3D~ m/spice/) { > $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.HWType'])= ; > - } elsif ($authuser ne 'root@pam') { > - die "only root can modify '$opt' config for real devices\n"; > + } elsif (!$is_superuser) { > + die "only superuser can modify '$opt' config for real devices\n" > + if !$rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.H= WType']); again > } > $conf->{pending}->{$opt} =3D $param->{$opt}; > } else { > @@ -1644,9 +1649,11 @@ __PACKAGE__->register_method({ > my $authuser =3D $rpcenv->get_user(); > my $vmid =3D $param->{vmid}; > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D $param->{skiplock}; > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option." = }) > + if $skiplock && !$is_superuser; > =20 > my $early_checks =3D sub { > # test if VM exists > @@ -2291,10 +2298,12 @@ __PACKAGE__->register_method({ > my $machine =3D extract_param($param, 'machine'); > my $force_cpu =3D extract_param($param, 'force-cpu'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $get_root_param =3D sub { > my $value =3D extract_param($param, $_[0]); > - raise_param_exc({ "$_[0]" =3D> "Only root may use this option." }) > - if $value && $authuser ne 'root@pam'; > + raise_param_exc({ "$_[0]" =3D> "Only superusers may use this option= ." }) > + if $value && !$is_superuser; > return $value; this isn't 100% correct either - most of these are migration-internal=20 parameters (which are only ever supposed to be set when called via SSH=20 via `qm`, which runs as root@pam anyway) skiplock can switch to being superuser-limited, the rest should stay=20 root@pam.. > }; > =20 > @@ -2436,17 +2445,19 @@ __PACKAGE__->register_method({ > my $node =3D extract_param($param, 'node'); > my $vmid =3D extract_param($param, 'vmid'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option." = }) > + if $skiplock && !$is_superuser; > =20 > my $keepActive =3D extract_param($param, 'keepActive'); > - raise_param_exc({ keepActive =3D> "Only root may use this option." }) > - if $keepActive && $authuser ne 'root@pam'; > + raise_param_exc({ keepActive =3D> "Only superusers may use this option.= " }) > + if $keepActive && !$is_superuser; same here - internal param only set in vzdump context > =20 > my $migratedfrom =3D extract_param($param, 'migratedfrom'); > - raise_param_exc({ migratedfrom =3D> "Only root may use this option." }) > - if $migratedfrom && $authuser ne 'root@pam'; > + raise_param_exc({ migratedfrom =3D> "Only superusers may use this optio= n." }) > + if $migratedfrom && !$is_superuser; and this one is again only set when stopping the target VM during=20 migration (via ssh, via qm, so always root). > =20 > =20 > my $storecfg =3D PVE::Storage::config(); > @@ -2513,9 +2524,11 @@ __PACKAGE__->register_method({ > =20 > my $vmid =3D extract_param($param, 'vmid'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option." = }) > + if $skiplock && !$is_superuser; > =20 > die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid); > =20 > @@ -2580,13 +2593,15 @@ __PACKAGE__->register_method({ > my $node =3D extract_param($param, 'node'); > my $vmid =3D extract_param($param, 'vmid'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option." = }) > + if $skiplock && !$is_superuser; > =20 > my $keepActive =3D extract_param($param, 'keepActive'); > - raise_param_exc({ keepActive =3D> "Only root may use this option." }) > - if $keepActive && $authuser ne 'root@pam'; > + raise_param_exc({ keepActive =3D> "Only superusers may use this option.= " }) > + if $keepActive && !$is_superuser; same as above - AFAICT this is vzdump only.. > =20 > my $storecfg =3D PVE::Storage::config(); > =20 > @@ -2739,9 +2754,11 @@ __PACKAGE__->register_method({ > =20 > my $statestorage =3D extract_param($param, 'statestorage'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option." = }) > + if $skiplock && !$is_superuser; > =20 > die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid); > =20 > @@ -2811,13 +2828,15 @@ __PACKAGE__->register_method({ > =20 > my $vmid =3D extract_param($param, 'vmid'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option." = }) > + if $skiplock && !$is_superuser; > =20 > my $nocheck =3D extract_param($param, 'nocheck'); > - raise_param_exc({ nocheck =3D> "Only root may use this option." }) > - if $nocheck && $authuser ne 'root@pam'; > + raise_param_exc({ nocheck =3D> "Only superusers may use this option." }= ) > + if $nocheck && !$is_superuser; this is also migration only (for resuming while the config is still on=20 the source node) > =20 > my $to_disk_suspended; > eval { > @@ -2883,9 +2902,11 @@ __PACKAGE__->register_method({ > =20 > my $vmid =3D extract_param($param, 'vmid'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option." }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this option." = }) > + if $skiplock && !$is_superuser; > =20 > PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key}); > =20 > @@ -3392,6 +3413,8 @@ __PACKAGE__->register_method({ > =20 > my $storecfg =3D PVE::Storage::config(); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); not used? > + > my $move_updatefn =3D sub { > my $conf =3D PVE::QemuConfig->load_config($vmid); > PVE::QemuConfig->check_lock($conf); > @@ -3856,7 +3879,7 @@ __PACKAGE__->register_method({ > }, > force =3D> { > type =3D> 'boolean', > - description =3D> "Allow to migrate VMs which use local devices. Only r= oot may use this option.", > + description =3D> "Allow to migrate VMs which use local devices. Only s= uperusers may use this option.", > optional =3D> 1, > }, > migration_type =3D> { > @@ -3910,15 +3933,17 @@ __PACKAGE__->register_method({ > =20 > my $vmid =3D extract_param($param, 'vmid'); > =20 > - raise_param_exc({ force =3D> "Only root may use this option." }) > - if $param->{force} && $authuser ne 'root@pam'; > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > =20 > - raise_param_exc({ migration_type =3D> "Only root may use this option." = }) > - if $param->{migration_type} && $authuser ne 'root@pam'; > + raise_param_exc({ force =3D> "Only superusers may use this option." }) > + if $param->{force} && !$is_superuser; > + > + raise_param_exc({ migration_type =3D> "Only superusers may use this opt= ion." }) > + if $param->{migration_type} && !$is_superuser; > =20 > # allow root only until better network permissions are available > - raise_param_exc({ migration_network =3D> "Only root may use this option= ." }) > - if $param->{migration_network} && $authuser ne 'root@pam'; > + raise_param_exc({ migration_network =3D> "Only superusers may use this = option." }) > + if $param->{migration_network} && !$is_superuser; > =20 > # test if VM exists > my $conf =3D PVE::QemuConfig->load_config($vmid); > @@ -4098,9 +4123,11 @@ __PACKAGE__->register_method({ > =20 > my $sizestr =3D extract_param($param, 'size'); > =20 > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); > + > my $skiplock =3D extract_param($param, 'skiplock'); > - raise_param_exc({ skiplock =3D> "Only root may use this option."= }) > - if $skiplock && $authuser ne 'root@pam'; > + raise_param_exc({ skiplock =3D> "Only superusers may use this op= tion." }) > + if $skiplock && !$is_superuser; > =20 > my $storecfg =3D PVE::Storage::config(); > =20 > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20