[PATCH pve-network v2 1/2] fix #7077: Enforce ID format in JSON schema definitions

Arthur Bied-Charreton
2026-02-06T16:12:37Z

Add ID format constraints checked in registered formats' custom
verifiers to JSON schema definitions, so that:

1. The constraints are visible in the API docs.

2. Length constraints are checked *before* regex, which will
generate more precise error messages in case a regex has implicit
length constraints

Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---

src/PVE/Network/SDN/Controllers/IsisPlugin.pm | 3 +++
src/PVE/Network/SDN/Controllers/Plugin.pm | 3 +++
src/PVE/Network/SDN/Dns/Plugin.pm | 2 ++
src/PVE/Network/SDN/Fabrics.pm | 3 +++
src/PVE/Network/SDN/Ipams/Plugin.pm | 2 ++
src/PVE/Network/SDN/VnetPlugin.pm | 3 +++
src/PVE/Network/SDN/Zones/Plugin.pm | 3 +++
7 files changed, 19 insertions(+)

diff --git a/src/PVE/Network/SDN/Controllers/IsisPlugin.pm b/src/PVE/Network/SDN/Controllers/IsisPlugin.pm
index 3a9acfd..4c11af3 100644
--- a/src/PVE/Network/SDN/Controllers/IsisPlugin.pm
+++ b/src/PVE/Network/SDN/Controllers/IsisPlugin.pm
@@ -43,6 +43,9 @@ sub properties {
description => "Network Entity title for this node in the IS-IS network.",
type => 'string',
format => 'pve-sdn-isis-net',
+ pattern => '[a-fA-F0-9]{2}(\.[a-fA-F0-9]{4}){3,9}\.[a-fA-F0-9]{2}',
+ minLength => 20,
+ maxLength => 50,
},
};
}
diff --git a/src/PVE/Network/SDN/Controllers/Plugin.pm b/src/PVE/Network/SDN/Controllers/Plugin.pm
index d70e518..73eaa0b 100644
--- a/src/PVE/Network/SDN/Controllers/Plugin.pm
+++ b/src/PVE/Network/SDN/Controllers/Plugin.pm
@@ -22,6 +22,9 @@ PVE::JSONSchema::register_standard_option(
description => "The SDN controller object identifier.",
type => 'string',
format => 'pve-sdn-controller-id',
+ minLength => 2,
+ maxLength => 64,
+ pattern => '[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]',
},
);

diff --git a/src/PVE/Network/SDN/Dns/Plugin.pm b/src/PVE/Network/SDN/Dns/Plugin.pm
index 2864d4c..8e623ba 100644
--- a/src/PVE/Network/SDN/Dns/Plugin.pm
+++ b/src/PVE/Network/SDN/Dns/Plugin.pm
@@ -24,6 +24,8 @@ PVE::JSONSchema::register_standard_option(
description => "The SDN dns object identifier.",
type => 'string',
format => 'pve-sdn-dns-id',
+ pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]',
+ minLength => 2,
},
);

diff --git a/src/PVE/Network/SDN/Fabrics.pm b/src/PVE/Network/SDN/Fabrics.pm
index d90992a..c65eae6 100644
--- a/src/PVE/Network/SDN/Fabrics.pm
+++ b/src/PVE/Network/SDN/Fabrics.pm
@@ -28,6 +28,9 @@ PVE::JSONSchema::register_standard_option(
description => "Identifier for SDN fabrics",
type => 'string',
format => 'pve-sdn-fabric-id',
+ pattern => '[a-zA-Z0-9][a-zA-Z0-9-]{0,6}[a-zA-Z0-9]',
+ minLength => 2,
+ maxLength => 8,
},
);

diff --git a/src/PVE/Network/SDN/Ipams/Plugin.pm b/src/PVE/Network/SDN/Ipams/Plugin.pm
index a986a92..422fbc8 100644
--- a/src/PVE/Network/SDN/Ipams/Plugin.pm
+++ b/src/PVE/Network/SDN/Ipams/Plugin.pm
@@ -25,6 +25,8 @@ PVE::JSONSchema::register_standard_option(
description => "The SDN ipam object identifier.",
type => 'string',
format => 'pve-sdn-ipam-id',
+ pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]',
+ minLength => 2,
},
);

diff --git a/src/PVE/Network/SDN/VnetPlugin.pm b/src/PVE/Network/SDN/VnetPlugin.pm
index 717438c..5ceb3a1 100644
--- a/src/PVE/Network/SDN/VnetPlugin.pm
+++ b/src/PVE/Network/SDN/VnetPlugin.pm
@@ -22,6 +22,9 @@ PVE::JSONSchema::register_standard_option(
description => "The SDN vnet object identifier.",
type => 'string',
format => 'pve-sdn-vnet-id',
+ pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]',
+ minLength => 2,
+ maxLength => 8,
},
);

diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm
index 826ebdf..2a02278 100644
--- a/src/PVE/Network/SDN/Zones/Plugin.pm
+++ b/src/PVE/Network/SDN/Zones/Plugin.pm
@@ -24,6 +24,9 @@ PVE::JSONSchema::register_standard_option(
description => "The SDN zone object identifier.",
type => 'string',
format => 'pve-sdn-zone-id',
+ pattern => '[a-zA-Z][a-zA-Z0-9]*[a-zA-Z0-9]',
+ minLength => 2,
+ maxLength => 8,
},
);

--
2.47.3