Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XRDP not updating lastlog info. #1302

Closed
kenleach2 opened this issue Mar 7, 2019 · 25 comments
Closed

XRDP not updating lastlog info. #1302

kenleach2 opened this issue Mar 7, 2019 · 25 comments
Labels

Comments

@kenleach2
Copy link

Running xrdp 0.9.6 and have found that user lastlog information is not being updated, after a user connects and successfully logs in. We are running Red Hat Enterprise Linux 6.7 and 7.6.

This prevents certain security rules from being applied, as the user would be locked out, due to inactivity.

@metalefty
Copy link
Member

Yes, xrdp doesn't update the info right now. I think that feature is needed. I stack it as a "feature request".

@shaneforsythe
Copy link

This appears to be similar to Pull Request #1077 and issue #870

@metalefty
Copy link
Member

This should be done after #1961.

@matt335672
Copy link
Member

Pardon me for jumping in, but as far as I can see this should work already if it's correctly configured. This is based on my experiences with using the EPEL xrdp RPM in a previous life as a sysadmin.

The lastlog file is maintained by pam_lastlog.so. On RHEL/etc 7 systems, this is called as part of /etc/pam.d/postlogin

If you're using the EPEL xrdp RPM, /etc/pam.d/xrdp-sesman looks like this:-

#%PAM-1.0
# Generic Fedora config
auth       include      password-auth
account    include      password-auth
password   include      password-auth
session    include      password-auth

# Gnome specific Fedora config
#auth       include      gdm-password
#account    include      gdm-password
#password   include      gdm-password
#session    include      gdm-password

On GNOME-only systems, the system manager needs to update this file to work correctly. This is ALL RHEL/etc systems where only GNOME is installed. Otherwise some GNOME features won't work correctly.

If this is done, the problem should be fixed for GNOME, as /etc/pam.d/gdm-password correctly includes the postlogin section.

On non-GNOME systems, the file maybe needs to look like this to get it working:-

#%PAM-1.0
# Generic Fedora config
auth       include      password-auth
account    include      password-auth
password   include      password-auth
session    include      password-auth
# Needed for lastlog support
session    include      postlogin

# Gnome specific Fedora config
#auth       include      gdm-password
#account    include      gdm-password
#password   include      gdm-password
#session    include      gdm-password

In any case I don't think it's an XRDP issue, but a packaging issue.

@kenleach2, @shaneforsythe, @ibaldonl - can one of you look into this and see if it solves your problem?

@kenleach2
Copy link
Author

kenleach2 commented Sep 22, 2021 via email

@matt335672
Copy link
Member

@kenleach2 - thanks for coming back to me.

First thing to say is I absolutely agree that we should be making the correct calls to update wtmp and utmp and I've made a note of this against #1961.

I've fired up a CentOS 7 VM to look at this in more detail, and to dig into the authconfig Python script. My immediate observations are:-

  1. The config I've suggested above won't work
  2. I may have something at least a little useful for you in the short term.

The reason the config I've given you is useless is that config generated by authconfig in /etc/pam.d/lastlogin isn't that configurable. For non GDM sessions, the line which is executed is this:-

session     optional      pam_lastlog.so silent noupdate showfailed

The net effect is simply to show the last failed login time to the user.

The only way I can see to change the behaviour of authconfig is to modify /usr/share/authconfig/authinfo.py which I can't recommend.

However, I had some success with this file:-

#%PAM-1.0
# Generic Fedora config
auth       include      password-auth
account    include      password-auth
password   include      password-auth
session    include      password-auth
# Update lastlog and wtmp
session    optional     pam_lastlog.so silent


# Gnome specific Fedora config
#auth       include      gdm-password
#account    include      gdm-password
#password   include      gdm-password
#session    include      gdm-password

With this,, at least /var/log/lastlog and /var/log/wtmp are updated. On my VM I've got a testuser used exclusively for xrdp:-

$ lastlog | grep testuser
testuser         :10                       Thu Sep 23 09:50:12 +0100 2021
$ who /var/log/wtmp | grep testuser
testuser :10          2021-09-23 09:49
testuser :10          2021-09-23 09:50

I've also had a quick look at CentOS 8 and authselect. This is slightly more configurable, but not in a useful way. However, the workaround above should also work.

To solve the mystery of how openssh updates lastlog, I had to poke around in the openssh sources. OpenSSH updates lastlog itself directly. I think it unlikely that we'll be following this path, as PAM is available, but it's always an option.

If anyone following this thread thinks this is useful for RHEL/CentOS/etc until we're updating utmp and wtmp directly, I can start a Bugzilla conversation with Red Hat.

@matt335672 matt335672 mentioned this issue Sep 23, 2021
@kenleach2
Copy link
Author

kenleach2 commented Sep 23, 2021 via email

@matt335672
Copy link
Member

Thanks for the info @kenleach2.

For the benefit of others who may be in the same position as you, would you be able to share your script? If you can, feel free to reply via email, and I'll tidy up your response so it's readable in this thread.

If anyone else would like to comment on the changes to /etc/pam.d/xrdp-sesman above, please do. I think there may be some value in starting the conversation with Red Hat ASAP (the maintainer Bojan is very helpful) but I need some user experiences to guide me here. For clarity, this particular script is delivered by the EPEL RPM rather than by us. I don't think I made that at all clear.

@kenleach2
Copy link
Author

kenleach2 commented Sep 23, 2021 via email

@matt335672
Copy link
Member

Thanks @kenleach2 - that's very kind and may be of use to others reading this thread as another option.

As it happens, my options for tidying up your reply are limited as apparently email replies do not support markdown. However, it should be a simple matter to recover your files from your message above.

@moobyfr
Copy link
Contributor

moobyfr commented Sep 23, 2021

As the main author of the wtmp branch, I wasn't aware of the module pam_lastlog (didn't look the evolution since the last decade!)
This pam module seems to make the job. As the PAM stack seems the default on most system (linux, freebsd), this should really the way to go.

@kenleach2
Copy link
Author

kenleach2 commented Sep 23, 2021 via email

@matt335672
Copy link
Member

pam_lastlog on Linux doesn't update utmp, so it's not a complete solution. Oddly, it looks like it does on FreeBSD but I haven't checked the code.

@kenleach2 - what systems are you using? The reason I ask is that /etc/pam.d/xrdp-sesman on RHEL/CentOS/etc is not the one supplied by us, but rather it's supplied by EPEL. Also, modifying this file will not affect the way that other login methods work.

@kenleach2
Copy link
Author

kenleach2 commented Sep 24, 2021 via email

@matt335672
Copy link
Member

I'm pretty sure based on my CentOS 7 testing you can get something working using pam_lastlog. That might depend on the minor versions you are using possibly.

RHEL 6 seems to be using linux-pam 1.1.1, which contains the pam_lastlog module, at least. There have been quite a few changes to the module since then.

EPEL for RHEL 6 is now retired, so you won't be able to get xrdp updates from this route anyway. Do I take it from that you're building from source? gcc 4.4 isn't something we build with on a regular basis any more, so there could conceivably be compiler issues.

@kenleach2
Copy link
Author

kenleach2 commented Sep 24, 2021 via email

@matt335672
Copy link
Member

Thanks for the update @kenleach2 .

If you can find some time to investigate this further, we could possibly both benefit. I'm pretty sure my change to /etc/xrdp/xrdp-sesman can work for you, but I need more to back this up than 'it works for me'. At the same time, it would be good for you to get to the bottom of why you're getting unreliable results from your PAM configurations. Even if we move code into sesman to update wtmp and lastlog, it won't be doing anything that the PAM module isn't doing. There could well be something in your setup I'm not anticipating, and since I'm looking at restructuring our PAM interface at the moment I'd really like to understand what that might be.

I've taken the trouble to knock up a script for CentOS 7 (I know it's not exactly the same as Red Hat) which takes a minimal install, adds a GNOME desktop and gets xrdp working with the modifications I've described above.

I add a user 'testuser' as part of my minimal install. After running the script, testuser is correctly added to lastlog when I log in

I'm hoping you'll be able to use this script in your environment to figure out where the gap is. I'll be happy to help you with that.

Script is:-

#!/bin/sh

# Run this on an updated minimal CentOS install

# Configure desktop
yum group install -y "GNOME Desktop"
systemctl set-default graphical.target

# Install xrdp
yum install -y epel-release
yum install -y xrdp xrdp-selinux
systemctl enable xrdp xrdp-sesman
firewall-cmd --permanent --add-port=3389/tcp

# Patch /etc/pam.d/xrdp-sesman
if [ ! -x /usr/bin/patch ]; then
    yum install -y patch
fi
cd /etc/pam.d/
patch -b <<EOF
--- xrdp-sesman.orig    2021-09-27 11:25:07.211842645 +0100
+++ xrdp-sesman 2021-09-27 11:27:43.511277088 +0100
@@ -1,12 +1,14 @@
 #%PAM-1.0
 # Generic Fedora config
-auth       include      password-auth
-account    include      password-auth
-password   include      password-auth
-session    include      password-auth
+#auth       include      password-auth
+#account    include      password-auth
+#password   include      password-auth
+#session    include      password-auth

 # Gnome specific Fedora config
-#auth       include      gdm-password
-#account    include      gdm-password
-#password   include      gdm-password
-#session    include      gdm-password
+auth       include      gdm-password
+account    include      gdm-password
+password   include      gdm-password
+session    include      gdm-password
+# Update lastlog and wtmp
+session    optional     pam_lastlog.so silent
EOF

# Done
echo "System is now configured"
echo "Please reboot for the changes to take effect"

@kenleach2
Copy link
Author

kenleach2 commented Sep 27, 2021 via email

@matt335672
Copy link
Member

I'm in no great rush for this.

At some stage we'll revisit this area and make the changes we think are necessary to support this functionality. Whether that's in the app, or via PAM is not yet decided. Any additional information would be useful if you're able to provide it.

If anyone else reading this thread want to comment, please do.

@jtcleek
Copy link

jtcleek commented Feb 25, 2022

The supplied edit to /etc/pam.d/xrdp-sesman fixed my xrdp lastlog issues on RHEL8

@dosmage
Copy link

dosmage commented Oct 22, 2023

I just wanted to throw in a few cents to the conversation.
Problems with pure pam_lastlog.so

This seems to trigger is_phantom in last.c which causes "gone - no logout" due to /proc/pid/loginuid not containing the uid of the user but 4294967295 (-1)
Fix is to add session required pam_loginuid.so after session optional pam_lastlog.so silent
Whether these are optional or required, I'm not a pam master

pam_lastlog.so doesn't appear to update utmp, which is what's necessary to see the active logins via w.

The remote host is empty, even with pam_env.so user_readenv=1
My assumption is that xrdp isn't exporting an environment to pam that it needs, but I haven't traveled down the c so we'll have to wait for xrdp to implement wtmp more; or if it was then wait for pull from our distros

Here is my incredibly dirty workaround to the above for anyone who might want/need remote host to be populated and active logins shown via w.
First I cannot use pam_lastlogin.so in combination with my workaround, remark this entry in xrdp-sessman
I do require pam_loginuid.so, put this into the config
I'm using Perl system event correlator to read /var/log/xrdp-sessman.log
I have four events
xrdp login, xrdp start, xrdp stop and xrdp logout

xrdp login and logout grabs pid, display, client ip and username
xrdp start and stop grabs display and window manager pid
The reason for the start and stop filters is to find the windows manager pids which aren't in the session create or terminate lines from the login and logout lines that are logged. I use a temporary file to write missing data from the windows manager to be collected by the start stop scripts.

The scripts create the relevant utmp format and I'm using utmpdump -r to reverse the format and then write it to a file.

The result is that the remote host of the user will also show in wtmp, gone is replaced with relevant data.

If I knew more perl this could all be done in one script.

@matt335672
Copy link
Member

Thanks for the thoughts @dosmage

Have a look at #2745 which is pending. I'm waiting for other changes before I merge it. It includes the pam_loginuid.so library you mention and includes separate code to update utmp.

@freonheat
Copy link

I am almost ashamed to post this... but I ran across your thread....

We support hundreds of local linux thin clients through xdm/xdmcp on our main system (currently Alma 8) and just recently installed xrdp/xorgxrdp to start supporting remote users as well (with appropriate multifactor security and firewall precautions). We didn't run into the wtmp problem because we already customized things a different way for xdm, which is also working with xrdp.

Since all users use icewm, we put a sessreg commands in icewm's startup (to add a wtmp record) and shutdown (to close out the wtmp record). This did require something sneaky- we had to chown utmp /usr/bin/sessreg ; chmod g+s sessreg. This is because sessreg cannot be run as a normal user. Probably a security no-no, since any user can then add or delete records as they please. But, at the time, it looked like our only option. Anyway, it is a hack, but does the job. Note, I am not recommending anyone follow this course of action, but thought it would at least be amusing. :)

@matt335672
Copy link
Member

Thanks @freonheat - it's always good to hear from our enterprise users.

Hopefully we're getting close to our GFX release, so it shouldn't be too long before we can get #2745 in an official release for you.

@matt335672
Copy link
Member

#2745 is now merged into devel, so I'm closing this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants