Skip to content

Commit 8c77ce3

Browse files
Bugfix: sshd listens on IPv6 interface if enabled
Fixes dev-secGH-140
1 parent 04e0374 commit 8c77ce3

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ This cookbook provides secure ssh-client and ssh-server configurations. This coo
5858
* `['ssh-hardening']['ssh']['sftp']['group']` - `sftponly` to configure the `Match Group` option of SFTP to allow SFTP only for dedicated users
5959
* `['ssh-hardening']['ssh']['sftp']['chroot']` - `/home/%u` to configure the directory where the SFTP user should be chrooted
6060

61+
Notice: Some of attribute defaults of this cookbook are set in the recipes. You will have to use a higher [attribute precedence](https://docs.chef.io/attributes.html#attribute-precedence) in order to override them.
62+
6163
## Usage
6264

6365
Add the recipes to the run_list:

attributes/default.rb

-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
default['ssh-hardening']['ssh']['client']['cbc_required'] = false
5959
default['ssh-hardening']['ssh']['client']['weak_hmac'] = false
6060
default['ssh-hardening']['ssh']['client']['weak_kex'] = false
61-
6261
default['ssh-hardening']['ssh']['client']['remote_hosts'] = []
6362
default['ssh-hardening']['ssh']['client']['password_authentication'] = false # ssh
6463
# http://undeadly.org/cgi?action=article&sid=20160114142733
@@ -71,11 +70,9 @@
7170
default['ssh-hardening']['ssh']['server']['cbc_required'] = false
7271
default['ssh-hardening']['ssh']['server']['weak_hmac'] = false
7372
default['ssh-hardening']['ssh']['server']['weak_kex'] = false
74-
default['ssh-hardening']['ssh']['server']['listen_to'] = ['0.0.0.0']
7573
default['ssh-hardening']['ssh']['server']['host_key_files'] = ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key']
7674
default['ssh-hardening']['ssh']['server']['client_alive_interval'] = 600 # 10min
7775
default['ssh-hardening']['ssh']['server']['client_alive_count'] = 3 # ~> 3 x interval
78-
7976
default['ssh-hardening']['ssh']['server']['allow_root_with_key'] = false
8077
default['ssh-hardening']['ssh']['server']['allow_tcp_forwarding'] = false
8178
default['ssh-hardening']['ssh']['server']['allow_agent_forwarding'] = false

recipes/server.rb

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
# limitations under the License.
2020
#
2121

22+
# default attributes
23+
# We can not set this kind of defaults in the attribute files
24+
# as we react on value of other attributes
25+
# https://github.com/dev-sec/chef-ssh-hardening/issues/140#issuecomment-267779720
26+
node.default['ssh-hardening']['ssh']['listen_to'] =
27+
if node['ssh-hardening']['network']['ipv6']['enable']
28+
['0.0.0.0', '::']
29+
else
30+
['0.0.0.0']
31+
end
32+
2233
# installs package name
2334
package 'openssh-server' do
2435
package_name node['ssh-hardening']['sshserver']['package']

spec/recipes/server_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,31 @@
374374
with_content(/^ChrootDirectory test_home_dir$/)
375375
end
376376
end
377+
378+
context 'with disabled IPv6' do
379+
cached(:chef_run) do
380+
ChefSpec::ServerRunner.new do |node|
381+
node.normal['ssh-hardening']['network']['ipv6']['enable'] = false
382+
end.converge(described_recipe)
383+
end
384+
385+
it 'sets proper IPv4 ListenAdress' do
386+
expect(chef_run).to render_file('/etc/ssh/sshd_config').
387+
with_content(/ListenAddress 0.0.0.0/)
388+
end
389+
end
390+
391+
context 'with enabled IPv6' do
392+
cached(:chef_run) do
393+
ChefSpec::ServerRunner.new do |node|
394+
node.normal['ssh-hardening']['network']['ipv6']['enable'] = true
395+
end.converge(described_recipe)
396+
end
397+
398+
it 'sets proper IPv4 and IPv6 ListenAdress' do
399+
expect(chef_run).to render_file('/etc/ssh/sshd_config').
400+
with_content(/ListenAddress 0.0.0.0/).
401+
with_content(/ListenAddress ::/)
402+
end
403+
end
377404
end

0 commit comments

Comments
 (0)