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 F3D5C9A18C for ; Fri, 17 Nov 2023 11:10:09 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D63551F863 for ; Fri, 17 Nov 2023 11:10:09 +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 ; Fri, 17 Nov 2023 11:10:09 +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 0A9A443D72 for ; Fri, 17 Nov 2023 11:10:09 +0100 (CET) Date: Fri, 17 Nov 2023 11:10:07 +0100 From: Wolfgang Bumiller To: Fabian =?utf-8?Q?Gr=C3=BCnbichler?= Cc: pve-devel@lists.proxmox.com Message-ID: References: <20231116153128.788593-1-f.gruenbichler@proxmox.com> <20231116153128.788593-3-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231116153128.788593-3-f.gruenbichler@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.101 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 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [accesscontrol.pm] Subject: Re: [pve-devel] [PATCH access-control 2/2] pools: record parent/subpool information 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: Fri, 17 Nov 2023 10:10:10 -0000 On Thu, Nov 16, 2023 at 04:31:26PM +0100, Fabian Grünbichler wrote: > and ensure a missing intermediate pool exists at all times. > > Signed-off-by: Fabian Grünbichler > --- > > Notes: > a "missing link" should never happen when modifying via the API (both deletion > with children and addition without the parent existing is blocked there), but > it could happen when manually editing the config. > > src/PVE/AccessControl.pm | 14 +++++++++++++- > src/test/parser_writer.pl | 4 ++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm > index d9ae611..e33f844 100644 > --- a/src/PVE/AccessControl.pm > +++ b/src/PVE/AccessControl.pm > @@ -1529,7 +1529,19 @@ sub parse_user_config { > } > > # make sure to add the pool (even if there are no members) > - $cfg->{pools}->{$pool} = { vms => {}, storage => {} } if !$cfg->{pools}->{$pool}; > + $cfg->{pools}->{$pool} = { vms => {}, storage => {}, pools => {} } if !$cfg->{pools}->{$pool}; > + > + if ($pool =~ m!/!) { > + my $curr = $pool; > + while ($curr =~ m!^(.*)/[^/]+$!) { I wonder if we should use `.+` instead of `.*`. This way it would work the same even with a leading slash. That said, we don't allow leading slashes and there's a verify_poolname further up in the function so it doesn't really matter much. We just need to be careful that we never allow/introduce leading slashes anywhere, otherwise this runs with a final iteration where $parent is an empty string. > + # ensure nested pool info is correctly recorded > + my $parent = $1; > + $cfg->{pools}->{$curr}->{parent} = $parent; > + $cfg->{pools}->{$parent} = { vms => {}, storage => {}, pools => {} } if !$cfg->{pools}->{$parent}; (could use //= instead of the suffix if, IMO a bit easier to read (and doesn't break the 100 char limit :p) > + $cfg->{pools}->{$parent}->{pools}->{$curr} = 1; > + $curr = $parent; > + } > + } > > $cfg->{pools}->{$pool}->{comment} = PVE::Tools::decode_text($comment) if $comment; > > diff --git a/src/test/parser_writer.pl b/src/test/parser_writer.pl > index 65a70eb..80c346b 100755 > --- a/src/test/parser_writer.pl > +++ b/src/test/parser_writer.pl > @@ -237,21 +237,25 @@ my $default_cfg = { > 'id' => 'testpool', > vms => {}, > storage => {}, > + pools => {}, > }, > test_pool_members => { > 'id' => 'testpool', > vms => { 123 => 1, 1234 => 1}, > storage => { 'local' => 1, 'local-zfs' => 1}, > + pools => {}, > }, > test_pool_duplicate_vms => { > 'id' => 'test_duplicate_vms', > vms => {}, > storage => {}, > + pools => {}, > }, > test_pool_duplicate_storages => { > 'id' => 'test_duplicate_storages', > vms => {}, > storage => { 'local' => 1, 'local-zfs' => 1}, > + pools => {}, > }, > acl_simple_user => { > 'path' => '/', > -- > 2.39.2