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 3FBC28BA8 for ; Wed, 16 Nov 2022 15:04:42 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DB149205E9 for ; Wed, 16 Nov 2022 15:04:41 +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 for ; Wed, 16 Nov 2022 15:04:39 +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 C742844D73 for ; Wed, 16 Nov 2022 15:04:38 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Wed, 16 Nov 2022 15:04:30 +0100 Message-Id: <20221116140435.93067-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221116140435.93067-1-f.ebner@proxmox.com> References: <20221116140435.93067-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: =?UTF-8?Q?0=0A=09?=AWL 0.027 Adjusted score from AWL reputation of From: =?UTF-8?Q?address=0A=09?=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 =?UTF-8?Q?Alignment=0A=09?=SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF =?UTF-8?Q?Record=0A=09?=SPF_PASS -0.001 SPF: sender matches SPF =?UTF-8?Q?record=0A=09?=URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [vzdump.pm, backup.pm] Subject: [pve-devel] [PATCH manager 1/6] api: vzdump: soften parameter permission checks 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: Wed, 16 Nov 2022 14:04:42 -0000 Allows sufficiently privileged users to pass-in retention and performance parameters for manual backup, but keeps tmpdir, dumpdir and script root-only. Such users could already edit the job accordingly, so essentially not granting anything new. Suggested-by: Thomas Lamprecht Signed-off-by: Fiona Ebner --- PVE/API2/Backup.pm | 15 ++++++++++----- PVE/API2/VZDump.pm | 25 ++++++++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/PVE/API2/Backup.pm b/PVE/API2/Backup.pm index 3a079874..6aef5bb7 100644 --- a/PVE/API2/Backup.pm +++ b/PVE/API2/Backup.pm @@ -40,14 +40,19 @@ my $vzdump_job_id_prop = { maxLength => 50 }; -my $assert_param_permission = sub { - my ($param, $user) = @_; +# NOTE: also used by the vzdump API call. +sub assert_param_permission_common { + my ($rpcenv, $user, $param) = @_; return if $user eq 'root@pam'; # always OK for my $key (qw(tmpdir dumpdir script)) { raise_param_exc({ $key => "Only root may set this option."}) if exists $param->{$key}; } -}; + + if (defined($param->{bwlimit}) || defined($param->{ionice}) || defined($param->{performance})) { + $rpcenv->check($user, "/", [ 'Sys.Modify' ]); + } +} my $convert_to_schedule = sub { my ($job) = @_; @@ -207,7 +212,7 @@ __PACKAGE__->register_method({ my $rpcenv = PVE::RPCEnvironment::get(); my $user = $rpcenv->get_user(); - $assert_param_permission->($param, $user); + assert_param_permission_common($rpcenv, $user, $param); if (my $pool = $param->{pool}) { $rpcenv->check_pool_exist($pool); @@ -419,7 +424,7 @@ __PACKAGE__->register_method({ my $rpcenv = PVE::RPCEnvironment::get(); my $user = $rpcenv->get_user(); - $assert_param_permission->($param, $user); + assert_param_permission_common($rpcenv, $user, $param); if (my $pool = $param->{pool}) { $rpcenv->check_pool_exist($pool); diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm index 30d47825..8e873c05 100644 --- a/PVE/API2/VZDump.pm +++ b/PVE/API2/VZDump.pm @@ -14,12 +14,25 @@ use PVE::Tools qw(extract_param); use PVE::VZDump::Common; use PVE::VZDump; +use PVE::API2::Backup; use PVE::API2Tools; use Data::Dumper; # fixme: remove use base qw(PVE::RESTHandler); +my sub assert_param_permission_vzdump { + my ($rpcenv, $user, $param) = @_; + return if $user eq 'root@pam'; # always OK + + PVE::API2::Backup::assert_param_permission_common($rpcenv, $user, $param); + + if (!$param->{dumpdir} && (defined($param->{maxfiles}) || defined($param->{'prune-backups'}))) { + my $storeid = $param->{storage} || 'local'; + $rpcenv->check($user, "/storage/$storeid", [ 'Datastore.Allocate' ]); + } # no else branch, because dumpdir is root-only +} + __PACKAGE__->register_method ({ name => 'vzdump', path => '', @@ -27,9 +40,10 @@ __PACKAGE__->register_method ({ description => "Create backup.", permissions => { description => "The user needs 'VM.Backup' permissions on any VM, and " - ."'Datastore.AllocateSpace' on the backup storage. The 'maxfiles', 'prune-backups', " - ."'tmpdir', 'dumpdir', 'script', 'bwlimit', 'performance' and 'ionice' parameters are " - ."restricted to the 'root\@pam' user.", + ."'Datastore.AllocateSpace' on the backup storage. The 'tmpdir', 'dumpdir' and " + ."'script' parameters are restricted to the 'root\@pam' user. The 'maxfiles' and " + ."'prune-backups' settings require 'Datastore.Allocate' on the backup storage. The " + ."'bwlimit', 'performance' and 'ionice' parameters require 'Sys.Modify' on '/'.", user => 'all', }, protected => 1, @@ -62,10 +76,7 @@ __PACKAGE__->register_method ({ if $param->{stdout}; } - for my $key (qw(maxfiles prune-backups tmpdir dumpdir script bwlimit performance ionice)) { - raise_param_exc({ $key => "Only root may set this option."}) - if defined($param->{$key}) && ($user ne 'root@pam'); - } + assert_param_permission_vzdump($rpcenv, $user, $param); PVE::VZDump::verify_vzdump_parameters($param, 1); -- 2.30.2