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 220981FF0E5 for ; Wed, 15 Jul 2026 17:00:57 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id AEC982141C; Wed, 15 Jul 2026 17:00:56 +0200 (CEST) Message-ID: <9722561d-b631-402e-b69b-dde095bb206e@proxmox.com> Date: Wed, 15 Jul 2026 17:00:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH pve-network v5 7/7] fix #7520: config: prune orphaned and relocate moved VNet ACLs To: pve-devel@lists.proxmox.com References: <20260707120404.73072-1-d.riley@proxmox.com> <20260707120404.73072-8-d.riley@proxmox.com> Content-Language: en-US From: Stefan Hanreich In-Reply-To: <20260707120404.73072-8-d.riley@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.163 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) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low 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: 4MICRFYEQ3XTTPGZKCH64FWOFELUKY4O X-Message-ID-Hash: 4MICRFYEQ3XTTPGZKCH64FWOFELUKY4O X-MailFrom: s.hanreich@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: On 7/7/26 2:06 PM, David Riley wrote: > Compare the running configuration with the newly compiled state during > config commit to track configuration changes across: > * Zones > * VNets > * Fabrics > * Controllers > * Route maps > * Prefix lists > > Based on this comparison, identify and prune orphaned SDN ACL entries > to ensure state consistency for manual applies via the UI/API as well > as during automatic configuration reloads on system boot. > > Additionally, reject conflicting destination paths when a VNet is > moved between zones to prevent configuration overwrites. If the target > path is clear, relocate the corresponding ACLs to the updated zone. > > Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7520 > > Suggested-by: Stefan Hanreich > Signed-off-by: David Riley > --- > src/PVE/Network/SDN.pm | 115 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 115 insertions(+) > > diff --git a/src/PVE/Network/SDN.pm b/src/PVE/Network/SDN.pm > index 33a3cf3..5da425e 100644 > --- a/src/PVE/Network/SDN.pm > +++ b/src/PVE/Network/SDN.pm > @@ -10,6 +10,7 @@ use LWP::UserAgent; > use Net::SSLeay; > use UUID; > > +use PVE::AccessControl; > use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); > use PVE::INotify; > use PVE::RESTEnvironment qw(log_warn); > @@ -238,11 +239,125 @@ sub compile_running_cfg { > } > > sub commit_config { > + my $old_cfg = cfs_read_file($RUNNING_CFG_FILENAME); nit: there is already running_config() for accessing the running_config. suppose we shoudl adjust it in compile_running_cfg as well while we're at it > my $cfg = compile_running_cfg(); > > + cleanup_access_control($old_cfg, $cfg); > + > cfs_write_file($RUNNING_CFG_FILENAME, $cfg); > } > > +sub cleanup_access_control { > + my ($old_cfg, $cfg) = @_; > + > + my $route_map_paths = diff_route_maps($old_cfg, $cfg); > + my $generic_paths = diff_generic_resources($old_cfg, $cfg); > + my ($vnet_delete_paths, $vnet_move_paths) = diff_vnets($old_cfg, $cfg); > + > + if (@$vnet_move_paths) { > + PVE::AccessControl::migrate_sdn_resource_access($vnet_move_paths); > + } > + > + my @paths_to_delete = (@$vnet_delete_paths, @$route_map_paths, @$generic_paths); > + if (@paths_to_delete) { > + PVE::AccessControl::remove_sdn_resource_access(\@paths_to_delete); > + } > +} > + > +sub diff_generic_resources { > + my ($old_cfg, $cfg) = @_; > + > + my @paths_to_delete = (); > + > + my @types = qw(zones controllers fabrics prefix-lists); > + for my $type (@types) { > + if (!defined($old_cfg->{$type}) || !defined($old_cfg->{$type}->{ids})) { > + next; > + } > + > + my $old_ids = $old_cfg->{$type}->{ids}; > + my $new_ids = $cfg->{$type}->{ids}; > + > + for my $id (keys %$old_ids) { > + next if defined($new_ids->{$id}); > + > + push(@paths_to_delete, "$type/$id"); > + } > + } > + > + return \@paths_to_delete; > +} > + > +sub diff_route_maps { > + my ($old_cfg, $cfg) = @_; > + > + my @paths_to_delete = (); > + > + if (defined($old_cfg->{'route-maps'}) && defined($old_cfg->{'route-maps'}->{ids})) { > + my $old_route_maps = $old_cfg->{'route-maps'}->{ids}; > + my $route_map_suffix_regex = qr/_[0-9]+$/; > + > + my %active_route_maps = (); > + if (defined($cfg->{'route-maps'}->{ids})) { > + for my $id (keys $cfg->{'route-maps'}->{ids}->%*) { > + (my $base_name = $id) =~ s/$route_map_suffix_regex//; > + $active_route_maps{$base_name} = 1; > + } > + } > + > + my %queued_route_maps = (); > + for my $id (keys %$old_route_maps) { > + next if defined($cfg->{'route-maps'}->{ids}->{$id}); > + > + (my $base_name = $id) =~ s/$route_map_suffix_regex//; > + > + next if ($active_route_maps{$base_name}); > + > + next if ($queued_route_maps{$base_name}); > + > + push(@paths_to_delete, "route-maps/$base_name"); > + $queued_route_maps{$base_name} = 1; > + } > + } > + > + return \@paths_to_delete; > +} > + > +sub diff_vnets { > + my ($old_cfg, $cfg) = @_; > + > + my @paths_to_delete = (); > + my @paths_to_move = (); > + > + if (defined($old_cfg->{vnets}->{ids})) { > + my $old_vnets = $old_cfg->{vnets}->{ids}; > + my $new_vnets = $cfg->{vnets}->{ids}; > + > + for my $vnetid (keys %$old_vnets) { > + my $old_zone = $old_vnets->{$vnetid}->{zone}; > + > + if (!defined($new_vnets->{$vnetid})) { > + push(@paths_to_delete, "zones/$old_zone/$vnetid"); > + next; > + } > + > + my $new_zone = $new_vnets->{$vnetid}->{zone}; > + > + if ($old_zone ne $new_zone) { > + push( > + @paths_to_move, > + { > + src_path => "zones/$old_zone/$vnetid", > + dest_path => "zones/$new_zone/$vnetid", > + }, > + ); > + } > + } > + } > + > + return (\@paths_to_delete, \@paths_to_move); > +} > + > sub has_pending_changes { > my $running_cfg = PVE::Network::SDN::running_config(); >