Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Win32-OpenSSH #1744

Merged
merged 3 commits into from
Jun 27, 2022
Merged

Conversation

joshcooper
Copy link
Contributor

Newer versions of Windows ship with Win32-OpenSSH (see https://github.com/PowerShell/openssh-portable) This PR makes it possible to detect when that implementation is used (based on the binary path of the sshd service) and it converts backslashes to forward slashes, such as when calling scp_to. This is similar to the work that was done to support BitVise and powershell (PSWindows)

Updates the `Beaker::Host::Windows#determine_ssh_server` method to detect when
running the Win32-OpenSSH sshd based on the service's binPath. This is needed
because that implementation handles backslashes differently than cygwin's sshd.
If `determine_ssh_server` returned an unknown type, then beaker failed to raise
an ArgumentError. When using `raise` you can pass two arguments, the class to
raise and the message, or pass an instance of an exception, e.g.
ArgumentError.new("message").

This also adds tests for the other cases.
When using cygwin bash.exe, backslashes are handled differently depending on
whether we're using cygwin or Windows-OpenSSH's sshd.

    $ ssh Administrator@win32-openssh 'cmd /c echo c:\\Windows'
    c:Windows

    $ ssh Administrator@cygwin 'cmd /c echo c:\\Windows'
    c:\Windows

Note that Win32-OpenSSH lost the backslashes. This issue prevents beaker from
installing puppet-agent on Windows 11 using Win32-OpenSSH, as it scp's a bat
file to the Windows host:

    $ scp /tmp/install-puppet-msi-2022-06-22_18.18.04.bat20220622-2096997-1w3xtbd host.example.com:C:\Windows\TEMP\install-puppet-msi-2022-06-22_18.18.04.bat

But the resulting path doesn't exist:

    $ cmd.exe /c "C:\Windows\TEMP\install-puppet-msi-2022-06-22_18.18.04.bat"
    'C:\Windows\TEMP\install-puppet-msi-2022-06-22_18.18.04.bat' is not recognized as an internal or external command, operable program or batch file.

To avoid these problems, convert backslashes to forward slashes when using
Windows-OpenSSH. This way the scp and execute steps refer to the same file. This
is the same solution used when using bitvise and `Beaker::Host:PSWindows` since
it's `scp_separator` is '/'[1]

[1] https://github.com/voxpupuli/beaker/blob/76a974f448bc49cdab69792d95ae606d2d868f50/lib/beaker/host/pswindows.rb#L28
@codecov
Copy link

codecov bot commented Jun 23, 2022

Codecov Report

Merging #1744 (f296c89) into master (76a974f) will increase coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1744      +/-   ##
==========================================
+ Coverage   74.77%   74.88%   +0.10%     
==========================================
  Files          82       82              
  Lines        4861     4865       +4     
==========================================
+ Hits         3635     3643       +8     
+ Misses       1226     1222       -4     
Impacted Files Coverage Δ
lib/beaker/host/windows.rb 94.11% <100.00%> (+0.56%) ⬆️
lib/beaker/host/windows/file.rb 76.66% <100.00%> (+14.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76a974f...f296c89. Read the comment docs.

Copy link
Member

@smortex smortex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, windows is weird 🤪

@joshcooper
Copy link
Contributor Author

joshcooper commented Jun 23, 2022

Still a problem trying to scp to a file containing spaces

    localhost $ scp /tmp/beaker20220622-2142744-1x2p96 jumpy-firepower.xxx:C:/Program Files/Puppet Labs/Puppet/puppet/lib/ruby/site_ruby/2.7.0/facter/custom_fact.rb {:ignore => }
    Warning: Net::SCP::Error error in scp'ing. Forcing the connection to close, which should raise an erro

Nevermind, the error was actually before that as the destination directory wasn't created correctly.

@joshcooper
Copy link
Contributor Author

This is working in puppet, facter & puppet-agent PRs, so going to merge

@joshcooper joshcooper merged commit 6c0b15b into voxpupuli:master Jun 27, 2022
@joshcooper joshcooper deleted the win11_sshd branch June 27, 2022 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants