From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 797171FF0B0 for ; Tue, 27 Oct 2026 10:31:40 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id AAC49216B5; Tue, 27 Oct 2026 10:31:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=straightec.de; s=dkim; t=1793008733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6QJnKpQj3R6IVFhadqDN89/0DjdUbpEYOVye4tXoOWA=; b=p+0gIEPBf1YyVJ7q9TNUGyGcgNfoHJDHEEFXOoD3qH78AiZfaE191MPS2KxcCTTi1KdJMc 0lxQ3ELtIc1m/ryOaXbABo5ddnhOZDiiuWM4GCFcwZONoXyHNblUqIrbH5DRzNB8VeSLep BTip4jCRffgdkRKRvAf6fG/2E/TZUK63FPSEK2rDg7/38ghU486uSwyIyZgEnKeFCIpb4e 48mfSSqGirfJg/nhYJnNv0znumxqXJS6JqAFTNUuTV/S/tsSwomF2Y0KofIz8l+voZ+vnf a+ZaNzRNIoCDL+cOodqgORMGRCdh2EBUf+3+BzOB3DlDlp3wH69Iz5g+m2YxHA== From: Carsten Haerle To: pmg-devel@lists.proxmox.com Subject: [PATCH pmg-api 3/6] fix #8231: api: mynetworks: optionally list automatically trusted networks Date: Mon, 26 Oct 2026 10:58:48 +0100 Message-ID: <20261026095852.3243241-4-carsten.haerle@straightec.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261026095852.3243241-1-carsten.haerle@straightec.de> References: <20261026095852.3243241-1-carsten.haerle@straightec.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL -0.050 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy PROLO_LEO2 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record X-MailFrom: carsten.haerle@straightec.de X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation Message-ID-Hash: V4Z7R5QIZ2RWAG563XFSKVEQD6GZ3S5J X-Message-ID-Hash: V4Z7R5QIZ2RWAG563XFSKVEQD6GZ3S5J X-Mailman-Approved-At: Tue, 27 Oct 2026 10:31:21 +0100 CC: Carsten Haerle X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: With 'automatic=3D1' the index also returns the networks that are added to mynetworks automatically, marked with 'automatic: 1' and a comment that tells where each entry comes from and where it is configured. A configured entry for the same network takes precedence. Without the parameter the result is unchanged, so existing API users that iterate over and modify the list are not affected. Signed-off-by: Carsten Haerle --- src/PMG/API2/MyNetworks.pm | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/PMG/API2/MyNetworks.pm b/src/PMG/API2/MyNetworks.pm index 565b6f8..30bf448 100644 --- a/src/PMG/API2/MyNetworks.pm +++ b/src/PMG/API2/MyNetworks.pm @@ -11,6 +11,7 @@ use PVE::JSONSchema qw(get_standard_option); use PVE::RESTHandler; use PVE::INotify; =20 +use PMG::Cluster; use PMG::Config; =20 use base qw(PVE::RESTHandler); @@ -25,7 +26,15 @@ __PACKAGE__->register_method({ permissions =3D> { check =3D> ['admin', 'audit'] }, parameters =3D> { additionalProperties =3D> 0, - properties =3D> {}, + properties =3D> { + automatic =3D> { + description =3D> "Also list the networks that are trusted = automatically" + . " (local network, default relay, transport hosts).", + type =3D> 'boolean', + optional =3D> 1, + default =3D> 0, + }, + }, }, returns =3D> { type =3D> 'array', @@ -33,6 +42,12 @@ __PACKAGE__->register_method({ type =3D> "object", properties =3D> { cidr =3D> { type =3D> 'string' }, + comment =3D> { type =3D> 'string', optional =3D> 1 }, + automatic =3D> { + description =3D> "Trusted automatically, cannot be mod= ified here.", + type =3D> 'boolean', + optional =3D> 1, + }, }, }, links =3D> [{ rel =3D> 'child', href =3D> "{cidr}" }], @@ -48,6 +63,33 @@ __PACKAGE__->register_method({ push @$res, $mynetworks->{$cidr}; } =20 + return $res if !$param->{automatic}; + + my $cfg =3D PMG::Config->new(); + my $nodename =3D PVE::INotify::nodename(); + my $int_ip =3D PMG::Cluster::remote_node_ip($nodename); + my $automatic =3D $cfg->get_automatic_mynetworks($int_ip); + + foreach my $cidr (sort keys %$automatic) { + next if $mynetworks->{$cidr}; # a configured entry takes prece= dence + + my $origin =3D $automatic->{$cidr}; + my @why; + push @why, "local network of node '$nodename' (Options: Trust = Local Network)" + if $origin->{local}; + push @why, "default relay (Relaying)" if $origin->{relay}; + if (my $domains =3D $origin->{transport}) { + push @why, "transport for " . join(', ', $domains->@*) . "= (Transports)"; + } + + my $entry =3D { + cidr =3D> $cidr, + comment =3D> 'automatic: ' . join('; ', @why), + automatic =3D> 1, + }; + push @$res, $entry; + } + return $res; }, }); --=20 2.53.0