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 D615B1FF0DE for ; Thu, 19 Nov 2026 13:48:15 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 14910217B9; Thu, 19 Nov 2026 13:47:48 +0100 (CET) From: David Riley To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager v5 5/6] fix #7294: api: pool: add SDN VNets as pool members Date: Thu, 19 Nov 2026 13:47:30 +0100 Message-ID: <20261119124731.84602-6-d.riley@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261119124731.84602-1-d.riley@proxmox.com> References: <20261119124731.84602-1-d.riley@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795092461748 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.621 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: FT2G6W7UVKRIADKZJQQJFYJ3KABRFQUS X-Message-ID-Hash: FT2G6W7UVKRIADKZJQQJFYJ3KABRFQUS X-MailFrom: d.riley@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: Extend the pool API to accept SDN VNets as pool members under the 'network' parameter. Accept comma-separated lists of network resources for VNets. These can include optional VLAN tags or a wildcard (*) to propagate access to all untagged and tagged traffic. Unlike VMs or containers which strictly belong to a single pool, VNets are shared similar to storage. A single VNet can be assigned to multiple pools simultaneously, allowing cross-team usage without management conflicts. Enforce a cluster-wide version check before allowing network assignments. This prevents older nodes from accidentally overwriting the newly structured pool configurations. Suggested-by: Daniel Kral Signed-off-by: David Riley Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7294 --- PVE/API2/Pool.pm | 176 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 171 insertions(+), 5 deletions(-) diff --git a/PVE/API2/Pool.pm b/PVE/API2/Pool.pm index f1f67e84..9a51559f 100644 --- a/PVE/API2/Pool.pm +++ b/PVE/API2/Pool.pm @@ -7,7 +7,11 @@ use PVE::AccessControl; use PVE::Cluster qw (cfs_read_file cfs_write_file); use PVE::Exception qw(raise_param_exc); use PVE::INotify; +use PVE::JSONSchema; +use PVE::Network::SDN::Vnets; +use PVE::Network::SDN::Zones; use PVE::Storage; +use PVE::Tools; use PVE::SafeSyslog; @@ -16,6 +20,37 @@ use PVE::RESTHandler; use base qw(PVE::RESTHandler); +use constant NETWORK_VNET_REGEX => qr!^vnet/([^/]+)/([^/]+)(?:/([1-9][0-9]{0,3}|\*))?$!; + +sub pve_verify_pool_network { + my ($value, $noerr) = @_; + + if ($value !~ NETWORK_VNET_REGEX) { + return undef if $noerr; + die "Value '$value' is not a valid pool network vnet string" + . " (vnet//[/|/*])\n"; + } + my ($zone, $vnet, $tag) = ($1, $2, $3); + + eval { + PVE::JSONSchema::check_format('pve-sdn-zone-id', $zone); + PVE::JSONSchema::check_format('pve-sdn-vnet-id', $vnet); + + if (defined($tag) && $tag ne '*' && $tag > 4094) { + die "VLAN tag '$tag' out of range (1-4094)\n"; + } + }; + + if (my $err = $@) { + return undef if $noerr; + die $err; + } + + return $value; +} + +PVE::JSONSchema::register_format('pve-pool-network', \&pve_verify_pool_network); + __PACKAGE__->register_method({ name => 'index', path => '', @@ -36,7 +71,7 @@ __PACKAGE__->register_method({ }, type => { type => 'string', - enum => ['qemu', 'lxc', 'storage'], + enum => ['qemu', 'lxc', 'storage', 'network'], optional => 1, requires => 'poolid', }, @@ -61,13 +96,14 @@ __PACKAGE__->register_method({ properties => { type => { type => 'string', - enum => ['qemu', 'lxc', 'openvz', 'storage'], + enum => ['qemu', 'lxc', 'openvz', 'storage', 'network'], }, id => { type => 'string', }, node => { type => 'string', + optional => 1, }, vmid => { type => 'integer', @@ -77,6 +113,13 @@ __PACKAGE__->register_method({ type => 'string', optional => 1, }, + 'network-type' => { + type => 'string', + enum => ['vnet'], + optional => 1, + description => + 'Type of the network resource (only for network members).', + }, }, }, }, @@ -135,6 +178,27 @@ __PACKAGE__->register_method({ } } + if (!defined($param->{type}) || $param->{type} eq 'network') { + for my $net_key (sort keys $pool_config->{network}->%*) { + my ($type, @path) = split('/', $net_key); + + if ($type eq 'vnet') { + my ($zoneid, $vnet, $tag) = @path; + + my $description = "$vnet ($zoneid)"; + $description = "$vnet.$tag ($zoneid)" if defined($tag); + + push @$members, + { + type => 'network', + 'network-type' => $type, + id => $net_key, + text => $description, + }; + } + } + } + my $pool_info = { members => $members, }; @@ -243,6 +307,13 @@ __PACKAGE__->register_method({ format => 'pve-storage-id-list', optional => 1, }, + network => { + description => 'List of network resources to add or remove from this pool.', + type => 'string', + typetext => 'vnet//[/|/*]', + format => 'pve-pool-network-list', + optional => 1, + }, 'allow-move' => { description => 'Allow adding a guest even if already in another pool.' . ' The guest will be removed from its current pool and added to this one.', @@ -295,6 +366,13 @@ __PACKAGE__->register_method({ format => 'pve-storage-id-list', optional => 1, }, + network => { + description => 'List of network resources to add or remove from this pool.', + type => 'string', + typetext => 'vnet//[/|/*]', + format => 'pve-pool-network-list', + optional => 1, + }, 'allow-move' => { description => 'Allow adding a guest even if already in another pool.' . ' The guest will be removed from its current pool and added to this one.', @@ -304,7 +382,8 @@ __PACKAGE__->register_method({ }, delete => { description => - 'Remove the passed VMIDs and/or storage IDs instead of adding them.', + 'Remove the passed VMIDs, storage IDs and/or network resources instead of' + . ' adding them.', type => 'boolean', optional => 1, default => 0, @@ -373,6 +452,77 @@ __PACKAGE__->register_method({ } } + if (defined($param->{network})) { + if (!$param->{delete}) { + # FIXME: MAJOR VERSION: 10.0 remove gatekeeper + # nodes without support for network pool members drop them when + # rewriting user.cfg, so all nodes must support them before adding + PVE::Cluster::assert_min_cluster_version(9, 2, 30); + } + + my $zones_cfg = PVE::Network::SDN::Zones::config(1); + my $vnets_cfg = PVE::Network::SDN::Vnets::config(1); + + my $network_param = $param->{network}; + for my $network (PVE::Tools::split_list($network_param)) { + next if $network !~ NETWORK_VNET_REGEX; + my ($zone, $vnetid, $tag) = ($1, $2, $3); + + my $network_key = "vnet/$zone/$vnetid"; + my $acl_path = "/sdn/zones/$zone/$vnetid"; + + if (defined($tag)) { + $network_key .= "/$tag"; + $acl_path .= "/$tag" if $tag ne "*"; + } + + $rpcenv->check_perm_modify($authuser, $acl_path); + + if ($param->{delete}) { + die "Network resource '$network_key' is not a pool member\n" + if !$pool_config->{network}->{$network_key}; + + delete $pool_config->{network}->{$network_key}; + next; + } + + die "SDN zone '$zone' does not exist or is not applied\n" + if !$zones_cfg->{ids}->{$zone}; + + my $vnet_data = $vnets_cfg->{ids}->{$vnetid} + or die "VNet '$vnetid' does not exist or is not applied\n"; + + die "VNet '$vnetid' does not belong to zone '$zone'\n" + if $zone ne $vnet_data->{zone}; + + die + "VNet '$vnetid' is not VLAN-aware, cannot assign a specific VLAN tag\n" + if (defined($tag) && !$vnet_data->{vlanaware}); + + # a wildcard grants the pool's roles on all tags of the VNet, so the + # user's SDN.Allocate must propagate to them + if (defined($tag) && $tag eq '*') { + my $auth_user_privs = $rpcenv->permissions($authuser, $acl_path); + + if ( + !defined($auth_user_privs->{'Permissions.Modify'}) + && !$auth_user_privs->{'SDN.Allocate'} + ) { + raise_param_exc({ + network => + "Cannot add '$network_key' - requires 'Permissions.Modify'" + . " or propagated 'SDN.Allocate' on '$acl_path'", + }); + } + } + + die "Network resource '$network_key' is already a pool member\n" + if ($pool_config->{network}->{$network_key}); + + $pool_config->{network}->{$network_key} = 1; + } + } + cfs_write_file("user.cfg", $usercfg); }, "update pools failed", @@ -400,7 +550,7 @@ __PACKAGE__->register_method({ }, type => { type => 'string', - enum => ['qemu', 'lxc', 'storage'], + enum => ['qemu', 'lxc', 'storage', 'network'], optional => 1, }, }, @@ -421,13 +571,14 @@ __PACKAGE__->register_method({ properties => { type => { type => 'string', - enum => ['qemu', 'lxc', 'openvz', 'storage'], + enum => ['qemu', 'lxc', 'openvz', 'storage', 'network'], }, id => { type => 'string', }, node => { type => 'string', + optional => 1, }, vmid => { type => 'integer', @@ -437,6 +588,13 @@ __PACKAGE__->register_method({ type => 'string', optional => 1, }, + 'network-type' => { + type => 'string', + enum => ['vnet'], + optional => 1, + description => + 'Type of the network resource (only for network members).', + }, }, }, }, @@ -524,6 +682,14 @@ __PACKAGE__->register_method({ die "pool '$pool' is not empty (contains storage '$storeid')\n"; } + for my $netid (sort keys $pool_config->{network}->%*) { + my ($type, $id) = split('/', $netid, 2); + $type = 'network' if !defined($type); + $id = $netid if !defined($id); + + die "pool '$pool' is not empty (contains $type '$id')\n"; + } + delete($usercfg->{pools}->{$pool}); PVE::AccessControl::delete_pool_acl($pool, $usercfg); -- 2.47.3