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 7AD7B9F01D for ; Wed, 7 Jun 2023 16:48:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5E9401B6CA for ; Wed, 7 Jun 2023 16:48:19 +0200 (CEST) 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, 7 Jun 2023 16:48:18 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6112A41F3C for ; Wed, 7 Jun 2023 16:48:18 +0200 (CEST) Date: Wed, 07 Jun 2023 16:48:11 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20230607120357.4177891-1-aderumier@odiso.com> <20230607120357.4177891-6-aderumier@odiso.com> In-Reply-To: <20230607120357.4177891-6-aderumier@odiso.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1686149271.9la59tywtj.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.072 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 - Subject: [pve-devel] applied: [PATCH v2 pve-guest-common 1/1] helpers : add check_vnet_access 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, 07 Jun 2023 14:48:19 -0000 applied with a small fixup, I'll write the corresponding pve-container patch on Friday. On June 7, 2023 2:03 pm, Alexandre Derumier wrote: > if a tag is defined, test if user have a specific access to the vlan (or = propagate from full bridge acl or zone) > if trunks is defined, we check permissions for each vlan of the trunks > if no tag, test if user have access to full bridge. >=20 > Signed-off-by: Alexandre Derumier > --- > src/PVE/GuestHelpers.pm | 49 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 49 insertions(+) >=20 > diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm > index b4ccbaa..d22be1e 100644 > --- a/src/PVE/GuestHelpers.pm > +++ b/src/PVE/GuestHelpers.pm > @@ -10,10 +10,17 @@ use PVE::Storage; > use POSIX qw(strftime); > use Scalar::Util qw(weaken); > =20 > +my $have_sdn; > +eval { > + require PVE::Network::SDN; > + $have_sdn =3D 1; > +}; > + > use base qw(Exporter); > =20 > our @EXPORT_OK =3D qw( > assert_tag_permissions > +check_vnet_access > get_allowed_tags > safe_boolean_ne > safe_num_ne > @@ -366,4 +373,46 @@ sub get_unique_tags { > return !$no_join_result ? join(';', $res->@*) : $res; > } > =20 > +sub get_tags_from_trunk { > + my ($trunks) =3D @_; > + > + my $res =3D {}; > + my @trunks_array =3D split /;/, $trunks; > + for my $trunk (@trunks_array) { > + my ($tag, $tag_end) =3D split /-/, $trunk; > + if($tag_end && $tag_end > $tag) { > + my @tags =3D ($tag..$tag_end); > + $res->{$_} =3D 1 for @tags; > + } else { > + $res->{$tag} =3D 1; > + } > + } > + return $res; > +} > + > +sub check_vnet_access { > + my ($rpcenv, $authuser, $vnet, $tag, $trunks) =3D @_; > + > + my $zone =3D 'localnetwork'; > + > + if ($have_sdn) { > + my $vnet_cfg =3D PVE::Network::SDN::Vnets::config(); > + if (defined(my $vnet =3D PVE::Network::SDN::Vnets::sdn_vnets_config($vn= et_cfg, $vnet, 1))) { > + $zone =3D $vnet->{zone}; > + } > + } > + > + # if a tag is defined, test if user have a specific access to the vl= an (or propagated from full bridge acl) > + $rpcenv->check($authuser, "/sdn/zones/$zone/$vnet/$tag", ['SDN.Use']= ) if $tag; > + # check each vlan access from trunk > + if ($trunks) { > + my $tags =3D get_tags_from_trunk($trunks); > + for my $tag (sort keys %$tags) { > + $rpcenv->check($authuser, "/sdn/zones/$zone/$vnet/$tag", ['SDN.Use'= ]); > + } > + } > + # if no tag, test if user have access to full bridge. > + $rpcenv->check($authuser, "/sdn/zones/$zone/$vnet", ['SDN.Use']); > +} > + > 1; > --=20 > 2.30.2 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20