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 38E8FCD99 for ; Tue, 11 Jul 2023 10:34:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 11F5420602 for ; Tue, 11 Jul 2023 10:33:36 +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 ; Tue, 11 Jul 2023 10:33:35 +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 0A7CC422C1 for ; Tue, 11 Jul 2023 10:33:35 +0200 (CEST) Date: Tue, 11 Jul 2023 10:33:33 +0200 From: Stoiko Ivanov To: Fiona Ebner Cc: pmg-devel@lists.proxmox.com Message-ID: <20230711103333.4c99fd9a@rosa.proxmox.com> In-Reply-To: <20230710113647.53879-1-f.ebner@proxmox.com> References: <20230710113647.53879-1-f.ebner@proxmox.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.094 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: [pmg-devel] applied-series: [PATCH pmg-api 1/2] cluster config: restrict slurp scope to avoid issue parsing network interfaces X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jul 2023 08:34:06 -0000 hi, huge thanks for your persistence and patience while digging into this - great find! applied both patches to master and stable-7 (after verifying that it's affected as well :) On Mon, 10 Jul 2023 13:36:46 +0200 Fiona Ebner wrote: > As reported in the community forum [0], there is an edge case, where > querying the network interfaces would not work. In particular, this > could happen if the hostname cannot be resolved to a non-loopback IP > (when installing PMG on Debian and forgetting to adapt /etc/hosts for > example). > > The issue manifested as follows: > - When setting up the RESTEnvironemnt, the cluster config is read. > - This reader uses slurp mode by setting the line ending to undef > locally. > - But the subroutine call PVE::Network::get_local_ip() is still part > of that local context. > - When resolving the hostname to a non-loopback IP address failed, the > function would read (via the PVE::INotify module) the network > interfaces file. > - As part of that, /proc/net/dev was read all at once, while the > interface parsing code expects it line-by-line. > - The result for reading network interfaces was cached without having > detected the interfaces in /proc/net/dev. > - When a new request came in, the cached result was used (even > changing the file to invalidate the cache would only work as long > as the cluster config file exists, because otherwise, there would be > an attempt to read the cluster config which would read the updated > version of the interfaces file while slurping again). > > [0]: https://forum.proxmox.com/threads/129958/ > > Signed-off-by: Fiona Ebner > --- > src/PMG/ClusterConfig.pm | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/src/PMG/ClusterConfig.pm b/src/PMG/ClusterConfig.pm > index 77b9e60..c52508d 100644 > --- a/src/PMG/ClusterConfig.pm > +++ b/src/PMG/ClusterConfig.pm > @@ -170,9 +170,7 @@ sub lock_config { > sub read_cluster_conf { > my ($filename, $fh) = @_; > > - local $/ = undef; # slurp mode > - > - my $raw = defined($fh) ? <$fh> : undef; > + my $raw = defined($fh) ? do { local $/ = undef; <$fh> } : undef; > > my $cinfo = PMG::ClusterConfig::Base->parse_config($filename, $raw); >