Skip to content

Commit 0a81810

Browse files
authored
Merge pull request #148 from artem-sidorenko/ipv6
Bugfix: sshd listens on IPv6 interface if enabled
2 parents 941f1e7 + 03ca687 commit 0a81810

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Below you can find the attribute documentation and their default values.
4040
* `['ssh-hardening']['ssh']['client']['remote_hosts']` - `[]` - one or more hosts, to which ssh-client can connect to.
4141
* `['ssh-hardening']['ssh']['client']['password_authentication']` - `false`. Set to `true` if password authentication should be enabled.
4242
* `['ssh-hardening']['ssh']['client']['roaming']` - `false`. Set to `true` if experimental client roaming should be enabled. This is known to cause potential issues with secrets being disclosed to malicious servers and defaults to being disabled.
43-
* `['ssh-hardening']['ssh']['server']['listen_to']` - one or more ip addresses, to which ssh-server should listen to. Default is empty, but should be configured for security reasons!
43+
* `['ssh-hardening']['ssh']['server']['listen_to']` - one or more ip addresses, to which ssh-server should listen to. Default is to listen on all interfaces. It should be configured for security reasons!
4444
* `['ssh-hardening']['ssh']['server']['allow_root_with_key']` - `false` to disable root login altogether. Set to `true` to allow root to login via key-based mechanism
4545
* `['ssh-hardening']['ssh']['server']['allow_tcp_forwarding']` - `false`. Set to `true` to allow TCP Forwarding
4646
* `['ssh-hardening']['ssh']['server']['allow_agent_forwarding']` - `false`. Set to `true` to allow Agent Forwarding
@@ -65,6 +65,8 @@ Below you can find the attribute documentation and their default values.
6565
* `['ssh-hardening']['ssh']['server']['sftp']['group']` - `sftponly`. Sets the `Match Group` option of SFTP to allow SFTP only for dedicated users
6666
* `['ssh-hardening']['ssh']['server']['sftp']['chroot']` - `/home/%u`. Sets the directory where the SFTP user should be chrooted
6767

68+
Notice: Some of attribute defaults of this cookbook are set in the recipes. Its a good idea to use a higher [attribute precedence](https://docs.chef.io/attributes.html#attribute-precedence) level for attribute overriding. Otherwise you might get unexpected results.
69+
6870
## Usage
6971

7072
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']['server']['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
@@ -410,4 +410,31 @@
410410
with_content(/^ChrootDirectory test_home_dir$/)
411411
end
412412
end
413+
414+
context 'with disabled IPv6' do
415+
cached(:chef_run) do
416+
ChefSpec::ServerRunner.new do |node|
417+
node.normal['ssh-hardening']['network']['ipv6']['enable'] = false
418+
end.converge(described_recipe)
419+
end
420+
421+
it 'sets proper IPv4 ListenAdress' do
422+
expect(chef_run).to render_file('/etc/ssh/sshd_config').
423+
with_content(/ListenAddress 0.0.0.0/)
424+
end
425+
end
426+
427+
context 'with enabled IPv6' do
428+
cached(:chef_run) do
429+
ChefSpec::ServerRunner.new do |node|
430+
node.normal['ssh-hardening']['network']['ipv6']['enable'] = true
431+
end.converge(described_recipe)
432+
end
433+
434+
it 'sets proper IPv4 and IPv6 ListenAdress' do
435+
expect(chef_run).to render_file('/etc/ssh/sshd_config').
436+
with_content(/ListenAddress 0.0.0.0/).
437+
with_content(/ListenAddress ::/)
438+
end
439+
end
413440
end

0 commit comments

Comments
 (0)