Skip to content

Commit fb7a8f7

Browse files
Merge pull request #203 from artem-forks/deprecations
Removal of deprecated options for newer openssh versions
2 parents f042bc0 + c9e58c2 commit fb7a8f7

File tree

9 files changed

+66
-14
lines changed

9 files changed

+66
-14
lines changed

.kitchen.dokken.yml

-3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,3 @@ suites:
9494
run_list:
9595
- recipe[test]
9696
- recipe[ssh-hardening]
97-
verifier:
98-
inspec_tests:
99-
- https://github.com/dev-sec/ssh-baseline

.kitchen.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ suites:
3636
run_list:
3737
- recipe[test]
3838
- recipe[ssh-hardening]
39-
verifier:
40-
inspec_tests:
41-
- https://github.com/dev-sec/ssh-baseline
4239
- name: rhel-with-disabled-pam
4340
includes:
4441
- centos-6.8
@@ -61,5 +58,5 @@ suites:
6158
use_pam: false
6259
verifier:
6360
inspec_tests:
64-
- https://github.com/dev-sec/ssh-baseline
61+
- test/integration/default
6562
- test/integration/without-pam

recipes/client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
# limitations under the License.
2121
#
2222

23-
ohai 'reload' do
23+
ohai 'reload openssh-client' do
2424
action :nothing
2525
end
2626

2727
package 'openssh-client' do
2828
package_name node['ssh-hardening']['sshclient']['package']
2929
# we need to reload the package version, otherwise we get the version that was installed before cookbook execution
30-
notifies :reload, 'ohai[reload]', :immediate
30+
notifies :reload, 'ohai[reload openssh-client]', :immediately
3131
end
3232

3333
directory 'openssh-client ssh directory /etc/ssh' do

recipes/server.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
directory cache_dir
4141

4242
# installs package name
43-
ohai 'reload' do
43+
ohai 'reload openssh-server' do
4444
action :nothing
4545
end
4646

4747
package 'openssh-server' do
4848
package_name node['ssh-hardening']['sshserver']['package']
4949
# we need to reload the package version, otherwise we get the version that was installed before cookbook execution
50-
notifies :reload, 'ohai[reload]', :immediate
50+
notifies :reload, 'ohai[reload openssh-server]', :immediately
5151
end
5252

5353
# Handle addional SELinux policy on RHEL/Fedora for different UsePAM options
@@ -181,7 +181,8 @@
181181
kex: node['ssh-hardening']['ssh']['server']['kex'] || DevSec::Ssh.get_server_kexs(node['ssh-hardening']['ssh']['server']['weak_kex']),
182182
cipher: node['ssh-hardening']['ssh']['server']['cipher'] || DevSec::Ssh.get_server_ciphers(node['ssh-hardening']['ssh']['server']['cbc_required']),
183183
use_priv_sep: node['ssh-hardening']['ssh']['use_privilege_separation'] || DevSec::Ssh.get_server_privilege_separarion,
184-
hostkeys: node['ssh-hardening']['ssh']['server']['host_key_files'] || DevSec::Ssh.get_server_algorithms.map { |alg| "/etc/ssh/ssh_host_#{alg}_key" }
184+
hostkeys: node['ssh-hardening']['ssh']['server']['host_key_files'] || DevSec::Ssh.get_server_algorithms.map { |alg| "/etc/ssh/ssh_host_#{alg}_key" },
185+
version: DevSec::Ssh.get_ssh_server_version
185186
}
186187
end
187188
)

spec/recipes/server_spec.rb

+42-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,46 @@
230230
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM yes')
231231
end
232232

233+
describe 'version specifc options' do
234+
context 'running with OpenSSH < 7.4' do
235+
it 'should have UseLogin' do
236+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UseLogin')
237+
end
238+
239+
it 'should have UsePrivilegeSeparation' do
240+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePrivilegeSeparation')
241+
end
242+
end
243+
244+
context 'running with OpenSSH >= 7.4 on RHEL 7' do
245+
let(:chef_run) do
246+
ChefSpec::ServerRunner.new(platform: 'centos', version: '7.5.1804').converge(described_recipe)
247+
end
248+
249+
before do
250+
stub_command('getenforce | grep -vq Disabled && semodule -l | grep -q ssh_password').and_return(true)
251+
end
252+
253+
it 'should not have UseLogin' do
254+
expect(chef_run).to_not render_file('/etc/ssh/sshd_config').with_content('UseLogin')
255+
end
256+
end
257+
258+
context 'running with Openssh >= 7.5 on Ubuntu 18.04' do
259+
let(:chef_run) do
260+
ChefSpec::ServerRunner.new(version: '18.04').converge(described_recipe)
261+
end
262+
263+
it 'should not have UseLogin' do
264+
expect(chef_run).to_not render_file('/etc/ssh/sshd_config').with_content('UseLogin')
265+
end
266+
267+
it 'should not have UsePrivilegeSeparation' do
268+
expect(chef_run).to_not render_file('/etc/ssh/sshd_config').with_content('UsePrivilegeSeparation')
269+
end
270+
end
271+
end
272+
233273
describe 'UsePAM option' do
234274
let(:use_pam) { true }
235275

@@ -269,7 +309,7 @@
269309

270310
context 'when running on CentOS' do
271311
let(:platform) { 'centos' }
272-
let(:version) { '7.2.1511' }
312+
let(:version) { '7.5.1804' }
273313

274314
let(:selinux_disabled_or_policy_removed) { false }
275315
let(:selinux_enabled_and_policy_installed) { false }
@@ -392,7 +432,7 @@
392432
end
393433

394434
cached(:chef_run) do
395-
ChefSpec::ServerRunner.new(platform: 'centos', version: '7.2.1511') do |node|
435+
ChefSpec::ServerRunner.new(platform: 'centos', version: '7.5.1804') do |node|
396436
node.normal['ssh-hardening']['ssh']['server']['os_banner'] = true
397437
end.converge(described_recipe)
398438
end

templates/default/opensshd.conf.erb

+4
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ KexAlgorithms <%= @kex %>
8585
# --------------
8686

8787
# Secure Login directives.
88+
<% if @version.to_f < 7.4 %>
8889
UseLogin no
90+
<% end %>
91+
<% if @version.to_f < 7.5 %>
8992
UsePrivilegeSeparation <%= @use_priv_sep %>
93+
<% end %>
9094
PermitUserEnvironment no
9195
LoginGraceTime <%= @node['ssh-hardening']['ssh']['server']['login_grace_time'] %>
9296
MaxAuthTries <%= @node['ssh-hardening']['ssh']['server']['max_auth_tries'] %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
control 'sshd configuration should not have any deprecations' do
2+
describe command('sshd -t') do
3+
its(:exit_status) { should eq 0 }
4+
its(:stdout) { should eq '' }
5+
its(:stderr) { should eq '' }
6+
end
7+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include_controls 'ssh-baseline'

test/integration/default/inspec.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: ssh-hardening-integration-tests
2+
version: 1.0.0
3+
depends:
4+
- name: ssh-baseline
5+
url: https://github.com/dev-sec/ssh-baseline

0 commit comments

Comments
 (0)