Add PAM parameter to avoid implicit try_first_pass
behavior
#65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change introduces a new PAM parameter, clear_first_pass, which prevents the module from using the previously received authentication token from the pam_get_authtok() call during the authentication phase. Currently, the password is stored in context when a password change is required (link).
The purpose of this parameter is to ensure the user re-enters their old password when the LDAP password policy enforces a mandatory password change.
Currently, step (3) cannot be executed because the old password from step (1) is reused.
This issue can be reproduced with SSHD using
KbdInteractiveAuthentication yes
.After applying this PR, you can configure authentication to discard the old password, ensuring it is not available during the password change phase:
Although it may seem unusual to prompt the user to enter their password twice in a row, there are valid reasons for this:
Background
One might wonder why not use the existing try_first_pass parameter to control whether the old password is used. The behavior described by pam_get_authtok() in the Linux PAM implementation does not align with the documentation (quote from man page)
When
PAM_OLDAUTHTOK
is in the stackpam_get_authtok()
should reuse it only iftry_first_pass
is specified, which should result in a second password prompt by not settingtry_first_pass
. However, this is not the case astry_first_pass
has no effect linux-pam/linux-pam#357 (comment).The function
pam_get_authtok()
seems to have originated from OpenPAM where it adhered totry_first_pass
(link). Since its implementation in Linux PAM since 2009,try_first_pass
has not been part of the Linux PAM functionality.Actually, both
PAM_AUTHTOK
andPAM_OLDAUTHTOK
are cleared between PAM function calls for security reasons. This can be seen in the_pam_sanitize()
function, which is called when entering and exitingpam_authenticate()
andpam_chauthtok()
. This likely explains why the password is stored in an internal variable instead of relying onPAM_OLDAUTHTOK
to keep it in memory between function calls. This PR could be considered as hardening option to avoid keeping the password in memory in any situation.