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 7C0781FF0B7 for ; Fri, 13 Nov 2026 08:19:54 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id ECBD1217E1; Fri, 13 Nov 2026 08:19:49 +0100 (CET) Date: Fri, 13 Nov 2026 08:19:43 +0100 From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: Re: [PATCH pve-firewall v7 05/28] firewall: references: add wrappers for the SDN-generated IPSets Message-ID: <3og3atpscjcpso7in2bipf2hzwamucgimwcxeiumfcy7rr2wnu@gfbtkjymwgrw> References: <20261112151045.577923-1-a.bied-charreton@proxmox.com> <20261112151045.577923-6-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261112151045.577923-6-a.bied-charreton@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794554384924 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.396 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: Z7R4CZSOZGMSAHFLF4KRYWOMSJGC7X7M X-Message-ID-Hash: Z7R4CZSOZGMSAHFLF4KRYWOMSJGC7X7M X-MailFrom: a.bied-charreton@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: some PODs are stale from v6, just noting that here. will fold them into a new version if other things turn up. sorry for the noise! On Thu, Nov 12, 2026 at 04:10:22PM +0100, Arthur Bied-Charreton wrote: > SDN generates IPSets that cannot be deleted directly, but rather > disappear once the config stops generating them: the 4 IPSets of a VNet > go away with the VNet, and a guest's IPAM IPSet goes away once the guest > is destroyed. Rules referencing those are left dangling as well. > > Add update_sdn_ipset_refs() for a list of such ipsets, > update_vnet_ipset_refs() for the four ipsets of a VNet and > update_guest_ipam_ipset_refs() for a guest's IPAM ipset. > > The update can touch any firewall config in the cluster, and its log > shows which ones. Since the user destroying a guest may only have > permissions for that guest, the wrappers run udpates in a separate task > owned by root@pam. This makes it only visible to users with Sys.Audit on > the node. The user who triggered the update is still recorded in the > log. > > The callers are PUT /cluster/sdn in pve-network, and the guest destroy > endpoints in qemu-server and pve-container. > > Signed-off-by: Arthur Bied-Charreton > --- > src/PVE/Firewall/References.pm | 101 +++++++++++++++++++++++++++++++++ > 1 file changed, 101 insertions(+) > > diff --git a/src/PVE/Firewall/References.pm b/src/PVE/Firewall/References.pm > index 6ea39cb..f245d42 100644 > --- a/src/PVE/Firewall/References.pm > +++ b/src/PVE/Firewall/References.pm > @@ -477,4 +477,105 @@ sub log_ref_line { > return; > } > > +sub start_sdn_ipset_ref_task { > + my ($id, $ipsets, $action, $subject) = @_; > + > + my $rpcenv = PVE::RESTEnvironment::get(); > + my $user = $rpcenv->get_user(); > + > + my $worker = sub { > + print "firewall: started by $user\n"; > + update_sdn_ipset_refs($ipsets, $action, $subject); > + }; > + > + my $upid = eval { $rpcenv->fork_worker('fw-sdn-ipset-refs', $id, 'root@pam', $worker, 1) }; > + if (my $err = $@) { > + warn "could not start reference update task for the removed IPSets: $err"; > + return; > + } > + > + print "firewall: updating references to removed IPSets in task $upid\n"; > +} > + > +=head3 update_sdn_ipset_refs($ipsets, $action, $subject, $log) > + > +Apply C<$action> to all references to the SDN-generated IPSets in C<$ipsets>. > + > +C<$subject> is the header for the log block and C<$log> is an optional log sink callback. > + > +Return the number of references changed. > + > +=cut > + > +sub update_sdn_ipset_refs { > + my ($ipsets, $action, $subject, $log) = @_; > + > + die "SDN IPSets cannot be renamed\n" if $action && $action eq 'rename'; > + > + my $count = 0; > + > + PVE::Firewall::lock_clusterfw_conf( > + 10, > + sub { > + my $conf = PVE::Firewall::load_clusterfw_conf(); > + > + $count = update_refs({ > + conf => $conf, > + kind => 'ipset', > + old => $ipsets, > + env => 'sdn', > + action => $action, > + subject => $subject, > + log => $log, > + }); > + > + PVE::Firewall::save_clusterfw_conf($conf); > + }, > + ); > + > + return $count; > +} > + > +=head3 update_vnet_ipset_refs($vnets, $action) > + > +Apply C<$action> to all references to the auto-generated IPSets for C<$vnets>. > + > +Return the number of references changed. this POD is stale from v6, should be: "Start a tast applying C<$action> to all references to the auto-generated IPSets for C<$vnets>. Does nothing for C or an empty C<$vnets>" > + > +=cut > + > +sub update_vnet_ipset_refs { > + my ($vnets, $action) = @_; > + > + return if $action eq 'keep' || !$vnets->@*; > + > + my $ipsets = [ > + map { > + my $vnet = $_; > + map { "$vnet-$_" } qw(all gateway no-gateway dhcp) > + } $vnets->@* > + ]; > + > + my $names = join(', ', map { "'$_'" } $vnets->@*); > + my $subject = scalar($vnets->@*) > 1 ? "vnets $names removed" : "vnet $names removed"; > + > + start_sdn_ipset_ref_task(join(',', $vnets->@*), $ipsets, $action, $subject); > +} > + > +=head3 update_guest_ipam_ipset_refs($vmid, $action) > + > +Apply C<$action> to all references to the IPAM IPSet of the guest C<$vmid>. > + > +Return the number of references changed. > + this too: "Start a task applying C<$action> to all references to the IPAM IPSet of the guest C<$vmid>. Does nothing for C." > +=cut > + > +sub update_guest_ipam_ipset_refs { > + my ($vmid, $action) = @_; > + > + return if $action eq 'keep'; > + > + start_sdn_ipset_ref_task($vmid, "guest-ipam-$vmid", $action, "guest $vmid destroyed"); > +} > + > 1; > -- > 2.47.3 > > > > >