From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-network v4 25/45] sdn: microseg: add tag matcher
Date: Thu, 5 Nov 2026 12:13:04 +0100 [thread overview]
Message-ID: <20261105111324.706922-26-h.laimer@proxmox.com> (raw)
In-Reply-To: <20261105111324.706922-1-h.laimer@proxmox.com>
A tag matcher binds every guest with the given tags to a set of
groups, guests created later included.
A tag the matchers name moves a guest between groups, an SDN change
like putting a NIC on a vnet. So a new permission check requires
SDN.Use on /sdn/microseg when a guest gains or loses such a tag.
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
debian/control | 1 +
src/PVE/API2/Network/SDN/Microseg/Base.pm | 7 ++-
src/PVE/Network/SDN.pm | 1 +
src/PVE/Network/SDN/Microseg.pm | 59 ++++++++++++++++++-----
4 files changed, 56 insertions(+), 12 deletions(-)
diff --git a/debian/control b/debian/control
index 268f40186b6b..c8842ab3d37d 100644
--- a/debian/control
+++ b/debian/control
@@ -42,6 +42,7 @@ Description: Proxmox VE's SDN (Software Defined Network) stack
Package: libpve-network-api-perl
Architecture: all
Depends: libpve-common-perl (>= 9.0.2),
+ libpve-guest-common-perl,
pve-firewall (>= 5.1.0~),
pve-cluster (>= 9.0.1),
libpve-network-perl (= ${binary:Version}),
diff --git a/src/PVE/API2/Network/SDN/Microseg/Base.pm b/src/PVE/API2/Network/SDN/Microseg/Base.pm
index dde88d10c7b1..58ec75c6fb12 100644
--- a/src/PVE/API2/Network/SDN/Microseg/Base.pm
+++ b/src/PVE/API2/Network/SDN/Microseg/Base.pm
@@ -5,6 +5,7 @@ use warnings;
use PVE::Cluster;
use PVE::Exception qw(raise_param_exc);
+use PVE::GuestHelpers;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Tools qw(extract_param);
@@ -85,7 +86,7 @@ my sub assert_non_empty_lists {
my ($param) = @_;
my $errors = {};
- for my $property (qw(src dst groups)) {
+ for my $property (qw(src dst groups tags)) {
my $value = $param->{$property};
$errors->{$property} = "must not be empty" if $value && !@$value;
}
@@ -108,6 +109,10 @@ my sub create_object {
my $lock_token = extract_param($param, 'lock-token');
$param->{type} = $type;
+ if ($param->{tags}) {
+ $param->{tags} = PVE::GuestHelpers::get_unique_tags($param->{tags}, 1);
+ }
+
PVE::Cluster::check_cfs_quorum();
mkdir("/etc/pve/sdn");
diff --git a/src/PVE/Network/SDN.pm b/src/PVE/Network/SDN.pm
index 0996de05794b..210553de685f 100644
--- a/src/PVE/Network/SDN.pm
+++ b/src/PVE/Network/SDN.pm
@@ -661,6 +661,7 @@ sub encode_value {
|| $key eq 'secondary-controllers'
|| $key eq 'redistribute'
|| $key eq 'groups'
+ || $key eq 'tags'
|| $key eq 'src'
|| $key eq 'dst'
) {
diff --git a/src/PVE/Network/SDN/Microseg.pm b/src/PVE/Network/SDN/Microseg.pm
index 9cfaf6b746ff..4b322dede8be 100644
--- a/src/PVE/Network/SDN/Microseg.pm
+++ b/src/PVE/Network/SDN/Microseg.pm
@@ -35,7 +35,7 @@ PVE::JSONSchema::register_standard_option(
cfs_register_file('sdn/microseg.cfg', \&parse_microseg_config, \&write_microseg_config);
-our $ASSIGNMENT_TYPES = ['guest-assignment'];
+our $ASSIGNMENT_TYPES = ['guest-assignment', 'tag-assignment'];
sub parse_microseg_config {
my ($filename, $raw) = @_;
@@ -223,7 +223,8 @@ sub assignment_properties {
$properties->{type} = {
type => 'string',
enum => $ASSIGNMENT_TYPES,
- description => "The matcher kind. 'guest-assignment' binds a specific guest.",
+ description => "The matcher kind. 'guest-assignment' binds a specific guest,"
+ . " 'tag-assignment' every guest carrying the matched tags.",
};
$properties->{vmid} = get_standard_option(
'pve-vmid',
@@ -233,6 +234,27 @@ sub assignment_properties {
description => "The guest whose NICs to bind.",
},
);
+ $properties->{tags} = {
+ type => 'array',
+ items => {
+ type => 'string',
+ format => 'pve-tag',
+ },
+ 'type-property' => 'type',
+ 'instance-types' => ['tag-assignment'],
+ description => "The guest tags to match. They are normalized like the tags on a"
+ . " guest, so case only matters with a case-sensitive datacenter tag style.",
+ };
+ $properties->{'tag-match'} = {
+ type => 'string',
+ enum => [@MATCH_KINDS],
+ optional => 1,
+ default => 'any',
+ 'type-property' => 'type',
+ 'instance-types' => ['tag-assignment'],
+ description => "How tags match. 'any' shares a listed tag, 'all' carries every"
+ . " listed tag, 'exact' equals the listed set.",
+ };
$properties->{iface} = {
type => 'integer',
minimum => 0,
@@ -268,10 +290,21 @@ sub optional_properties {
return { map { $_ => { $properties->{$_}->%*, optional => 1 } } keys $properties->%* };
}
+sub check_tag_access {
+ my ($rpcenv, $authuser, $old, $new) = @_;
+
+ my $old_tags = [PVE::Tools::split_list($old // '')];
+ my $new_tags = [PVE::Tools::split_list($new // '')];
+ my $policy = running_policy(PVE::Network::SDN::running_config());
+ return if !$policy->tag_match_changed($old_tags, $new_tags);
+ $rpcenv->check($authuser, '/sdn/microseg', ['SDN.Use']);
+}
+
sub guest_inventory {
my (%opts) = @_;
- my @props = map { "net$_" } 0 .. $MAX_NIC_INDEX;
+ # 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);
my $by_vmid = PVE::Cluster::get_guest_config_properties(\@props, $opts{vmid});
@@ -279,11 +312,14 @@ sub guest_inventory {
for my $vmid (sort { $a <=> $b } keys %$by_vmid) {
my $guest = $by_vmid->{$vmid};
+ my @tags = PVE::Tools::split_list($guest->{tags});
+
my @nics = grep { defined $guest->{"net$_"} } 0 .. $MAX_NIC_INDEX;
push @$inventory,
{
vmid => $vmid,
+ tags => \@tags,
nics => \@nics,
};
}
@@ -311,13 +347,13 @@ 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 NICs
+# the guest as the inventory lists it, with nothing but its vmid when it has no tags
my sub guest_info {
my ($vmid) = @_;
- my ($guest) = guest_inventory(vmid => $vmid)->@*;
+ my ($guest) = guest_inventory(vmid => $vmid, skip_nics => 1)->@*;
- return $guest // { vmid => int($vmid), nics => [] };
+ return $guest // { vmid => int($vmid), tags => [], nics => [] };
}
# an unmounted pmxcfs reads like a config that was never committed, and enforcement would be dropped
@@ -358,11 +394,12 @@ sub apply_all {
eval {
my $lock = PVE::RS::SDN::Microseg::ExclusiveLock->new();
my $raw = read_running_config();
- $lock->apply($raw, guest_inventory())
- or !is_configured()
- or log_warn("microseg: the running config carries no microseg block, as written"
- . " before the upgrade or by a node without microsegmentation support, leaving"
- . " enforcement unchanged");
+ if (!$lock->apply($raw, guest_inventory(skip_nics => 1))) {
+ log_warn("microseg: the running config carries no microseg block, as written"
+ . " before the upgrade or by a node without microsegmentation support, leaving"
+ . " enforcement unchanged")
+ if is_configured();
+ }
};
die "microseg: failed to apply running config: $@" if $@;
}
--
2.47.3
next prev parent reply other threads:[~2026-11-05 11:18 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 11:12 [PATCH access-control/cluster/container/docs/manager/network/proxmox{,-ve-rs,-perl-rs}/qemu-server v4 00/45] sdn: add microsegmentation support Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox v4 01/45] ebpf: build: keep the build directory out of the BPF objects Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox v4 02/45] ebpf: policy: add the enforcement subsystem for guest interfaces Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox v4 03/45] ebpf: policy: add a check for non-first fragments Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 04/45] ve-config: firewall: add a constructor for sctp matches Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 05/45] ve-config: sdn: microseg: add identity allocation for group sets Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 06/45] ve-config: sdn: microseg: add config types Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 07/45] ve-config: sdn: microseg: add tag matcher Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 08/45] ve-config: sdn: microseg: add name regex matcher Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 09/45] ve-config: sdn: microseg: narrow rules by protocol and ports Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 10/45] ve-config: sdn: microseg: add group hierarchy Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 11/45] ve-config: firewall: expose protocol, icmp type and code numbers Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 12/45] ve-config: sdn: microseg: add the desired state Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 13/45] microseg: add a crate that applies the policy to a node's guest NICs Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-ve-rs v4 14/45] microseg: add a rule option that matches non-first fragments Hannes Laimer
2026-11-05 11:12 ` [PATCH pve-cluster v4 15/45] cfs: add 'sdn/microseg.cfg' to observed files Hannes Laimer
2026-11-05 11:12 ` [PATCH pve-access-control v4 16/45] permissions: add ACL path for SDN microsegmentation Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-perl-rs v4 17/45] pve-rs: sdn: add microseg config binding Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-perl-rs v4 18/45] pve-rs: sdn: microseg: bind the data plane Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-perl-rs v4 19/45] pve-rs: sdn: microseg: check the data plane limits on render Hannes Laimer
2026-11-05 11:12 ` [PATCH proxmox-perl-rs v4 20/45] pve-rs: debian: fire the pve-microseg-update trigger on upgrade Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 21/45] sdn: zones: add vxlan-gbp option to vxlan and evpn zones Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 22/45] sdn: microseg: add config, API and guest inventory Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 23/45] sdn: dry-run: show pending microseg changes Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 24/45] sdn: microseg: enforce the policy on guest NICs Hannes Laimer
2026-11-05 11:13 ` Hannes Laimer [this message]
2026-11-05 11:13 ` [PATCH pve-network v4 26/45] sdn: microseg: add name regex matcher Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 27/45] sdn: microseg: add an update for a running NIC Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 28/45] sdn: microseg: expose protocol, port and macro rule options Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 29/45] sdn: microseg: allow nesting groups under a parent Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-network v4 30/45] sdn: microseg: expose the fragments rule option Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 31/45] network: apply the microseg policy on reload Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 32/45] pve-sdn-commit: apply the microseg policy at boot Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 33/45] ui: sdn: zones: add vxlan-gbp checkbox to vxlan and evpn Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 34/45] ui: sdn: add microsegmentation panel Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 35/45] ui: sdn: dry-run: show pending microseg diff Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 36/45] ui: sdn: microseg: add tag matcher Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 37/45] ui: sdn: microseg: add name regex matcher Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 38/45] ui: sdn: microseg: add narrowing to the rule form Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 39/45] ui: sdn: microseg: show and edit the group hierarchy Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 40/45] ui: sdn: microseg: add fragments option to the rule form Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-manager v4 41/45] ui: sdn: microseg: add a guest tab with its groups and rules Hannes Laimer
2026-11-05 11:13 ` [PATCH qemu-server v4 42/45] network: update the microseg enforcement on a tag or name change Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-container v4 43/45] lxc: update the microseg enforcement on a tag or hostname change Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-docs v4 44/45] sdn: zones: document the VXLAN-GBP option Hannes Laimer
2026-11-05 11:13 ` [PATCH pve-docs v4 45/45] sdn: add microsegmentation section Hannes Laimer
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=20261105111324.706922-26-h.laimer@proxmox.com \
--to=h.laimer@proxmox.com \
--cc=pve-devel@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.