From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id C49B91FF141 for ; Tue, 05 May 2026 16:23:12 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9E7DD5699; Tue, 5 May 2026 16:23:12 +0200 (CEST) From: David Riley To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network 1/2] fix #7520: sdn: clean up dangling ACLs on resource deletion Date: Tue, 5 May 2026 16:22:06 +0200 Message-ID: <20260505142207.2563052-2-d.riley@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260505142207.2563052-1-d.riley@proxmox.com> References: <20260505142207.2563052-1-d.riley@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1777990849580 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.414 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [sdn.pm] Message-ID-Hash: K5JGBAAHVF6TW7DRMGRXIVKNIHBDVYMS X-Message-ID-Hash: K5JGBAAHVF6TW7DRMGRXIVKNIHBDVYMS X-MailFrom: d.riley@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 CC: David Riley X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add pruning mechanism to clean up orphaned SDN ACL entries by comparing the current `running-config` with the newly compiled state during `commit_config`. This ensures state consistency for manual applies via the UI/API as well as during the automatic configuration reload on system boot. Covers resources tracked in the `running-config`: * Zones * VNets * Fabrics * Controllers Signed-off-by: David Riley --- src/PVE/Network/SDN.pm | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/PVE/Network/SDN.pm b/src/PVE/Network/SDN.pm index 0bb36bf..0e802d6 100644 --- a/src/PVE/Network/SDN.pm +++ b/src/PVE/Network/SDN.pm @@ -12,6 +12,7 @@ use UUID; use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); use PVE::INotify; +use PVE::AccessControl; use PVE::RESTEnvironment qw(log_warn); use PVE::RPCEnvironment; use PVE::Tools qw(file_get_contents file_set_contents extract_param dir_glob_regex run_command); @@ -227,11 +228,55 @@ sub compile_running_cfg { } sub commit_config { + my $old_cfg = cfs_read_file($RUNNING_CFG_FILENAME); my $cfg = compile_running_cfg(); + cleanup_sdn_acls($old_cfg, $cfg); + cfs_write_file($RUNNING_CFG_FILENAME, $cfg); } +sub cleanup_sdn_acls { + my ($old_cfg, $new_cfg) = @_; + return if !$old_cfg || !$new_cfg; + + my @paths_to_delete = (); + + my @types = qw(zones controllers fabrics); + foreach my $type (@types) { + if (my $old_ids = $old_cfg->{$type}->{ids}) { + my $new_ids = $new_cfg->{$type}->{ids} // {}; + + foreach my $id (keys %$old_ids) { + if (!$new_ids->{$id}) { + push @paths_to_delete, [$type, $id]; + } + } + } + } + + if (my $old_vnets = $old_cfg->{vnets}->{ids}) { + my $new_vnets = $new_cfg->{vnets}->{ids} // {}; + + foreach my $vnetid (keys %$old_vnets) { + if (!$new_vnets->{$vnetid}) { + my $zoneid = $old_vnets->{$vnetid}->{zone}; + + if ($zoneid) { + push @paths_to_delete, ['zones', $zoneid, $vnetid]; + } else { + log_warn( + "SDN Cleanup: Could not find zone for VNet $vnetid, skipping ACL cleanup"); + } + } + } + } + + if (scalar(@paths_to_delete) > 0) { + PVE::AccessControl::remove_sdn_resource_access(\@paths_to_delete); + } +} + sub has_pending_changes { my $running_cfg = PVE::Network::SDN::running_config(); -- 2.47.3