Repository navigation
Closed
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-BugIssue has been identified as a bug in the productWG-RemotingPSRP issues with any transport layer
Milestone
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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 1Environment 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.0Visuals
No response
Metadata
Metadata
Assignees
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-BugIssue has been identified as a bug in the productWG-RemotingPSRP issues with any transport layer
Activity
rkeithhill commentedon Jul 12, 2021
Can you try enabling the following experimental feature:
Enable-ExperimentalFeature PSNotApplyErrorActionToStderrTry doing that on the Linux side first to see if that resolves it. If it doesn't, then try it on the client side.
thukk commentedon Jul 12, 2021
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.
thukk commentedon Jul 21, 2021
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.
iSazonov commentedon Jul 22, 2021
I don't understand how it is related to KB5003173. Is it contain new Windows SSH?
Update: yes, there is new Windows SSH.
iSazonov commentedon Jul 22, 2021
Is this the same as #5142?
thukk commentedon Jul 22, 2021
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.
iSazonov commentedon Jul 22, 2021
Paul Higinbotham (@PaulHigin) Do you prefer close this issue as duplicate and continue tracking in #5142?
PaulHigin commentedon Jul 27, 2021
Ilya (@iSazonov) Thanks, yes this looks like a duplicate.
thukk commentedon Jul 27, 2021
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?
PaulHigin commentedon Jul 27, 2021
@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.
3 remaining items
PaulHigin commentedon Oct 6, 2021
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
-ConnectingTimeoutso 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:
Crtl+Cinto interactive terminal-ConnectingTimeoutthat 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.
thukk commentedon Oct 7, 2021
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?
PaulHigin commentedon Oct 7, 2021
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).
JacobStruiksma commentedon Oct 14, 2021
Does issue #16027 also has impact on this issue?
thukk commentedon Oct 26, 2021
Were you able to get the change into 7.2.0-rc.1? I am happy to test it and report my findings.
PaulHigin commentedon Oct 26, 2021
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.SteveL-MSFT commentedon Nov 10, 2021
This was already reviewed by @PowerShell/powershell-committee to have as experimental feature in 7.3
daxian-dbw commentedon Nov 12, 2021
Close via #16205
thukk commentedon Dec 22, 2021
I just pulled down 7.3 Preview 1, ran
Enable-ExperimentalFeature PSRemotingSSHTransportErrorHandlingand viola! with-EA Continue, I was able to see the banner and still enter my SSH password to create a valid session.SilentlyContinuehides 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.