Bug 1065 - password expiration and SSH keys don't go well together
Summary: password expiration and SSH keys don't go well together
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp-server (show other bugs)
Version: 4.1p1
Hardware: All Linux
: P2 normal
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-04 00:40 AEST by Josselin Mouette
Modified: 2021-03-04 09:54 AEDT (History)
3 users (show)

See Also:


Attachments
Debugging output of the issue (36.01 KB, text/plain)
2005-12-06 22:31 AEDT, Josselin Mouette
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Josselin Mouette 2005-08-04 00:40:11 AEST
We are running a setup using pam_ldap, and password expiration. When a password
is expired, PAM forces the user to change it. However, here is what happens when
using a SSH key to log in without a password:

16:33 jmouette@silicium ~ > ssh tantale
You are required to change your LDAP password immediately.
Last login: Wed Aug  3 15:49:24 2005 from silicium.ccc.cea.fr
Connection to tantale closed.

When disabling the key, things work as expected:
16:38 jmouette@silicium ~ > ssh -o PubkeyAuthentication=no tantale
Password:
You are required to change your LDAP password immediately.
Enter login(LDAP) password:
New password:
Retype new password:
LDAP password information changed for jmouette
Last login: Wed Aug  3 16:33:27 2005 from silicium.ccc.cea.fr
[ successful login ]
Comment 1 Darren Tucker 2005-08-04 11:52:13 AEST
pam_unix doesn't do that on my (FC3) system, it throws the user into a password
change dialogue even with pubkey auth.

Could you please attach the relevant PAM conf file to this bug?

I would guess that pam_ldap is configured as a session module and that's causing
the login to be dropped before the password can be changed.
Comment 2 Darren Tucker 2005-08-04 11:57:39 AEST
Also: please try commenting out pam_ldap as a session module and see if the
behaviour changes.
Comment 3 Josselin Mouette 2005-08-04 17:09:48 AEST
Here is the PAM configuration (using RHEL 3.0, except for the pam_ldap module,
version 178, and the sshd daemon, version 4.1p1).

auth        required      /lib/security/$ISA/pam_env.so
auth [success=1 default=ignore] /lib/security/$ISA/pam_unix.so nullok_secure
auth        required      /usr/local/lib64/ldap/pam_ldap.so use_first_pass
auth        required      /lib/security/$ISA/pam_permit.so

account     sufficient    /usr/local/lib64/ldap/pam_ldap.so
account     required      /lib/security/$ISA/pam_unix.so

password    required      /lib/security/$ISA/pam_cracklib.so retry=3 type=
password    sufficient    /usr/local/lib64/ldap/pam_ldap.so use_authtok
password    required      /lib/security/$ISA/pam_unix.so nullok use_authtok md5
shadow

session     required      /lib/security/$ISA/pam_limits.so
#session     sufficient    /usr/local/lib64/ldap/pam_ldap.so use_authtok
session     required      /lib/security/$ISA/pam_unix.so

Commenting out the session pam_ldap stanza or uncommenting it doesn't change the
behavior.
Comment 4 Darren Tucker 2005-08-04 19:19:04 AEST
(In reply to comment #3)
> Commenting out the session pam_ldap stanza or uncommenting it doesn't change the
> behavior.

In that case my guess as to what's happening was wrong.  Could you please attach
(ie use "create new attachment" rather than pasting into the comment field) the
server side debugging from "/path/to/sshd -ddd" for both pubkey and non-pubkey
logins?
Comment 5 Darren Tucker 2005-08-04 19:22:26 AEST
Also: is this built from vanilla source or a vendor-supplied binary?  If the
latter, can you reproduce the behaviour with vanilla openssh-4.1p1?
Comment 6 senthilkumar 2005-08-10 16:55:30 AEST
I think this problem have some resemblance with the discussion at http://marc.
theaimsgroup.com/?l=openssh-unix-dev&m=110844606628771&w=2. I feel the change in 
behaviour occurs if you comment pam_ldap from Account management section. I 
think the call pam_acct_mgmt() is returning PAM_NEW_AUTHTOK_REQD. 
Comment 7 Josselin Mouette 2005-08-10 18:36:22 AEST
* This is a local build of vanilla OpenSSH 4.1p1 sources.
* The machine is in production now, so I can't obtain the debugging output. I
will try to obtain in during the next maintenance.
* Commenting out the account stanza leads to a different message ("You are
required to change your password immediately (password aged)" instead of "You
are required to change your LDAP password immediately.") but the behavior still
occurs.
Comment 8 senthilkumar 2005-08-10 19:20:34 AEST
That message happens because of pam_unix(local password aging). I suspect the 
problem as below, the pam_authenticate() is skipped in sshd for key based 
authentications. So when pam_acct_mgmt() is called at this case, I guess  
pam_ldap checks whether previous call for pam_authenticate() is successful or 
not (which is skipped). This may results in this kind of behaviour.
Comment 9 Darren Tucker 2005-08-10 20:03:36 AEST
(In reply to comment #7)
> * The machine is in production now, so I can't obtain the debugging output. I
> will try to obtain in during the next maintenance.

If it's permitted by your policy, you can run sshd on a non-standard port on the
loopback and get the debug trace that way ("/path/to/sshd -ddd -o
listenaddress=127.0.0.1:222")

Alternatively, if it would permit running some code as root that's not a network
service then you could use my PAM test tool:
http://www.zip.com.au/~dtucker/patches/#pamtest

The "-a" option approximates what sshd does for public-key authentications, and
the "-s" option lets you test alternate PAM service names without affecting the
production ones.  It may give enough information to figure out what's going on.
 Something like this ought to do it:
# ./pam-test-harness -s sshd -a -u youruser

Caveat: it does not implement an "echo off" so it will echo any passwords to the
tty.  Remove anything sensitive before sending (and beware of shoulder-surfers :-)

If neither of the above is the case then I'm out of options and we'll wait for
the debug output.
Comment 10 Ulrich Windl 2005-08-18 18:41:20 AEST
Please also see bug #511.
Comment 11 Josselin Mouette 2005-12-06 22:31:30 AEDT
Created attachment 1036 [details]
Debugging output of the issue

Finally, here is the output of sshd -ddd. First, in normal operation. Second, when the problem occurs. Third, with an expired password, and disabling public key authentication.
Comment 12 Darren Tucker 2005-12-07 09:53:00 AEDT
Comment on attachment 1036 [details]
Debugging output of the issue

This looks like the reason:
>PAM: pam_chauthtok(): User not known to the underlying authentication module

I suspect that the chauthtok() in the pam_ldap module relies on something set earlier during the authenticate(), and is bailing when it's not present due to the authentication being done via public-key and not PAM.  If that's the case, I can't see anything sshd can do to make pam_chauthtok() work under those conditions, it would require (probably minor) surgery on pam_ldap.

As a workaround you can try enabling UsePrivilegeSeparation: this will cause sshd to exec /usr/bin/password to change the password, rather than using pam_chauthtok() directly.
Comment 13 senthilkumar 2005-12-07 16:56:33 AEDT
There exists a description + workaround for the problem in HP-UX at http://docs.hp.com/en/6965/pam_authz_for_policy_wp_2_3.pdf .
Comment 14 Josselin Mouette 2005-12-07 19:17:25 AEDT
Thanks a lot, things indeed work with privilege separation enabled.
(Privilege separation didn't work with LDAP in OpenSSH 3.6, that's why we had disabled it.)
Comment 15 Darren Tucker 2005-12-07 20:33:31 AEDT
Cool.  Like I said, I don't think there's anything that sshd can do in the pam_chauthtok() case and you'd need to modify pam_ldap to make it work.

Closing bug.
Comment 16 Darren Tucker 2006-10-07 11:41:23 AEST
Change all RESOLVED bug to CLOSED with the exception of the ones fixed post-4.4.
Comment 17 Damien Miller 2020-01-26 00:16:24 AEDT
looks like this bug should have been closed 14 years ago :)
Comment 18 Damien Miller 2021-03-04 09:54:21 AEDT
close bugs that were resolved in OpenSSH 8.5 release cycle