Skip to content

fix(ssh): log in when a second factor is only offered after the password - #358

Merged
FloSch62 merged 3 commits into
mainfrom
fix/multi-step-auth-order
Nov 11, 2026
Merged

FloSch62 merged 3 commits into
mainfrom
fix/multi-step-auth-order

Conversation

@FloSch62

Copy link
Copy Markdown
Owner

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 failed right after the password. OpenSSH logs in to the same host:

Authentications that can continue: gssapi-with-mic,password
Authenticated using "password" with partial success.
Authentications that can continue: gssapi-with-mic,keyboard-interactive

Testing that flow end to end turned up two more problems on the same path.

Cause and fix

1. Auth order. AuthLadder walked 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 resize therefore 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

  • Unit tests:
    • a server that takes the password and then offers a passcode logs in, and reports password, keyboard-interactive in the session summary
    • the saved password is reused on the second login and only the passcode is prompted
    • a resize during a password or host-key prompt neither answers nor cancels it, and the shell opens at the last reported size
    • prompt text is split into the text above the field and the field label
  • OpenSSH in a container with AuthenticationMethods password,keyboard-interactive and a PAM module that asks a Duo-style menu after the password. The stock ssh client shows the same trace against it as in the issue.
    • before: fails after the password with authentication to 127.0.0.1:2357 failed
    • after: trust the host key, enter the password, read the menu, answer 1, shell opens, driven through the web UI
  • Not tested against a real Duo deployment.
  • Typecheck, lint and the full unit suite pass.

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.
@FloSch62
FloSch62 merged commit f61fa17 into main Nov 11, 2026
5 checks passed
@FloSch62
FloSch62 deleted the fix/multi-step-auth-order branch November 11, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSH connection failed on systems requiring manual two-factor authentication

1 participant