From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 988FA1FF0B3 for ; Wed, 11 Nov 2026 14:20:19 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C8A9A2166C; Wed, 11 Nov 2026 14:19:31 +0100 (CET) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-firewall v6 09/28] firewall: aliases: add option to handle dangling references on rename Date: Wed, 11 Nov 2026 14:18:42 +0100 Message-ID: <20261111131901.1791124-10-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261111131901.1791124-1-a.bied-charreton@proxmox.com> References: <20261111131901.1791124-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794403148287 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.639 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_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: 2X6QGTWTP6XE354HCWZQHYW55HD5F5HW X-Message-ID-Hash: 2X6QGTWTP6XE354HCWZQHYW55HD5F5HW 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: Renaming an alias still referenced by rules or ipset members leaves dangling references. The firewall then fails to parse those rules during compilation and drops them. A rename can therefore effectively disable a whole set of rules. Add a 'dangling-references' option to the rename path offering to 'keep' the references around, 'disable' the referencing rules, 'drop' them, or to 'rename' the references to the new name. For cluster aliases, this also covers references in downstream configs (host, guest and vnet). A rename that fails partway leaves both the old and the new alias in the cluster config. Retrying it chokes on the check against overwriting an existing alias. 'force-rename' bypasses that check, so an interrupted rename can be finished. Avoiding the half-updated state altogether would need either a transaction across every config in the cluster or a rollback mechanism, neither of which is really an option here. Signed-off-by: Arthur Bied-Charreton --- src/PVE/API2/Firewall/Aliases.pm | 45 +++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/PVE/API2/Firewall/Aliases.pm b/src/PVE/API2/Firewall/Aliases.pm index 02835b3..90fe95f 100644 --- a/src/PVE/API2/Firewall/Aliases.pm +++ b/src/PVE/API2/Firewall/Aliases.pm @@ -2,6 +2,8 @@ package PVE::API2::Firewall::AliasesBase; use strict; use warnings; + +use PVE::Firewall::References qw(update_refs); use PVE::Exception qw(raise raise_param_exc); use PVE::JSONSchema qw(get_standard_option); @@ -219,6 +221,9 @@ sub register_update_alias { $properties->{comment} = $api_properties->{comment}; $properties->{digest} = get_standard_option('pve-config-digest'); + $properties->{'dangling-references'} = get_standard_option('pve-dangling-references-rename'); + $properties->{'force-rename'} = get_standard_option('pve-dangling-references-force-rename'); + $class->register_method({ name => 'update_alias', path => '{name}', @@ -239,6 +244,11 @@ sub register_update_alias { sub { my ($param) = @_; + my $dangling_refs = $param->{'dangling-references'} + // $properties->{'dangling-references'}->{default}; + my $force = $param->{'force-rename'} + // $properties->{'force-rename'}->{default}; + my ($fw_conf, $aliases) = $class->load_config($param); my $list = &$aliases_to_list($aliases); @@ -264,9 +274,38 @@ sub register_update_alias { if ($rename && ($name ne $rename)) { raise_param_exc({ name => "alias '$param->{rename}' already exists" }) - if defined($aliases->{$rename}); - $aliases->{$name}->{name} = $param->{rename}; - $aliases->{$rename} = $aliases->{$name}; + if defined($aliases->{$rename}) + && !$force; + + $aliases->{$rename} = + { $aliases->{$name}->%*, name => $param->{rename} }; + + my $saved = 0; + my $save = sub { + $class->save_aliases($param, $fw_conf, $aliases); + $saved = 1; + }; + + eval { + update_refs({ + conf => $fw_conf, + kind => 'aliases', + old => $name, + new => $param->{rename}, + env => $class->rule_env(), + action => $dangling_refs eq 'keep' ? undef : $dangling_refs, + subject => + "alias '$param->{name}' renamed to '$param->{rename}'", + save => $save, + }); + }; + if (my $err = $@) { + die "rename interrupted, the alias exists under both names; " + . "retry with 'force-rename' to finish: $err" + if $saved; + die "could not update references to alias '$name': $err"; + } + delete $aliases->{$name}; } -- 2.47.3