From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id A3A2C1FF14C for ; Fri, 12 Jun 2026 19:42:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id ACF4D1888D; Fri, 12 Jun 2026 19:42:30 +0200 (CEST) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Subject: [PATCH pmg-api v3 1/5] config: add root_only paramter option. Date: Fri, 12 Jun 2026 19:40:58 +0200 Message-ID: <20260612174145.1190233-2-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260612174145.1190233-1-s.ivanov@proxmox.com> References: <20260612174145.1190233-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1781286064809 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.084 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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: OPYQK2Z4EBUCX5YWJNWWRHH6WLRUXIGD X-Message-ID-Hash: OPYQK2Z4EBUCX5YWJNWWRHH6WLRUXIGD X-MailFrom: s.ivanov@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 Mail Gateway development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: this introduces a way to have some options in our pmg.conf SectionConfig restricted to 'root@pam' only. I skimmed the (quite improved) documentation in PVE::SectionConfig, and did not see any blockers to extending adding other options instead of 'optional' and 'fixed' there. This is needed to have unified way to check if a particular option should be restricted to 'root@pam' only. Signed-off-by: Stoiko Ivanov --- src/PMG/API2/Config.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/PMG/API2/Config.pm b/src/PMG/API2/Config.pm index 9cce95dd..6edde9b4 100644 --- a/src/PMG/API2/Config.pm +++ b/src/PMG/API2/Config.pm @@ -10,6 +10,7 @@ use HTTP::Status qw(:constants); use Storable qw(dclone); use PVE::JSONSchema qw(get_standard_option); use PVE::RESTHandler; +use PVE::Exception qw(raise_perm_exc); use Time::HiRes qw(); use PMG::Config; @@ -194,14 +195,21 @@ my $api_update_config_section = sub { die "no options specified\n" if !$delete_str && !scalar(keys %$param); + my $plugin = PMG::Config::Base->lookup($section); + my $rpcenv = PMG::RESTEnvironment->get(); + my $authuser = $rpcenv->get_user(); + foreach my $opt (PVE::Tools::split_list($delete_str)) { + my $is_root_only = $plugin->options()->{$opt}->{root_only}; + raise_perm_exc() if ( $is_root_only && $authuser ne 'root@pam') ; delete $ids->{$section}->{$opt}; } - my $plugin = PMG::Config::Base->lookup($section); my $config = $plugin->check_config($section, $param, 0, 1); foreach my $p (keys %$config) { + my $is_root_only = $plugin->options()->{$p}->{root_only}; + raise_perm_exc() if ( $is_root_only && $authuser ne 'root@pam') ; $ids->{$section}->{$p} = $config->{$p}; } -- 2.47.3