Skip to content

Commit

Permalink
Merge pull request #203 from artem-forks/deprecations
Browse files Browse the repository at this point in the history
Removal of deprecated options for newer openssh versions
  • Loading branch information
artem-sidorenko authored Oct 18, 2018
2 parents f042bc0 + c9e58c2 commit fb7a8f7
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .kitchen.dokken.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,3 @@ suites:
run_list:
- recipe[test]
- recipe[ssh-hardening]
verifier:
inspec_tests:
- https://github.com/dev-sec/ssh-baseline
5 changes: 1 addition & 4 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ suites:
run_list:
- recipe[test]
- recipe[ssh-hardening]
verifier:
inspec_tests:
- https://github.com/dev-sec/ssh-baseline
- name: rhel-with-disabled-pam
includes:
- centos-6.8
Expand All @@ -61,5 +58,5 @@ suites:
use_pam: false
verifier:
inspec_tests:
- https://github.com/dev-sec/ssh-baseline
- test/integration/default
- test/integration/without-pam
4 changes: 2 additions & 2 deletions recipes/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
# limitations under the License.
#

ohai 'reload' do
ohai 'reload openssh-client' do
action :nothing
end

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

directory 'openssh-client ssh directory /etc/ssh' do
Expand Down
7 changes: 4 additions & 3 deletions recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
directory cache_dir

# installs package name
ohai 'reload' do
ohai 'reload openssh-server' do
action :nothing
end

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

# Handle addional SELinux policy on RHEL/Fedora for different UsePAM options
Expand Down Expand Up @@ -181,7 +181,8 @@
kex: node['ssh-hardening']['ssh']['server']['kex'] || DevSec::Ssh.get_server_kexs(node['ssh-hardening']['ssh']['server']['weak_kex']),
cipher: node['ssh-hardening']['ssh']['server']['cipher'] || DevSec::Ssh.get_server_ciphers(node['ssh-hardening']['ssh']['server']['cbc_required']),
use_priv_sep: node['ssh-hardening']['ssh']['use_privilege_separation'] || DevSec::Ssh.get_server_privilege_separarion,
hostkeys: node['ssh-hardening']['ssh']['server']['host_key_files'] || DevSec::Ssh.get_server_algorithms.map { |alg| "/etc/ssh/ssh_host_#{alg}_key" }
hostkeys: node['ssh-hardening']['ssh']['server']['host_key_files'] || DevSec::Ssh.get_server_algorithms.map { |alg| "/etc/ssh/ssh_host_#{alg}_key" },
version: DevSec::Ssh.get_ssh_server_version
}
end
)
Expand Down
44 changes: 42 additions & 2 deletions spec/recipes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,46 @@
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM yes')
end

describe 'version specifc options' do
context 'running with OpenSSH < 7.4' do
it 'should have UseLogin' do
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UseLogin')
end

it 'should have UsePrivilegeSeparation' do
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePrivilegeSeparation')
end
end

context 'running with OpenSSH >= 7.4 on RHEL 7' do
let(:chef_run) do
ChefSpec::ServerRunner.new(platform: 'centos', version: '7.5.1804').converge(described_recipe)
end

before do
stub_command('getenforce | grep -vq Disabled && semodule -l | grep -q ssh_password').and_return(true)
end

it 'should not have UseLogin' do
expect(chef_run).to_not render_file('/etc/ssh/sshd_config').with_content('UseLogin')
end
end

context 'running with Openssh >= 7.5 on Ubuntu 18.04' do
let(:chef_run) do
ChefSpec::ServerRunner.new(version: '18.04').converge(described_recipe)
end

it 'should not have UseLogin' do
expect(chef_run).to_not render_file('/etc/ssh/sshd_config').with_content('UseLogin')
end

it 'should not have UsePrivilegeSeparation' do
expect(chef_run).to_not render_file('/etc/ssh/sshd_config').with_content('UsePrivilegeSeparation')
end
end
end

describe 'UsePAM option' do
let(:use_pam) { true }

Expand Down Expand Up @@ -269,7 +309,7 @@

context 'when running on CentOS' do
let(:platform) { 'centos' }
let(:version) { '7.2.1511' }
let(:version) { '7.5.1804' }

let(:selinux_disabled_or_policy_removed) { false }
let(:selinux_enabled_and_policy_installed) { false }
Expand Down Expand Up @@ -392,7 +432,7 @@
end

cached(:chef_run) do
ChefSpec::ServerRunner.new(platform: 'centos', version: '7.2.1511') do |node|
ChefSpec::ServerRunner.new(platform: 'centos', version: '7.5.1804') do |node|
node.normal['ssh-hardening']['ssh']['server']['os_banner'] = true
end.converge(described_recipe)
end
Expand Down
4 changes: 4 additions & 0 deletions templates/default/opensshd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ KexAlgorithms <%= @kex %>
# --------------

# Secure Login directives.
<% if @version.to_f < 7.4 %>
UseLogin no
<% end %>
<% if @version.to_f < 7.5 %>
UsePrivilegeSeparation <%= @use_priv_sep %>
<% end %>
PermitUserEnvironment no
LoginGraceTime <%= @node['ssh-hardening']['ssh']['server']['login_grace_time'] %>
MaxAuthTries <%= @node['ssh-hardening']['ssh']['server']['max_auth_tries'] %>
Expand Down
7 changes: 7 additions & 0 deletions test/integration/default/controls/deprecations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
control 'sshd configuration should not have any deprecations' do
describe command('sshd -t') do
its(:exit_status) { should eq 0 }
its(:stdout) { should eq '' }
its(:stderr) { should eq '' }
end
end
1 change: 1 addition & 0 deletions test/integration/default/controls/ssh-baseline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include_controls 'ssh-baseline'
5 changes: 5 additions & 0 deletions test/integration/default/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: ssh-hardening-integration-tests
version: 1.0.0
depends:
- name: ssh-baseline
url: https://github.com/dev-sec/ssh-baseline

0 comments on commit fb7a8f7

Please sign in to comment.