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 CA150604AF for ; Mon, 10 Jan 2022 14:45:27 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C22FA19D1 for ; Mon, 10 Jan 2022 14:45:27 +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 26CFF19C2 for ; Mon, 10 Jan 2022 14:45:26 +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 F026B45F96 for ; Mon, 10 Jan 2022 14:45:25 +0100 (CET) Date: Mon, 10 Jan 2022 14:45:18 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20220105152215.1307583-1-o.bektas@proxmox.com> <20220105152215.1307583-3-o.bektas@proxmox.com> In-Reply-To: <20220105152215.1307583-3-o.bektas@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1641819247.ufpnev051m.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.221 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 Subject: Re: [pve-devel] [RFC common 2/4] tools: add 'check_for_root' helper 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: Mon, 10 Jan 2022 13:45:27 -0000 On January 5, 2022 4:22 pm, Oguz Bektas wrote: > checks if the rpcenv user is 'root@pam' or has the 'Sys.Root' privilege > on a given API path >=20 > Signed-off-by: Oguz Bektas > --- > src/PVE/Tools.pm | 9 +++++++++ > 1 file changed, 9 insertions(+) >=20 > diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm > index 787942a..3e2e7f9 100644 > --- a/src/PVE/Tools.pm > +++ b/src/PVE/Tools.pm > @@ -2017,4 +2017,13 @@ sub get_file_hash { > return lc($digest); > } > =20 > +sub check_for_root { > + my ($path_to_check) =3D @_; > + > + my $rpcenv =3D PVE::RPCEnvironment::get(); > + my $authuser =3D $rpcenv->get_user(); > + my $is_root =3D $authuser eq 'root@pam' || $rpcenv->check($authuser,= $path_to_check, ['Sys.Root'], 1); > + return $is_root; > +} this is in the wrong place (pve-common is not concerned with=20 access-control), move it to RPCEnvironment if kept. this is only needed for the short-cut of not actually checking privs for=20 the 'root@pam' user, since 'root@pam' by definition has 'Sys.Root' on=20 all paths - so not sure whether the helper is necessary at all. we don't have that many places limited to 'root@pam', so not sure=20 whether simply doing: # no short-cut $rpcenv->check($authuser, $path_to_check, ['Sys.Root']); or # short-cut for user if in hot path somehow $rpcenv->check($authuser, $path_to_check, ['Sys.Root']) if $authuser ne 'root@pam'; is not sufficient? it seems to be very short compared to the other=20 helpers we have in PVE::RPCEnvironment ;) > + > 1; > --=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