Skip to content

Commit e86a5a1

Browse files
authored
Add Windows support (#170)
* Add support for sshd_config * Add windows specific unit tests * Update kitchen and ci config for Windows * template properties filtered out for Windows * template properties filtered out for Windows for all * Configure sshd path * Fix sshd Windows path * Remove iptables for Windows & fix integration tests * Run Windows VM on macOS
1 parent 0494f97 commit e86a5a1

File tree

14 files changed

+318
-24
lines changed

14 files changed

+318
-24
lines changed

.github/workflows/ci.yml

+52
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,58 @@ jobs:
6464
suite: ${{ matrix.suite }}
6565
os: ${{ matrix.os }}
6666

67+
integration-windows:
68+
needs: lint-unit
69+
runs-on: windows-latest
70+
timeout-minutes: 20
71+
strategy:
72+
matrix:
73+
os:
74+
- "windows-latest"
75+
suite:
76+
- "windows-default"
77+
fail-fast: false
78+
79+
steps:
80+
- name: Check out code
81+
uses: actions/checkout@v3
82+
- name: Install Chef
83+
uses: actionshub/[email protected]
84+
- name: Download Openssh Installer
85+
uses: suisei-cn/[email protected]
86+
with:
87+
url: https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.2.2.0p1-Beta/OpenSSH-Win64-v9.2.2.0.msi
88+
target: installer/
89+
- name: Install Openssh
90+
run: |
91+
echo %cd%
92+
dir installer
93+
$file = "installer\\OpenSSH-Win64-v9.2.2.0.msi"
94+
$log = "installer\\install.log"
95+
$procMain = Start-Process "msiexec" "/i `"$file`" /qn /l*! `"$log`"" -NoNewWindow -PassThru
96+
$procLog = Start-Process "powershell" "Get-Content -Path `"$log`" -Wait" -NoNewWindow -PassThru
97+
$procMain.WaitForExit()
98+
$procLog.Kill()
99+
100+
- name: Kitchen Converge
101+
uses: actionshub/[email protected]
102+
env:
103+
CHEF_LICENSE: accept-no-persist
104+
KITCHEN_LOCAL_YAML: kitchen.exec.yml
105+
with:
106+
suite: ${{ matrix.suite }}
107+
os: ${{ matrix.os }}
108+
action: converge
109+
- name: Kitchen Verify
110+
uses: actionshub/[email protected]
111+
env:
112+
CHEF_LICENSE: accept-no-persist
113+
KITCHEN_LOCAL_YAML: kitchen.exec.yml
114+
with:
115+
suite: ${{ matrix.suite }}
116+
os: ${{ matrix.os }}
117+
action: verify
118+
67119
# unable to get SSH service to start
68120
# integration-macos:
69121
# needs: [mdl, yamllint, delivery]

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This file is used to list changes made in each version of the openssh cookbook.
44

55
## Unreleased
66

7+
- Add Windows Support
8+
79
## 2.10.18 - *2023-07-10*
810

911
## 2.10.17 - *2023-05-16*

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of
2323
- Suse Enterprise Linux
2424
- openSUSE / openSUSE leap
2525
- AIX 7.1
26+
- Windows
2627

2728
### Chef
2829

attributes/default.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
%w(openssh-clients openssh-server)
2727
when 'arch', 'suse', 'gentoo'
2828
%w(openssh)
29-
when 'freebsd', 'smartos', 'mac_os_x', 'aix'
29+
when 'freebsd', 'smartos', 'mac_os_x', 'aix', 'windows'
3030
%w()
3131
else
3232
%w(openssh-client openssh-server)
@@ -140,8 +140,16 @@
140140
# default['openssh']['server']['chroot_directory'] = 'none'
141141
# default['openssh']['server']['banner'] = 'none'
142142
# default['openssh']['server']['subsystem'] = 'sftp /usr/libexec/sftp-server'
143-
default['openssh']['server']['trusted_user_c_a_keys'] = '/etc/ssh/ca_keys'
144-
default['openssh']['server']['revoked_keys'] = '/etc/ssh/revoked_keys'
143+
default['openssh']['server']['trusted_user_c_a_keys'] = if platform_family?('windows')
144+
join_path(base_ssh_config_dir, 'ca_userkeys.pub')
145+
else
146+
'/etc/ssh/ca_keys'
147+
end
148+
default['openssh']['server']['revoked_keys'] = if platform_family?('windows')
149+
join_path(base_ssh_config_dir, 'revoked_keys')
150+
else
151+
'/etc/ssh/revoked_keys'
152+
end
145153
default['openssh']['server']['subsystem'] = 'sftp /usr/libexec/openssh/sftp-server' if platform_family?('rhel', 'amazon', 'fedora')
146154
default['openssh']['server']['subsystem'] = 'sftp /usr/lib/openssh/sftp-server' if platform_family?('debian')
147155
default['openssh']['server']['subsystem'] = 'sftp /usr/lib/ssh/sftp-server' if platform_family?('suse')

kitchen.exec.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
---
2-
driver: { name: exec }
3-
transport: { name: exec }
2+
driver:
3+
name: exec
4+
5+
transport:
6+
name: exec
7+
8+
provisioner:
9+
name: chef_zero
10+
deprecations_as_errors: true
411

512
platforms:
6-
- name: macos-latest
713
- name: windows-latest
14+
- name: macos-latest

kitchen.yml

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
---
12
driver:
23
name: vagrant
34

45
provisioner:
5-
name: chef_infra
6-
enforce_idempotency: true
7-
multiple_converge: 2
6+
name: chef_zero
7+
product_name: chef
88
deprecations_as_errors: true
99
chef_license: accept-no-persist
1010

@@ -26,10 +26,20 @@ platforms:
2626
driver_config:
2727
box: tas50/macos_10.15
2828
provider: vmware_desktop
29+
- name: windows-2016
30+
driver_config:
31+
box: tas50/windows_2016
32+
- name: windows-2019
33+
driver_config:
34+
box: tas50/windows_2019
2935

3036
suites:
3137
- name: default
3238
run_list: openssh::default
39+
excludes:
40+
- windows-2016
41+
- windows-2019
42+
- windows-latest
3343
- name: iptables
3444
run_list:
3545
- openssh::default
@@ -41,3 +51,12 @@ suites:
4151
- macosx-10.15
4252
- opensuse-leap-15
4353
- rockylinux-8
54+
- windows-2016
55+
- windows-2019
56+
- windows-latest
57+
- name: windows-default
58+
run_list: openssh::default
59+
includes:
60+
- windows-2016
61+
- windows-2019
62+
- windows-latest

libraries/helpers.rb

+16-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,29 @@ def sshd_host_keys_missing?
4444
end
4545

4646
def openssh_service_name
47-
if platform_family?('rhel', 'fedora', 'suse', 'freebsd', 'gentoo', 'arch', 'mac_os_x', 'amazon', 'aix')
47+
if platform_family?('rhel', 'fedora', 'suse', 'freebsd', 'gentoo', 'arch', 'mac_os_x', 'amazon', 'aix', 'windows')
4848
'sshd'
4949
else
5050
'ssh'
5151
end
5252
end
5353

54+
def base_ssh_config_dir
55+
platform_family?('windows') ? 'C:\\ProgramData\\ssh' : '/etc/ssh'
56+
end
57+
58+
def base_ssh_bin_dir
59+
platform_family?('windows') ? 'C:\\Program Files\\OpenSSH' : '/usr/sbin/'
60+
end
61+
62+
def join_path(*path)
63+
Chef::Util::PathHelper.cleanpath(::File.join(path))
64+
end
65+
5466
def supported_ssh_host_keys
55-
keys = ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_ecdsa_key']
56-
keys << '/etc/ssh/ssh_host_dsa_key' if platform_family?('smartos, suse')
57-
keys << '/etc/ssh/ssh_host_ed25519_key' if rhel_7_plus? || platform?('amazon', 'fedora') || platform_family?('debian') || opensuse_15_plus?
67+
keys = [join_path(base_ssh_config_dir, 'ssh_host_rsa_key'), join_path(base_ssh_config_dir, 'ssh_host_ecdsa_key')]
68+
keys << join_path(base_ssh_config_dir, 'ssh_host_dsa_key') if platform_family?('smartos', 'suse', 'windows')
69+
keys << join_path(base_ssh_config_dir, 'ssh_host_ed25519_key') if rhel_7_plus? || platform?('amazon', 'fedora') || platform_family?('debian', 'windows') || opensuse_15_plus?
5870
keys
5971
end
6072

metadata.rb

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
supports 'smartos'
2222
supports 'suse'
2323
supports 'ubuntu'
24+
supports 'windows'
2425
supports 'zlinux'
2526

2627
depends 'iptables', '>= 7.0'

mlc_config.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ignorePatterns": [
3+
{
4+
"pattern": "^https://tickets.chef.io/browse/COOK"
5+
},
6+
{
7+
"pattern": "^https://opencollective.com/sous-chefs/contributors.svg"
8+
}
9+
]
10+
}

recipes/default.rb

+17-11
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def listen_addr_for(interface, type)
2424

2525
package node['openssh']['package_name'] unless node['openssh']['package_name'].empty?
2626

27-
template '/etc/ssh/ssh_config' do
27+
template join_path(base_ssh_config_dir, 'ssh_config') do
2828
source 'ssh_config.erb'
29-
mode '0644'
30-
owner 'root'
29+
mode '0644' unless platform_family?('windows')
30+
owner 'root' unless platform_family?('windows')
3131
group node['root_group']
3232
end
3333

@@ -44,16 +44,16 @@ def listen_addr_for(interface, type)
4444
template 'sshd_ca_keys_file' do
4545
source 'ca_keys.erb'
4646
path node['openssh']['server']['trusted_user_c_a_keys']
47-
mode node['openssh']['config_mode']
48-
owner 'root'
47+
mode node['openssh']['config_mode'] unless platform_family?('windows')
48+
owner 'root' unless platform_family?('windows')
4949
group node['root_group']
5050
end
5151

5252
template 'sshd_revoked_keys_file' do
5353
source 'revoked_keys.erb'
5454
path node['openssh']['server']['revoked_keys']
55-
mode node['openssh']['config_mode']
56-
owner 'root'
55+
mode node['openssh']['config_mode'] unless platform_family?('windows')
56+
owner 'root' unless platform_family?('windows')
5757
group node['root_group']
5858
end
5959

@@ -78,13 +78,19 @@ def listen_addr_for(interface, type)
7878
directory dir
7979
end
8080

81-
template '/etc/ssh/sshd_config' do
81+
default_sshd_path = if platform_family?('windows')
82+
"\"#{join_path(base_ssh_bin_dir, 'sshd.exe')}\""
83+
else
84+
join_path(base_ssh_bin_dir, 'sshd')
85+
end
86+
87+
template join_path(base_ssh_config_dir, 'sshd_config') do
8288
source 'sshd_config.erb'
83-
mode node['openssh']['config_mode']
84-
owner 'root'
89+
mode node['openssh']['config_mode'] unless platform_family?('windows')
90+
owner 'root' unless platform_family?('windows')
8591
group node['root_group']
8692
variables(options: openssh_server_options)
87-
verify '/usr/sbin/sshd -t -f %{path}'
93+
verify "#{default_sshd_path} -t -f %{path}"
8894
notifies :restart, 'service[ssh]'
8995
end
9096

recipes/iptables.rb

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# limitations under the License.
1818
#
1919

20+
# The iptables cookbook doesn't support Windows
21+
return if platform_family?('windows')
22+
2023
iptables_packages 'install iptables'
2124
iptables_service 'start iptables'
2225

spec/spec_helper.rb

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
config.platform = 'ubuntu'
99
config.version = '18.04'
1010
end
11+
12+
def join_path(*path)
13+
Chef::Util::PathHelper.cleanpath(::File.join(path))
14+
end

0 commit comments

Comments
 (0)