Repository navigation
fix(ssh): log in when a second factor is only offered after the password - #358
Merged
Merged
Conversation
The auth ladder walked its methods once, in a fixed order, and spent every method the server was not offering at that moment. A host that takes the password first and only then advertises keyboard-interactive (a common Duo setup) had its keyboard-interactive attempts used up before the password was sent, so the login ended in "authentication failed" right after the password. Each reply from the server now picks the first untried attempt it currently accepts, as OpenSSH does when the advertised list changes. Retry limits for passwords and keyboard-interactive are unchanged. Fixes #357
Any control frame that arrived while a password or host-key prompt was waiting was taken as its answer, so a resize cancelled the login or denied the host key. Only the opening request and the prompt answers settle a waiter now. A resize received before the session is attached is kept and applied once the shell opens, so it starts at the window's current size.
Duo sends its menu of options and the question as one keyboard-interactive prompt. The dialog used the whole prompt as a one-line field label, which cut the menu off. The last line now labels the field and the lines before it are shown above it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #357
Problem
A host that asks for the password first and only then offers a keyboard-interactive second factor (a common Duo setup) could not be reached with the built-in SSH client. The tab ended with
authentication to <host>:22 failedright after the password. OpenSSH logs in to the same host:Testing that flow end to end turned up two more problems on the same path.
Cause and fix
1. Auth order.
AuthLadderwalked its methods once, in a fixed order (agent, keys, keyboard-interactive, password), and spent every method the server was not offering at that moment. Keyboard-interactive was used up before the password was sent, so nothing was left when the server asked for it. The same applied to password → publickey and keyboard-interactive → publickey.Each reply from the server now picks the first untried attempt it currently accepts, as OpenSSH does when the advertised list changes. The preference order and the retry limits for passwords and keyboard-interactive are unchanged. A password accepted with partial success is still remembered in the vault and reused, so on later logins only the passcode is asked.
2. A resize could cancel a prompt. On the terminal socket, any control frame that arrived while a password or host-key prompt was waiting was taken as its answer. A
resizetherefore ended the login with "authentication cancelled" or "Host denied". Only the opening request and the prompt answers settle a waiter now. A resize received before the session is attached is kept and applied when the shell opens, so the shell starts at the window's current size.3. The Duo menu was cut off. Duo sends its menu of options and the question as one prompt. The dialog used the whole prompt as a one-line field label, so the options were truncated. The last line now labels the field and the lines before it are shown above it.
Testing
password,keyboard-interactivein the session summaryAuthenticationMethods password,keyboard-interactiveand a PAM module that asks a Duo-style menu after the password. The stocksshclient shows the same trace against it as in the issue.authentication to 127.0.0.1:2357 failed1, shell opens, driven through the web UI