Skip to content

don't override User in ssh_config #11344

Closed

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_hosts file containing, for each instance, the instance's public key; and
  • an ssh_config file containing, for each instance, a UserKnownHostsFile directive pointing to the known_hosts file, a User directive 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 a ProxyJump directive 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

  1. added
    Issue-Enhancement
    on Dec 15, 2019
  2. LucaFilipozzi commented on Dec 15, 2019

    @LucaFilipozzi
    ContributorAuthor

    if (!string.IsNullOrEmpty(this.KeyFilePath))
    {
    if (!System.IO.File.Exists(this.KeyFilePath))
    {
    throw new FileNotFoundException(
    StringUtil.Format(RemotingErrorIdStrings.KeyFileNotFound, this.KeyFilePath));
    }
    arguments = (string.IsNullOrEmpty(domainName)) ?
    string.Format(CultureInfo.InvariantCulture, @"-i ""{0}"" {1}@{2} -p {3} -s {4}", this.KeyFilePath, userName, hostname, this.Port, this.Subsystem) :
    string.Format(CultureInfo.InvariantCulture, @"-i ""{0}"" -l {1}@{2} {3} -p {4} -s {5}", this.KeyFilePath, userName, domainName, hostname, this.Port, this.Subsystem);
    }
    else
    {
    arguments = (string.IsNullOrEmpty(domainName)) ?
    string.Format(CultureInfo.InvariantCulture, @"{0}@{1} -p {2} -s {3}", userName, hostname, this.Port, this.Subsystem) :
    string.Format(CultureInfo.InvariantCulture, @"-l {0}@{1} {2} -p {3} -s {4}", userName, domainName, hostname, this.Port, this.Subsystem);
    }

  3. added
    WG-Remoting
    on Dec 15, 2019
  4. LucaFilipozzi commented on Dec 15, 2019

    @LucaFilipozzi
    ContributorAuthor

    Let me know if a pull request is something that you'd like me to prepare.

  5. iSazonov commented on Dec 16, 2019

    @iSazonov
    Collaborator
  6. PaulHigin commented on Dec 16, 2019

    @PaulHigin
    Contributor

    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.

  7. added
    Review - Committee
    on Dec 16, 2019
  8. SteveL-MSFT commented on Dec 18, 2019

    @SteveL-MSFT
    Member

    It seems that ssh already 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.

  9. LucaFilipozzi commented on Dec 22, 2019

    @LucaFilipozzi
    ContributorAuthor

    Let me know if I can help in any way to progress this enhancement request. Thank you for reviewing it so expeditiously.

  10. SteveL-MSFT commented on Dec 23, 2019

    @SteveL-MSFT
    Member

    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)

  11. removed
    Review - Committee
    on Jan 8, 2020
  12. SteveL-MSFT commented on Jan 8, 2020

    @SteveL-MSFT
    Member

    Removing need to review by @PowerShell/powershell-committee as the functional behavior hasn't changed for the user

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

    Issue-EnhancementResolution-FixedWG-Remoting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions