-
Medium/Average (~15 mins)
-
Use Session Recording to help log and audit users' terminal sessions and correlate them with system logs
The Terminal Session Recording project aims to log users' terminal sessions for the purposes of audit, security, and monitoring. It provides an interface in Cockpit to analyze these recordings and correlate them with system logs. This provides a comprehensive picture of the activity that took place.
In this lab, you first assume the role of a third-party contractor who breaks something on your system and then the role of a system administrator who needs to find out what has happened on that system.
-
Install the required
tlog
andcockpit-session-recording
packages -
Configure them to record terminal activity for specific users
The tlog
package allows you to records terminal activity by putting itself between the user and the terminal. Systemd Journal is used as a storage for recorded sessions.
The cockpit-session-recording
package for Cockpit uses provided APIs to access the Systemd Journal and obtain sessions from it. It provides a JavaScript-based player, which produces text output, but with video player-style controls.
A few packages are already installed for you:
-
tlog
-
Cockpit
-
cockpit-session-recording
-
mc
-
nginx
-
vim
-
Return to your Lab Information web page from the Lab 0: Setup Steps and click CONSOLE for your workstation bastion host:
-
Log in as lab-user with r3dh4t1! as the password:
-
Open a Firefox web browser:
-
Log in as the root user with r3dh4t1! as the password:
-
Click the Session Recording menu item:
-
In the upper right corner, click the cog button to access the configuration:
-
Examine the configuration of
tlog-rec-session.conf
, shown in Cockpit in the General Configuration dialog: -
Click Log User’s Input to enable logging of the user’s input, then click Save:
-
In the SSD Configuration dialog, entering Some for Scope and q for Users to set up the q user to be recorded using
cockpit-session-recording
, and then click Save:The q user is set up to be recorded.
In this section, you create some activity by one of the recorded users to be able to play it back in Cockpit.
-
Open Terminal:
-
Use SSH to log in to the same machine, using session1 as the password:
[lab-user@sessionrecording]# ssh [email protected]
-
Upon login, expect to see a terminal message informing the user that the session is being recorded:
Remember that this session is being recorded. Later, you can try to resize the session window to see if that is supported.
-
Launch GNU Midnight Commander (
mc
):[q@sessionrecording]$ mc
Expect
mc
to launch: -
Navigate to various directories to explore them, then press F10 or click Quit in the right corner.
In this section, you imitate a real-world scenario by breaking the nginx
web server configuration file and then address the problem using session recording in Cockpit.
-
Edit the nginx configuration file:
[q@sessionrecording]$ sudo vi /etc/nginx/nginx.conf
-
In the line
worker_connections 1024;
, remove the;
to introduce an error: -
Restart the
nginx
server:[q@sessionrecording]$ sudo systemctl restart nginx
The restart fails due to the error you created in the
nginx.conf
file.Expect to see an error message similar to this:
In this section, you log in to Cockpit and use cockpit-session-recording
to investigate why the web server does not work.
-
Go to your Lab Information webpage from Lab 0: Setup Steps and click CONSOLE for your workstation’s bastion host:
-
Log in as lab-user with r3dh4t1! as the password:
-
Open a Firefox web browser:
-
Log in as root with r3dh4t1! as the password:
-
Click the Session Recording menu item:
-
When your session appears in the list of sessions, click it to open it:
Expect your data to be different.
-
Click Play to start the playback of the session (you can also press the hotkey p to achieve the same results):
-
Enter
nginx
in the search bar to search for the first instance of thenginx
keyword in the session:This shows the closest beginning of "frame" that matches the keyword entered.
In Session Player, the action of restarting
nginx
looks similar to this:Expect to find the corresponding messages at the bottom of the page:
-
Click the timestamp event in the logs panel to jump to the same time in the session.
-
Search for
nginx.conf
to find the time when the configuration file was edited, showing the nearest time: -
Rewind the player position to that time.