From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: Stefan Hanreich <s.hanreich@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [PATCH pve-firewall 3/5] aliases: Add option to update references on rename/delete
Date: Fri, 24 Jul 2026 10:44:13 +0200 [thread overview]
Message-ID: <wbvksm3huqxuedsml6aijosfwgmgpxhfkr6cumidcqg4wxhbrz@u2witzrh4dkl> (raw)
In-Reply-To: <f3126b4b-e215-4f82-b1c8-416cede4aacc@proxmox.com>
On Thu, Jul 16, 2026 at 03:17:32PM +0200, Stefan Hanreich wrote:
>
>
> On 4/7/26 9:36 AM, Arthur Bied-Charreton wrote:
> > Renaming or deleting an alias that is referenced by rules or security
> > groups would leave dangling references, creating broken configurations.
> >
> > Add option to the POST and DELETE endpoints for /firewall/aliases to
> > update or delete those references from cluster, hosts, and guests
> > firewall configs.
> >
> > If these endpoints are hit from the cluster environment (/cluster/),
> > all firewall config files in the cluster (cluster + all nodes + all
> > guests) have to be checked and possibly updated.
> >
> > Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
> > ---
> > src/PVE/API2/Firewall/Aliases.pm | 115 +++++++++++++++++++++++++++++++
> > 1 file changed, 115 insertions(+)
> >
> > diff --git a/src/PVE/API2/Firewall/Aliases.pm b/src/PVE/API2/Firewall/Aliases.pm
> > index eaafe68..2a06822 100644
> > --- a/src/PVE/API2/Firewall/Aliases.pm
> > +++ b/src/PVE/API2/Firewall/Aliases.pm
> > @@ -5,6 +5,7 @@ use warnings;
> > use PVE::Exception qw(raise raise_param_exc);
> > use PVE::JSONSchema qw(get_standard_option);
> >
> > +use PVE::API2::Firewall::Helpers qw(filter_map foreach_conf_in_env);
> > use PVE::Firewall;
> >
> > use base qw(PVE::RESTHandler);
> > @@ -217,6 +218,12 @@ sub register_update_alias {
> > $properties->{cidr} = $api_properties->{cidr};
> > $properties->{comment} = $api_properties->{comment};
> > $properties->{digest} = get_standard_option('pve-config-digest');
> > + $properties->{'update-references'} = {
> > + type => 'boolean',
> > + optional => 1,
> > + description => 'Update dangling references when renaming the alias.',
> > + default => 0,
> > + };
> >
> > $class->register_method({
> > name => 'update_alias',
> > @@ -261,6 +268,9 @@ sub register_update_alias {
> > if ($rename && ($name ne $rename)) {
> > raise_param_exc({ name => "alias '$param->{rename}' already exists" })
> > if defined($aliases->{$rename});
> > + rename_alias_refs(
> > + $fw_conf, $name, $param->{rename}, $class->rule_env(),
> > + ) if $param->{'update-references'};
>
> This suffers from the same timing issues as the IPSet renaming.
>
ack, will fix in v2, thanks!
> > $aliases->{$name}->{name} = $param->{rename};
> > $aliases->{$rename} = $aliases->{$name};
> > delete $aliases->{$name};
> > @@ -282,6 +292,12 @@ sub register_delete_alias {
[...]
> > +
> > +sub rename_alias_refs {
> > + my ($conf, $alias, $new_name, $rule_env) = @_;
> > + my $lc_alias = lc($alias);
> > + return rewrite_alias_refs_in_env(
> > + $conf,
> > + $lc_alias,
> > + $rule_env,
> > + sub {
> > + my ($obj) = @_;
> > + for my $field (qw(source dest cidr)) {
> > + my $val = lc($obj->{$field} // '');
> > + if ($val eq "dc/$lc_alias") { $obj->{$field} = "dc/$new_name" }
> > + elsif ($val eq $lc_alias) { $obj->{$field} = $new_name }
> > + elsif ($val eq "guest/$lc_alias") { $obj->{$field} = "guest/$new_name" }
> > + }
> > + return $obj;
> > + },
> > + );
> > +}
> > +
>
> same point w.r.t moving them to the Helper module. Also, this seems
> quite similar to the respective IPSet function (minus the name parsing).
> Would it be possible to further simplify this and re-use the functions
> across the ipset / alias functions?
>
will move the functions to the helper module. regarding the similarity,
i did have a more generic approach in the beginning, which i ended up
dropping because it felt too complicated. i will revisit this for v2,
i'm sure there is a good way to generalize this.
>
>
>
>
next prev parent reply other threads:[~2026-07-24 8:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-07 7:36 [PATCH firewall/manager 0/5] Allow updating references to firewall objects when editing them Arthur Bied-Charreton
2026-04-07 7:36 ` [PATCH pve-firewall 1/5] Add helpers for updating alias and ipset references Arthur Bied-Charreton
2026-07-16 13:17 ` Stefan Hanreich
2026-07-24 8:52 ` Arthur Bied-Charreton
2026-04-07 7:36 ` [PATCH pve-firewall 2/5] ipset: Add option to update references on rename/delete Arthur Bied-Charreton
2026-07-16 13:17 ` Stefan Hanreich
2026-07-24 8:40 ` Arthur Bied-Charreton
2026-04-07 7:36 ` [PATCH pve-firewall 3/5] aliases: " Arthur Bied-Charreton
2026-07-16 13:17 ` Stefan Hanreich
2026-07-24 8:44 ` Arthur Bied-Charreton [this message]
2026-04-07 7:36 ` [PATCH pve-manager 4/5] ipset: " Arthur Bied-Charreton
2026-04-07 7:36 ` [PATCH pve-manager 5/5] aliases: " Arthur Bied-Charreton
2026-07-16 13:17 ` [PATCH firewall/manager 0/5] Allow updating references to firewall objects when editing them Stefan Hanreich
2026-07-24 8:53 ` Arthur Bied-Charreton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=wbvksm3huqxuedsml6aijosfwgmgpxhfkr6cumidcqg4wxhbrz@u2witzrh4dkl \
--to=a.bied-charreton@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
--cc=s.hanreich@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox