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 9D7101FF0B3 for ; Wed, 11 Nov 2026 14:21:36 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 411C821880; Wed, 11 Nov 2026 14:19:53 +0100 (CET) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-firewall v6 15/28] fix #8176: firewall: groups: handle dangling references on delete Date: Wed, 11 Nov 2026 14:18:48 +0100 Message-ID: <20261111131901.1791124-16-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: 1794403148630 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.644 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: 5PXLLHGXEQ4FPTURKSLYTWS2KFYGHN7F X-Message-ID-Hash: 5PXLLHGXEQ4FPTURKSLYTWS2KFYGHN7F 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: Deleting a security group referenced by rules leaves dangling references. Nothing checks that a group rule names a group that exists. The dangling reference is carried into the generated ruleset and what happens then depends on the firewall implementation. Add a 'dangling-references' option to the delete endpoint, to either 'disable' the referencing rules or 'drop' them along with the security group. The default, 'keep', leaves them as they are. If that option is passed, the delete runs as a task so the changes made to the configs can be found in the task log afterwards. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=8176 Signed-off-by: Arthur Bied-Charreton --- src/PVE/API2/Firewall/Rules.pm | 49 +++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/PVE/API2/Firewall/Rules.pm b/src/PVE/API2/Firewall/Rules.pm index 785ad05..9931d0c 100644 --- a/src/PVE/API2/Firewall/Rules.pm +++ b/src/PVE/API2/Firewall/Rules.pm @@ -487,6 +487,7 @@ package PVE::API2::Firewall::GroupRules; use strict; use warnings; use PVE::JSONSchema qw(get_standard_option); +use PVE::Firewall::References qw(update_refs run_ref_update); use base qw(PVE::API2::Firewall::RulesBase); @@ -539,27 +540,51 @@ __PACKAGE__->register_method({ additionalProperties => 0, properties => { group => get_standard_option('pve-security-group-name'), + 'dangling-references' => get_standard_option('pve-dangling-references-delete'), }, }, - returns => { type => 'null' }, + returns => { type => 'string', optional => 1 }, code => sub { my ($param) = @_; - __PACKAGE__->lock_config( - $param, - sub { - my ($param) = @_; + my $action = $param->{'dangling-references'} // 'keep'; - my (undef, $cluster_conf, $rules) = __PACKAGE__->load_config($param); + my $code = sub { + __PACKAGE__->lock_config( + $param, + sub { + my ($param) = @_; - die "Security group '$param->{group}' is not empty\n" - if scalar(@$rules); + my (undef, $cluster_conf, $rules) = __PACKAGE__->load_config($param); - __PACKAGE__->save_rules($param, $cluster_conf, undef); - }, - ); + die "Security group '$param->{group}' is not empty\n" + if scalar(@$rules); + + update_refs({ + conf => $cluster_conf, + kind => 'groups', + old => $param->{group}, + env => 'cluster', + action => $action eq 'keep' ? undef : $action, + subject => "security group '$param->{group}' deleted", + }); + + __PACKAGE__->save_rules($param, $cluster_conf, undef); + }, + ); + }; + + if (!defined($param->{'dangling-references'})) { + $code->(); + return undef; + } + + # fail on the request instead of inside the task. + my (undef, undef, $rules) = __PACKAGE__->load_config($param); + + die "Security group '$param->{group}' is not empty\n" if scalar($rules->@*); - return undef; + return run_ref_update('fw-group-delete', $param->{group}, $code); }, }); -- 2.47.3