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 B6B15990AB for ; Tue, 10 Oct 2023 12:40:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3D329317AB for ; Tue, 10 Oct 2023 12:40:52 +0200 (CEST) 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 for ; Tue, 10 Oct 2023 12:40:50 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 183BC4496D for ; Tue, 10 Oct 2023 12:40:49 +0200 (CEST) From: Philipp Hufnagl To: pve-devel@lists.proxmox.com Date: Tue, 10 Oct 2023 12:40:34 +0200 Message-Id: <20231010104034.932760-6-p.hufnagl@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231010104034.932760-1-p.hufnagl@proxmox.com> References: <20231010104034.932760-1-p.hufnagl@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.081 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 Subject: [pve-devel] [PATCH access-control v2 1/1] fix #4546: api: Return user expiration date on access/ticket API call 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: Tue, 10 Oct 2023 10:40:52 -0000 Adds an additional, optional parameter to the access/tickets api call which tells when the currently used user account will expire. If it will not expire, the parameter will not be added. Signed-off-by: Philipp Hufnagl --- src/PVE/API2/AccessControl.pm | 8 ++++++++ src/PVE/AccessControl.pm | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/PVE/API2/AccessControl.pm b/src/PVE/API2/AccessControl.pm index 74b3910..caba720 100644 --- a/src/PVE/API2/AccessControl.pm +++ b/src/PVE/API2/AccessControl.pm @@ -267,6 +267,11 @@ __PACKAGE__->register_method ({ ticket => { type => 'string', optional => 1}, CSRFPreventionToken => { type => 'string', optional => 1 }, clustername => { type => 'string', optional => 1 }, + 'account-expiry-date' => { + type => 'number', + description => "Account expiration date as a UNIX timestamp", + optional => 1 , + }, # cap => computed api permissions, unless there's a u2f challenge } }, @@ -304,6 +309,9 @@ __PACKAGE__->register_method ({ die PVE::Exception->new("authentication failure\n", code => 401); } + my $expires = PVE::AccessControl::lookup_user_expiration($username); + $res->{'account-expiry-date'} = $expires if defined($expires); + $res->{cap} = $rpcenv->compute_api_permission($username) if !defined($res->{NeedTFA}); diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm index cc0f00b..b30570b 100644 --- a/src/PVE/AccessControl.pm +++ b/src/PVE/AccessControl.pm @@ -1234,6 +1234,14 @@ sub lookup_username { return $username; } +sub lookup_user_expiration { + my ($username) = @_; + my $usercfg = cfs_read_file('user.cfg'); + my $expires = $usercfg->{users}->{$username}->{expire}; + return undef if $expires == 0; + return $expires; +} + sub normalize_path { my $path = shift; -- 2.39.2