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 DD7C61FF0E3 for ; Tue, 27 Oct 2026 09:59:34 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7F6FC218D9; Tue, 27 Oct 2026 09:56:35 +0100 (CET) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v3 26/45] sdn: microseg: add name regex matcher Date: Tue, 27 Oct 2026 09:55:08 +0100 Message-ID: <20261027085527.702738-27-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261027085527.702738-1-h.laimer@proxmox.com> References: <20261027085527.702738-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1793091361702 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.336 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: SYGNLQ6TBUUEBXNZ2ANOL5JYN3MDTQF4 X-Message-ID-Hash: SYGNLQ6TBUUEBXNZ2ANOL5JYN3MDTQF4 X-MailFrom: h.laimer@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: A name regex matcher binds every guest whose name matches a regular expression. For a container the name is its hostname. A rename into or out of the names a matcher covers moves the guest between groups. So a check for renames asks for SDN.Use on /sdn/microseg, like the one for tag changes. Signed-off-by: Hannes Laimer --- src/PVE/Network/SDN/Microseg.pm | 43 +++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/PVE/Network/SDN/Microseg.pm b/src/PVE/Network/SDN/Microseg.pm index 8090043268a7..bdfde447b320 100644 --- a/src/PVE/Network/SDN/Microseg.pm +++ b/src/PVE/Network/SDN/Microseg.pm @@ -32,9 +32,18 @@ PVE::JSONSchema::register_standard_option( }, ); +PVE::JSONSchema::register_format( + 'pve-sdn-microseg-name-regex', + sub { + my ($regex) = @_; + die "name regex '$regex' contains non-ASCII characters\n" if $regex =~ m/[^\x00-\x7f]/; + return $regex; + }, +); + cfs_register_file('sdn/microseg.cfg', \&parse_microseg_config, \&write_microseg_config); -our $ASSIGNMENT_TYPES = ['guest-assignment', 'tag-assignment']; +our $ASSIGNMENT_TYPES = ['guest-assignment', 'tag-assignment', 'regex-assignment']; sub parse_microseg_config { my ($filename, $raw) = @_; @@ -203,7 +212,8 @@ sub assignment_properties { type => 'string', enum => $ASSIGNMENT_TYPES, description => "The matcher kind. 'guest-assignment' binds a specific guest," - . " 'tag-assignment' every guest carrying the matched tags.", + . " 'tag-assignment' every guest carrying the matched tags, 'regex-assignment'" + . " every guest whose name matches a regex.", }; $properties->{vmid} = get_standard_option( 'pve-vmid', @@ -234,6 +244,17 @@ sub assignment_properties { description => "How tags match. 'any' shares a listed tag, 'all' carries every" . " listed tag, 'exact' equals the listed set.", }; + $properties->{'name-regex'} = { + type => 'string', + format => 'pve-sdn-microseg-name-regex', + minLength => 1, + maxLength => 1024, + 'type-property' => 'type', + 'instance-types' => ['regex-assignment'], + description => "A regular expression matched against each guest's name, ASCII only." + . " It matches anywhere in the name, so anchor it with '^' and '\$' for a" + . " whole-name match. A guest without a name is never matched.", + }; $properties->{iface} = { type => 'integer', minimum => 0, @@ -294,11 +315,22 @@ sub check_tag_access { } } +# a rename that changes which regex assignments match can move the guest between groups like a +# tag change, so it needs SDN.Use on the policy. The match runs in the config, so it uses the +# regex engine that resolves the NICs. +sub check_name_access { + my ($rpcenv, $authuser, $old, $new) = @_; + + return if !config()->name_match_changed($old, $new); + $rpcenv->check($authuser, '/sdn/microseg', ['SDN.Use']); +} + sub guest_inventory { my (%opts) = @_; - # the data plane takes a guest's NICs from the node, so an apply leaves them out - my @props = ('tags', $opts{skip_nics} ? () : map { "net$_" } 0 .. $MAX_NIC_INDEX); + # the data plane takes a guest's NICs from the node + my @props = + ('tags', 'name', 'hostname', $opts{skip_nics} ? () : map { "net$_" } 0 .. $MAX_NIC_INDEX); my $by_vmid = PVE::Cluster::get_guest_config_properties(\@props, $opts{vmid}); @@ -313,6 +345,7 @@ sub guest_inventory { push @$inventory, { vmid => $vmid, + name => $guest->{name} // $guest->{hostname}, tags => \@tags, nics => \@nics, }; @@ -341,7 +374,7 @@ my sub parse_guest_nic { return $iface =~ m/^(?:tap|veth)(\d+)i(\d+)$/; } -# the guest as the inventory lists it, with nothing but its vmid when it has no tags +# the inventory leaves out a guest without tags and name my sub guest_info { my ($vmid) = @_; -- 2.47.3