all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH ha-manager 2/2] api: rules: check for non-empty nodes and resources properties
Date: Wed, 11 Mar 2026 13:49:36 +0100	[thread overview]
Message-ID: <20260311125008.271334-3-d.kral@proxmox.com> (raw)
In-Reply-To: <20260311125008.271334-1-d.kral@proxmox.com>

The 'resources' property is required (i.e., not optional) for all rule
types and the 'nodes' property is required for node affinity rules.

Though setting these as required does not prevent users from setting
them to an empty string as non-optional properties are only checked for
definedness in PVE::JSONSchema at the moment.

This allows users to write invalid rule sections to the rules config as
subsequent config reads will complain about the missing required options
not being set as PVE::SectionConfig::write_config(...) will drop these
if their values evaluate to empty strings.

Therefore, add an additional check to prevent users from being able to
pass empty nodes and/or resource lists when creating or modifying
existing HA rules.

Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=7399
Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 src/PVE/API2/HA/Rules.pm | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/PVE/API2/HA/Rules.pm b/src/PVE/API2/HA/Rules.pm
index 046a4a9b..f09ab362 100644
--- a/src/PVE/API2/HA/Rules.pm
+++ b/src/PVE/API2/HA/Rules.pm
@@ -42,9 +42,11 @@ my $get_api_ha_rule = sub {
     return $cfg;
 };
 
-my $assert_resources_are_configured = sub {
+my $assert_valid_resources_param = sub {
     my ($resources) = @_;
 
+    die "no resources were specified\n" if !%$resources;
+
     my $unconfigured_resources = [];
 
     for my $resource (sort keys %$resources) {
@@ -56,9 +58,11 @@ my $assert_resources_are_configured = sub {
         if @$unconfigured_resources;
 };
 
-my $assert_nodes_do_exist = sub {
+my $assert_valid_nodes_param = sub {
     my ($nodes) = @_;
 
+    die "no nodes were specified\n" if !%$nodes;
+
     my $nonexistent_nodes = [];
     my $localnode = PVE::INotify::nodename();
 
@@ -281,8 +285,8 @@ __PACKAGE__->register_method({
 
                 die "HA rule '$ruleid' already defined\n" if $rules->{ids}->{$ruleid};
 
-                $assert_resources_are_configured->($opts->{resources});
-                $assert_nodes_do_exist->($opts->{nodes}) if $opts->{nodes};
+                $assert_valid_resources_param->($opts->{resources});
+                $assert_valid_nodes_param->($opts->{nodes}) if $opts->{nodes};
 
                 $rules->{order}->{$ruleid} = PVE::HA::Rules::get_next_ordinal($rules);
                 $rules->{ids}->{$ruleid} = $opts;
@@ -339,8 +343,8 @@ __PACKAGE__->register_method({
                 my $plugin = PVE::HA::Rules->lookup($type);
                 my $opts = $plugin->check_config($ruleid, $param, 0, 1);
 
-                $assert_resources_are_configured->($opts->{resources});
-                $assert_nodes_do_exist->($opts->{nodes}) if $opts->{nodes};
+                $assert_valid_resources_param->($opts->{resources});
+                $assert_valid_nodes_param->($opts->{nodes}) if $opts->{nodes};
 
                 my $options = $plugin->private()->{options}->{$type};
                 PVE::SectionConfig::delete_from_config($rule, $options, $opts, $delete);
-- 
2.47.3





  parent reply	other threads:[~2026-03-11 12:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 12:49 [PATCH ha-manager 0/2] fix #7399: check if required rule props are set Daniel Kral
2026-03-11 12:49 ` [PATCH ha-manager 1/2] rules: ensure rule is defined and has type in set_rule_defaults Daniel Kral
2026-03-12  9:49   ` Fiona Ebner
2026-03-11 12:49 ` Daniel Kral [this message]
2026-03-11 17:06 ` applied: [PATCH ha-manager 0/2] fix #7399: check if required rule props are set Thomas Lamprecht
2026-03-12  8:43   ` Daniel Kral

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=20260311125008.271334-3-d.kral@proxmox.com \
    --to=d.kral@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal