From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 84E3A6907D for ; Fri, 11 Mar 2022 12:25:52 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 04EB52367A for ; Fri, 11 Mar 2022 12:25:24 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id E84B9235CE for ; Fri, 11 Mar 2022 12:25:19 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id BD6CC45917 for ; Fri, 11 Mar 2022 12:25:19 +0100 (CET) From: Oguz Bektas To: pve-devel@lists.proxmox.com Date: Fri, 11 Mar 2022 12:25:03 +0100 Message-Id: <20220311112504.595964-12-o.bektas@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311112504.595964-1-o.bektas@proxmox.com> References: <20220311112504.595964-1-o.bektas@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.590 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH v2 access-control 11/12] api: allow superusers to edit tfa and password settings X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Mar 2022 11:25:52 -0000 Signed-off-by: Oguz Bektas --- v1->v2: * also adapt change_password * didn't remove the comments in TFA.pm since it was still confusing without them src/PVE/API2/AccessControl.pm | 6 ++++++ src/PVE/API2/TFA.pm | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/PVE/API2/AccessControl.pm b/src/PVE/API2/AccessControl.pm index 5d78c6f..1b471f6 100644 --- a/src/PVE/API2/AccessControl.pm +++ b/src/PVE/API2/AccessControl.pm @@ -378,9 +378,15 @@ __PACKAGE__->register_method ({ $rpcenv->check_user_exist($userid); + # check for SU privs on user groups + my $is_superuser = $rpcenv->check($authuser, "/access/groups", ['SuperUser'], 1); + if ($authuser eq 'root@pam') { # OK - root can change anything } else { + if ($is_superuser && $userid ne 'root@pam') { + # OK - superusers can change any user's password except root@pam + } if ($authuser eq $userid) { $rpcenv->check_user_enabled($userid); # OK - each user can change its own password diff --git a/src/PVE/API2/TFA.pm b/src/PVE/API2/TFA.pm index bee4dee..bab78ea 100644 --- a/src/PVE/API2/TFA.pm +++ b/src/PVE/API2/TFA.pm @@ -102,13 +102,16 @@ my $TFA_UPDATE_INFO_SCHEMA = { my sub root_permission_check : prototype($$$$) { my ($rpcenv, $authuser, $userid, $password) = @_; + # authuser = the user making the change + # userid = the user to be changed ($userid, undef, my $realm) = PVE::AccessControl::verify_username($userid); $rpcenv->check_user_exist($userid); - raise_perm_exc() if $userid eq 'root@pam' && $authuser ne 'root@pam'; + my $is_superuser = $authuser eq 'root@pam' || $rpcenv->check($authuser, "/access/groups", ['SuperUser'], 1); + raise_perm_exc() if $userid eq 'root@pam' && !$is_superuser; # root@pam can be only edited by superusers # Regular users need to confirm their password to change TFA settings. - if ($authuser ne 'root@pam') { + if ($authuser ne 'root@pam') { # we still do password confirmation for superusers like the other users raise_param_exc({ 'password' => 'password is required to modify TFA data' }) if !defined($password); -- 2.30.2