Bug 2100464

Summary: RFE: mechanism and logind.conf option to terminate idle sessions
Product: Red Hat Enterprise Linux 9 Reporter: Jan Pazdziora (Red Hat) <jpazdziora>
Component: systemdAssignee: Michal Sekletar <msekleta>
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact: Šárka Jana <sjanderk>
Priority: medium    
Version: 9.0CC: ccheney, ggasparb, jgamba, jpazdziora, kanderso, mhaicman, msekleta, peter.vreman, rmetrich, sjanderk, systemd-maint-list, tscherf, vpolasek
Target Milestone: rcKeywords: FutureFeature, Triaged, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: systemd-250-12.el9_1 Doc Type: Release Note
Doc Text:
Story Points: ---
Clone Of:
: 2125240 (view as bug list) Environment:
Last Closed: 2022-11-15 11:18:19 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2125240    
Attachments:
Description Flags
My POC patch to add support for the SessionIdleTerminateSec parameter. none

Description Jan Pazdziora (Red Hat) 2022-06-23 12:43:53 UTC
Description of problem:

The Common Criteria OSPP SFR

  https://www.niap-ccevs.org/MMO/PP/-442-/#FMT_SMF_EXT.1.1

has as one of the security functions that the product should support session timeout. Other security policies have similar requirements.

In the past, a de facto solution was to use sshd's ClientAliveInterval and ClientAliveCountMax options. However, those options were never intended for this purpose, and on RHEL 9 with openssh rebase their behaviour has changed to the extend that it cannot be reliably used for sessions timeouts.

At the same time, systemd-logind has a notion of sessions (and not just for remote connections), and it already has some logic for handling idle sessions. Unfortunately, the IdleAction and IdleActionSec options from /etc/systemd/logind.conf deal with the whole system's status, it does not have the per-session granularity or ability to terminate idle session.

We'd like the systemd-logind's functionality to be extended with logind.conf's option SessionIdleTerminateSec (or similar name) which would set per-session idle accounting and termination of sessions idle for more then the set limit.

Version-Release number of selected component (if applicable):

systemd-250-6.el9_0.x86_64

How reproducible:

Deterministic.

Steps to Reproduce:
1. Try to setup session timeout on RHEL where idle sessions would be terminated but the system as whole would keep running.

Actual results:

It is currently not possible.

Expected results:

It should be possible for example by adding

  SessionIdleTerminateSec=10min

to /etc/systemd/logind.conf

Additional info:

Comment 3 Jan Pazdziora (Red Hat) 2022-06-23 12:49:58 UTC
Hello Michal,

I have a proof of concept patch that seems to work reasonably well on RHEL 9's systemd 250. If you feel that it might make the discussion about the approach easier, I'd be happy to attach it -- I just did not want to kick off with it in case you wanted to discuss the requirement in general first. Please let me know what approach you'd prefer.

Thank you, Jan

Comment 4 Jan Pazdziora (Red Hat) 2022-06-28 11:56:05 UTC
Created attachment 1893169 [details]
My POC patch to add support for the SessionIdleTerminateSec parameter.

Comment 5 Michal Sekletar 2022-07-12 09:55:17 UTC
I reviewed the PoC patch and it seems generally OK (and big parts of it could be used mostly w/o modification). However, there of couple of nitpicks, e.g. proposed option name should probably read "TerminateIdleSessionSec=" as other similar logind.conf options start with verb (e.g. KillUser, CleanIPC).

Bikeshedding aside, the more substential technical problem I see is reuse of existing timer that is used to dispatch idle system action. Accuracy of that timer is 30 seconds (meaning, timer is scheduled on "timeout + accuracy" where accuracy is selected from 0-30 seconds interval and stable afterwards). Hence maximum timer accuracy delay is 30 seconds. I think that is fine for current system wide timer that is set by default to 30 minutes. However, potential of up to 30 seconds delay is probably not OK as session timeout timer, moreover, if use of this newly proposed feature will be part of the RHEL's security posture/story and undergo evaluation as part of Common Criteria certification process. 

I propose we introduce new timer with higher accuracy and dispatch routine scheduled with higher priority in the event loop. Also, I think it would make sense to have more generic option, i.e. not hardcode the behavior in the option name itself. I propose we add "IdleSessionAction=(ignore|terminate|lock)" and "IdleSessionTimeout=". At this point I think we should discuss this upstream, hence I will file Github issue for this RFE and will bring this topic in the meeting we have with other upstream stakeholders.

Comment 6 Jan Pazdziora (Red Hat) 2022-07-12 16:47:00 UTC
Thanks for the review and initial thought, Michal.

As for the accuracy, having second timer would certainly help ... but I wonder if a quick way to handle things could be to set accuracy to 0 in case the TerminateIdleSessionSec set.

I don't have specific opinion about the option name. However, I specifically aimed to have that "Terminate" in the option name rather than use IdleSessionAction=(ignore|terminate|lock)" because I envisioned in the future you could have different actions enabled at the same time, at different timeouts -- something like LockIdleSessionSec=5min together with TerminateIdleSessionSec=60min.

Comment 7 Michal Sekletar 2022-08-04 13:33:53 UTC
I've discussed this with upstream stakeholders and consensus was that such feature would be very welcome and it should be introduced as a separate option, i.e. as originally proposed by Jan. I will start working on the patch, based on PoC patch provided by Jan.

Comment 8 Michal Sekletar 2022-08-08 14:48:08 UTC
First version of the PR that implements this RFE was posted upstream.

https://github.com/systemd/systemd/pull/24242

Comment 15 Dmitry Belyavskiy 2022-09-08 12:27:48 UTC
*** Bug 2022064 has been marked as a duplicate of this bug. ***

Comment 17 Plumber Bot 2022-09-12 11:38:48 UTC
fix merged to github main branch -> https://github.com/redhat-plumbers/systemd-rhel9/pull/105

Comment 19 Plumber Bot 2022-09-23 13:11:45 UTC
fix merged to github rhel-9.1.0 branch -> https://github.com/redhat-plumbers/systemd-rhel9/pull/111

Comment 27 errata-xmlrpc 2022-11-15 11:18:19 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (systemd bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:8327