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 90AE06AE9B for ; Thu, 17 Mar 2022 13:12:24 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 802CE3900 for ; Thu, 17 Mar 2022 13:11:54 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 38D6A38F4 for ; Thu, 17 Mar 2022 13:11:52 +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 EABF046EBE for ; Thu, 17 Mar 2022 13:11:51 +0100 (CET) Date: Thu, 17 Mar 2022 13:11:42 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20220311112504.595964-1-o.bektas@proxmox.com> <20220311112504.595964-9-o.bektas@proxmox.com> In-Reply-To: <20220311112504.595964-9-o.bektas@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1647517997.4n08fbtadl.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.182 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. [lxc.pm, config.pm, proxmox.com, status.pm] Subject: Re: [pve-devel] [PATCH v2 container 08/12] fix #2582: api: add checks for 'SuperUser' privilege 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, 17 Mar 2022 12:12:24 -0000 some more stuff: - PVE::API2::LXC mentions root-only code paths in line 261 - message in PVE::LXC::Create mentions root in line 334 On March 11, 2022 12:25 pm, Oguz Bektas wrote: > this way we can allow regular users to act as superuser on specific > paths by giving them the (new) builtin 'SuperAdministrator' role or a > custom role with the 'SuperUser' privilege >=20 > Signed-off-by: Oguz Bektas > --- > v1->v2: > * update the messages to reflect superuser instead of root@pam >=20 >=20 > src/PVE/API2/LXC.pm | 15 +++++++-------- > src/PVE/API2/LXC/Config.pm | 2 +- > src/PVE/API2/LXC/Status.pm | 12 ++++++++---- > src/PVE/LXC.pm | 21 ++++++++++++--------- > 4 files changed, 28 insertions(+), 22 deletions(-) >=20 > diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm > index 84712f7..4631d0b 100644 > --- a/src/PVE/API2/LXC.pm > +++ b/src/PVE/API2/LXC.pm > @@ -304,7 +304,7 @@ __PACKAGE__->register_method({ > =20 > my $conf =3D {}; > =20 > - my $is_root =3D $authuser eq 'root@pam'; > + my $is_superuser =3D $authuser eq 'root@pam' || $rpcenv->check($authuse= r, "/vms/$vmid", ['SuperUser'], 1); nit: line too long.. > =20 > my $no_disk_param =3D {}; > my $mp_param =3D {}; > @@ -339,8 +339,8 @@ __PACKAGE__->register_method({ > my $mp =3D $mountpoint->{mp}; > =20 > if ($mountpoint->{type} ne 'volume') { # bind or device > - die "Only root can pass arbitrary filesystem paths.\n" > - if !$is_root; > + die "Only superusers can pass arbitrary filesystem paths.\n" > + if !$is_superuser; > } else { > my ($sid, $volname) =3D PVE::Storage::parse_volume_id($volid); > &$check_and_activate_storage($sid); > @@ -380,7 +380,7 @@ __PACKAGE__->register_method({ comment above this context line is still referencing root.. > # causing it to restore the raw lxc entries, among which there may be > # 'lxc.idmap' entries. We need to make sure that the extracted conten= ts > # of the container match up with the restored configuration afterward= s: > - $conf->{lxc} =3D $orig_conf->{lxc} if $is_root; > + $conf->{lxc} =3D $orig_conf->{lxc} if $is_superuser; > =20 > $conf->{unprivileged} =3D $orig_conf->{unprivileged} > if !defined($unprivileged) && defined($orig_conf->{unprivileged})= ; > @@ -414,8 +414,7 @@ __PACKAGE__->register_method({ > my $type =3D $mountpoint->{type}; > die "restoring rootfs to $type mount is only possible by specifying = -rootfs manually!\n" > if ($ms eq 'rootfs'); > - die "restoring '$ms' to $type mount is only possible for root\n" > - if !$is_root; > + die "restoring '$ms' to $type mount is only possible for superusers\= n" if !$is_superuser; > =20 > if ($mountpoint->{backup}) { > warn "WARNING - unsupported configuration!\n"; > @@ -456,7 +455,7 @@ __PACKAGE__->register_method({ > =20 > if ($restore) { > print "merging backed-up and given configuration..\n"; > - PVE::LXC::Create::restore_configuration($vmid, $storage_cfg, $archive= , $rootdir, $conf, !$is_root, $unique, $skip_fw_config_restore); > + PVE::LXC::Create::restore_configuration($vmid, $storage_cfg, $archive= , $rootdir, $conf, !$is_superuser, $unique, $skip_fw_config_restore); > my $lxc_setup =3D PVE::LXC::Setup->new($conf, $rootdir); > $lxc_setup->template_fixup($conf); > } else { > @@ -2216,7 +2215,7 @@ __PACKAGE__->register_method({ > raise_param_exc({ 'target-vmid' =3D> $msg, 'storage' =3D> $msg }); > } elsif ($target_vmid) { > $rpcenv->check_vm_perm($authuser, $target_vmid, undef, ['VM.Config.= Disk']) > - if $authuser ne 'root@pam'; > + if $authuser ne 'root@pam'; # no need to check for root@pam why leave this one in and add a comment, but the others don't get the=20 short cut? (e.g., there are two plain rpcenv->check calls jumping out=20 even when just looking at the location of this change!) > =20 > if ($vmid eq $target_vmid) { > my $msg =3D "must be different than source VMID to move disk to anothe= r container"; > diff --git a/src/PVE/API2/LXC/Config.pm b/src/PVE/API2/LXC/Config.pm > index 1fec048..6278b8a 100644 > --- a/src/PVE/API2/LXC/Config.pm > +++ b/src/PVE/API2/LXC/Config.pm > @@ -99,7 +99,7 @@ __PACKAGE__->register_method({ > description =3D> "Set container options.", > permissions =3D> { > check =3D> ['perm', '/vms/{vmid}', $vm_config_perm_list, any =3D> 1], > - description =3D> 'non-volume mount points in rootfs and mp[n] are restr= icted to root@pam', > + description =3D> 'non-volume mount points in rootfs and mp[n] are restr= icted to superusers', > }, > parameters =3D> { > additionalProperties =3D> 0, > diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm > index f7e3128..92e37f8 100644 > --- a/src/PVE/API2/LXC/Status.pm > +++ b/src/PVE/API2/LXC/Status.pm > @@ -150,9 +150,11 @@ __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); you can guess the nit ;) > + > 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 "CT $vmid already running\n" if PVE::LXC::check_running($vmid); > =20 > @@ -234,9 +236,11 @@ __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); same > + > 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 "CT $vmid not running\n" if !PVE::LXC::check_running($vmid); > =20 > diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm > index b07d986..60c4fce 100644 > --- a/src/PVE/LXC.pm > +++ b/src/PVE/LXC.pm > @@ -1254,7 +1254,10 @@ sub template_create { > sub check_ct_modify_config_perm { > my ($rpcenv, $authuser, $vmid, $pool, $oldconf, $newconf, $delete, $= unprivileged) =3D @_; > =20 > - return 1 if $authuser eq 'root@pam'; > + return 1 if $authuser eq 'root@pam'; # early exit for root@pam > + > + my $is_superuser =3D $rpcenv->check($authuser, "/vms/$vmid", ['Super= User'], 1); > + > my $storage_cfg =3D PVE::Storage::config(); > =20 > my $check =3D sub { > @@ -1265,8 +1268,8 @@ sub check_ct_modify_config_perm { > $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Disk'])= ; > return if $delete; > my $data =3D PVE::LXC::Config->parse_volume($opt, $newconf->{$opt})= ; > - raise_perm_exc("mount point type $data->{type} is only allowed for = root\@pam") > - if $data->{type} ne 'volume'; > + raise_perm_exc("mount point type $data->{type} is only allowed for = superusers") > + if $data->{type} ne 'volume' && !$is_superuser; > my $volid =3D $data->{volume}; > if ($volid =3D~ $NEW_DISK_RE) { > my $sid =3D $1; > @@ -1280,8 +1283,8 @@ sub check_ct_modify_config_perm { > $opt eq 'searchdomain' || $opt eq 'hostname') { > $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Network= ']); > } elsif ($opt eq 'features') { > - raise_perm_exc("changing feature flags for privileged container is = only allowed for root\@pam") > - if !$unprivileged; > + raise_perm_exc("changing feature flags for privileged container is = only allowed for superusers") > + if !$unprivileged && !$is_superuser; > =20 > my $nesting_changed =3D 0; > my $other_changed =3D 0; > @@ -1319,13 +1322,13 @@ sub check_ct_modify_config_perm { > $other_changed =3D 1; > } > } > - raise_perm_exc("changing feature flags (except nesting) is only all= owed for root\@pam") > - if $other_changed; > + raise_perm_exc("changing feature flags (except nesting) is only all= owed for superusers") > + if $other_changed && !$is_superuser; > $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Allocate']) > if $nesting_changed; > } elsif ($opt eq 'hookscript') { > - # For now this is restricted to root@pam > - raise_perm_exc("changing the hookscript is only allowed for root\@p= am"); > + raise_perm_exc("changing the hookscript is only allowed for superus= ers") > + if !$is_superuser; > } else { > $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Options= ']); > } > --=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