Repository navigation
Description
request: don't override User directive in ssh_config
I pre-generate ssh host keys which I deploy to cloud instances using cloud-init for use by their ssh daemons. This allows me to generate local ssh client configuration files:
- a
known_hostsfile containing, for each instance, the instance's public key; and - an
ssh_configfile containing, for each instance, aUserKnownHostsFiledirective pointing to theknown_hostsfile, aUserdirective providing the instance's system administrator username (e.g.: "ec2-user" for AWS RedHat instances, "sysadmin" for AWS Debian instances, "Administrator" for Windows Server instances, etc.), and aProxyJumpdirective so that connections to the instances are routed through a bastion host.
This allows me to avoid security warnings regarding unknown host keys, etc. and to use ansible without compromising the ssh security model.
PowerShell Core Remoting over SSH uses the underlying operating system's ssh client. In the case of OpenSSH on Linux or macOS, this means that the ssh_config and known_hosts files that I generated provide the directives necessary for a secure connection as described above.
This works perfectly except that StartSSHProcess always passes a User command line parameter to the ssh client, overriding the User directive in ssh_config.
As a system administrator, I want to generate ssh configuration files containing directives that aren't overriden by PowerShell's invocation of ssh.
proposal: do not pass -l <username> to ssh client unless -UserName <username> is passed to cmdlets
When invoking *PSSession cmdlets, if -UserName <username> isn't used , then don't pass -l <username> as a command line argument to the ssh client.
Activity
LucaFilipozzi commentedon Dec 15, 2019
PowerShell/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
Lines 2088 to 2105 in f1b96eb
LucaFilipozzi commentedon Dec 15, 2019
Let me know if a pull request is something that you'd like me to prepare.
iSazonov commentedon Dec 16, 2019
Paul Higinbotham (@PaulHigin) What do you think?
PaulHigin commentedon Dec 16, 2019
I feel we should take this change. Default UserName was only added so as to be similar to Windows connections using WinRM. But since this breaks useful SSH scenarios, I feel we should change the behavior.
This would technically be a breaking change so I am adding the committee to review it.
SteveL-MSFT commentedon Dec 18, 2019
It seems that
sshalready users the current username if it's not provided. So if we omit the userName if it's not explicitly supplied, it seems that functionally it's not a breaking change.LucaFilipozzi commentedon Dec 22, 2019
Let me know if I can help in any way to progress this enhancement request. Thank you for reviewing it so expeditiously.
SteveL-MSFT commentedon Dec 23, 2019
Luca Filipozzi (@LucaFilipozzi) Go ahead an prep a PR. Folks are out on holiday currently, but we can review in the new year and there's still a chance we can take it for GA (seems low risk to me)
SteveL-MSFT commentedon Jan 8, 2020
Removing need to review by @PowerShell/powershell-committee as the functional behavior hasn't changed for the user