Skip to content

New-PSSession from Windows to Linux fails due to ssh banner #15759

Closed

Description

@thukk

Prerequisites

Steps to reproduce

Set up Windows 10 and Linux host for SSH.
Create a New-PSSession from Windows to Linux using SSH transport.
$Session = New-PSSession -HostName $ComputerName -UserName $SSHUsername -SSHTransport

Prior to KB5003173 for 20H2, the error could be negated with error handling. After that patch, the error is terminating regardless of how it is handled.

Expected behavior

New session should be created.

Actual behavior

The SSH banner is evaluated to stderr and the connection fails.

Error details

> get-error

Exception             :
    Type        : System.Management.Automation.Remoting.PSRemotingTransportException
    ErrorCode   : 2100
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The background process reported an error with the following message: The SSH client session has
ended with error message: "SSH Banner Test".
            HResult : -2146233087
        CategoryInfo          : ResourceUnavailable: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException
    Message     : The background process reported an error with the following message: The SSH client session has
ended with error message: "SSH Banner Test".
    HResult     : -2146233087
TargetObject          : System.Management.Automation.RemoteRunspace
CategoryInfo          : OpenError: (System.Management.A…tion.RemoteRunspace:RemoteRunspace) [New-PSSession],
PSRemotingTransportException
FullyQualifiedErrorId : 2100,PSSessionOpenFailed
ErrorDetails          : [Linux_TestHost] The background process reported an error with the following message: The SSH
client session has ended with error message: "SSH Banner Test".
InvocationInfo        :
    MyCommand        : New-PSSession
    ScriptLineNumber : 755
    OffsetInLine     : 36
    HistoryId        : 3
    ScriptName       : C:\Users\username\Desktop\SSH_test.ps1
    Line             : $Session = New-PSSession -HostName $ComputerName -UserName $SSHUsername -SSHTransport
-ErrorAction Stop

    PositionMessage  : At C:\Users\username\Desktop\SSH_test.ps1
                       + …  $Session = New-PSSession -HostName $ComputerName -UserName $SSHUsern …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\username\Desktop\
    PSCommandPath    : C:\Users\username\Desktop\SSH_test.ps1
    InvocationName   : New-PSSession
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock><Process>, C:\Users\username\Desktop\SSH_test.ps1:
line 755
                        at <ScriptBlock>, <No file>: line 1

Environment data

> $psversiontable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Jul 12, 2021
  2. rkeithhill commented on Jul 12, 2021

    @rkeithhill
    Collaborator

    Can you try enabling the following experimental feature:

    Enable-ExperimentalFeature PSNotApplyErrorActionToStderr

    Try doing that on the Linux side first to see if that resolves it. If it doesn't, then try it on the client side.

  3. added
    WG-Remoting
    on Jul 12, 2021
  4. thukk commented on Jul 12, 2021

    @thukk
    Author

    no change. Ran it on the Linux host as well as the Windows client.

    both times, I closed and restarted pwsh before attempting to create a new session.

  5. thukk commented on Jul 21, 2021

    @thukk
    Author

    With -EA SilentlyContinue, I get "Error: Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again."

    With -EA Stop, I get the SSH banner message as an error.

    These errors come up when PS prompts for the SSH password - before I enter anything.

  6. iSazonov commented on Jul 22, 2021

    @iSazonov
    Collaborator

    I don't understand how it is related to KB5003173. Is it contain new Windows SSH?

    Update: yes, there is new Windows SSH.

  7. iSazonov commented on Jul 22, 2021

    @iSazonov
    Collaborator

    Is this the same as #5142?

  8. thukk commented on Jul 22, 2021

    @thukk
    Author

    Yes - same as #5142. The KB is relevant as before that KB, I could manage the error and get past it. After that KB was installed, I get a terminating error regardless of how I manage the error actions. There were some changes to the scripting engine that could have affected it.

    As stated in 5142, this is quite a big deal in trying to secure environments. SSH banners are a requirement is many areas and PS 7 not being to handle them is quite concerning.

  9. iSazonov commented on Jul 22, 2021

    @iSazonov
    Collaborator

    Paul Higinbotham (@PaulHigin) Do you prefer close this issue as duplicate and continue tracking in #5142?

  10. PaulHigin commented on Jul 27, 2021

    @PaulHigin
    Contributor

    Ilya (@iSazonov) Thanks, yes this looks like a duplicate.

  11. thukk commented on Jul 27, 2021

    @thukk
    Author

    Respectfully, 5142 has not gotten updated since January. This thread at least got a response to attempt an experimental feature...Is this an active bug/improvement being worked?

  12. PaulHigin commented on Jul 27, 2021

    @PaulHigin
    Contributor

    @PowerShell/wg-powershell-remoting

    We can bump up the priority on this (#5142), but SSH writes the banner in the error stream, it is difficult to distinguish it from a legit error. I think the solution will end up being fairly involved.

  13. added
    Issue-Bug
    and removed
    Needs-Triage
    on Jul 27, 2021
  14. 3 remaining items

  15. PaulHigin commented on Oct 6, 2021

    @PaulHigin
    Contributor

    thukk

    I looked at this today and the main problem (as I mentioned before) is that SSH error data is unreliable, as it streams banner text, warnings, non-terminating errors, and terminating errors. The SSH transport currently assumes any error should terminate the connection. The reason for this was to prevent a hanging connection attempt, a connection that cannot succeed but continues indefinitely. But this results in sessions being prematurely terminated due to warnings, or other non-terminating messages coming through stdError, even when we try to filter out known non-terminating error messages (warnings).

    However, it turns out that SSH will fail to connect and not emit any message whatsoever, under some conditions, so we still have the hanging problem even if we treat all error messages as terminating. To solve this problem I added a -ConnectingTimeout so that users can optionally end a connection attempt after a period time.

    I am now thinking that we can fix this problem (and other issues) by just removing the connection terminating on error message code. Any SSH error messages will be streamed to the terminal, but the connection attempt will never be aborted based on SSH error messages. So there will be only two (already existing) ways to stop a connection attempt:

    • Typing Crtl+C into interactive terminal
    • Using -ConnectingTimeout that will automatically terminate an unsuccessful connection attempt.

    This will be a breaking change, but I feel it is minor. But I'll mark this for committee review.

  16. added
    Review - Committee
    on Oct 6, 2021
  17. thukk commented on Oct 7, 2021

    @thukk
    Author

    Paul Higinbotham (@PaulHigin)

    That is very promising and excellent news. I am happy to run any testing you might need until the fix is put in. Maybe premature, but is there any sort of timeframe to implementing the changes or a target version?

  18. PaulHigin commented on Oct 7, 2021

    @PaulHigin
    Contributor

    Since this is technically a breaking change, it should begin as an experimental feature. So I'll try to get it in for the next preview release (which I believe is later this month).

  19. JacobStruiksma commented on Oct 14, 2021

    @JacobStruiksma

    Does issue #16027 also has impact on this issue?

  20. thukk commented on Oct 26, 2021

    @thukk
    Author

    Were you able to get the change into 7.2.0-rc.1? I am happy to test it and report my findings.

  21. PaulHigin commented on Oct 26, 2021

    @PaulHigin
    Contributor

    thukk
    No, it was rejected for the 7.2 release because it is technically a breaking change and too close to GA release. I also had to make it an experimental feature, PSRemotingSSHTransportErrorHandling, because of the breaking change in behavior. So it should be in the first 7.3-preview release, in November.

  22. added
    Committee-Reviewed
    and removed
    Review - Committee
    on Nov 10, 2021
  23. SteveL-MSFT commented on Nov 10, 2021

    @SteveL-MSFT
    Member

    This was already reviewed by @PowerShell/powershell-committee to have as experimental feature in 7.3

  24. daxian-dbw commented on Nov 12, 2021

    @daxian-dbw
    Member

    Close via #16205

  25. thukk commented on Dec 22, 2021

    @thukk
    Author

    I just pulled down 7.3 Preview 1, ran Enable-ExperimentalFeature PSRemotingSSHTransportErrorHandling and viola! with -EA Continue, I was able to see the banner and still enter my SSH password to create a valid session. SilentlyContinue hides the basement completely, which is also nice.

    If I had one complaint, the SSH banner shows at the password prompt, so the cursor is awaiting input on an empty line - but that is a somewhat minor inconvenience.

    Thank you for getting this working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedIssue-BugWG-Remoting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions