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 64D139824A for ; Fri, 6 Oct 2023 15:16:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4E0E0B4C for ; Fri, 6 Oct 2023 15:16:28 +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 ; Fri, 6 Oct 2023 15:16:26 +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 D90EB44871 for ; Fri, 6 Oct 2023 15:16:25 +0200 (CEST) Message-ID: <8bb962b1-0078-4b5d-84b6-d0859ad7d5d5@proxmox.com> Date: Fri, 6 Oct 2023 15:16:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Lukas Wagner To: Proxmox VE development discussion , Philipp Hufnagl References: <20230922143658.1639173-1-p.hufnagl@proxmox.com> <20230922143658.1639173-3-p.hufnagl@proxmox.com> Content-Language: de-AT, en-US In-Reply-To: <20230922143658.1639173-3-p.hufnagl@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.028 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [accesscontrol.pm] Subject: Re: [pve-devel] [PATCH access-control v1 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: Fri, 06 Oct 2023 13:16:28 -0000 Comments inline. On 9/22/23 16:36, Philipp Hufnagl wrote: > 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..e562a97 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 }, > + user_expires => { I'd prefer a different property name. `user_expires` kinda suggests it to be a boolean variable (e.g. whether the user expires at *some point*) How about `account-expiry-date`? Also note that prefer to use hyphens (-) instead of underscores (_) for new properties. > + type => 'number', > + description => "When the user account expires.", I'd maybe elaborate a bit: "Account expiration date as a UNIX timestamp" or something like that. > + 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 $exp = PVE::AccessControl::lookup_user_expiration($username); > + $res->{user_expieres} = $exp if defined($exp); Typo in `user_expieres` Nit: maybe call it $expires/$expiry instead of $exp. Not much longer but easier to follow. > + > $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..471cc92 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 $exp = $usercfg->{users}->{$username}->{expire}; > + return undef if $exp == 0; > + return $exp; > +} Nit: Same as above -- - Lukas