Skip to content

Commit 51c18f2

Browse files
Merge pull request #211 from pbsc/permittunnel
Permittunnel
2 parents 3b7f92f + 6936abf commit 51c18f2

File tree

7 files changed

+74
-1
lines changed

7 files changed

+74
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ override['ssh-hardening']['ssh']['server']['listen_to'] = node['ipaddress']
5555
* `['ssh-hardening']['ssh']['server']['allow_tcp_forwarding']` - `false`. Set to `true` to allow TCP Forwarding
5656
* `['ssh-hardening']['ssh']['server']['allow_agent_forwarding']` - `false`. Set to `true` to allow Agent Forwarding
5757
* `['ssh-hardening']['ssh']['server']['allow_x11_forwarding']` - `false`. Set to `true` to allow X11 Forwarding
58+
* `['ssh-hardening']['ssh']['server']['permit_tunnel']` - `false` to disable tun device forwarding. Set to `true` to allow tun device forwarding. Other accepted values: 'yes', 'no', 'point-to-point', 'ethernet'. See `man sshd_config` for exact behaviors. Note: you'll also need to enable `allow_tcp_forwarding`.
5859
* `['ssh-hardening']['ssh']['server']['use_pam']` - `true`. Set to `false` to disable the pam authentication of sshd
5960
* `['ssh-hardening']['ssh']['server']['challenge_response_authentication']` - `false`. Set to `true` to enable challenge response authentication.
6061
* `['ssh-hardening']['ssh']['server']['deny_users']` - `[]` to configure `DenyUsers`, if specified login is disallowed for user names that match one of the patterns.

attributes/default.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
server['client_alive_interval'] = 300 # 5min
8787
server['client_alive_count'] = 3 # ~> 3 x interval
8888
server['allow_root_with_key'] = false
89+
server['permit_tunnel'] = false
8990
server['allow_tcp_forwarding'] = false
9091
server['allow_agent_forwarding'] = false
9192
server['allow_x11_forwarding'] = false

libraries/devsec_ssh.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ def get_server_kexs(enable_weak = false)
126126
end
127127
end
128128

129+
# Verify values of permit_tunnel
130+
def validate_permit_tunnel(value)
131+
case value
132+
when true
133+
'yes'
134+
when false
135+
'no'
136+
when 'yes', 'no', 'point-to-point', 'ethernet'
137+
value
138+
else
139+
raise "Incorrect value for attribute node['ssh-hardening']['ssh']['server']['permit_tunnel']: must be boolean or a string as defined in the sshd_config man pages, you passed \"#{value}\""
140+
end
141+
end
142+
129143
private
130144

131145
# :nocov:

recipes/server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
# we do lazy here to ensure we detect the version that comes with the packge update above
178178
lazy do
179179
{
180+
permit_tunnel: DevSec::Ssh.validate_permit_tunnel(node['ssh-hardening']['ssh']['server']['permit_tunnel']),
180181
mac: node['ssh-hardening']['ssh']['server']['mac'] || DevSec::Ssh.get_server_macs(node['ssh-hardening']['ssh']['server']['weak_hmac']),
181182
kex: node['ssh-hardening']['ssh']['server']['kex'] || DevSec::Ssh.get_server_kexs(node['ssh-hardening']['ssh']['server']['weak_kex']),
182183
cipher: node['ssh-hardening']['ssh']['server']['cipher'] || DevSec::Ssh.get_server_ciphers(node['ssh-hardening']['ssh']['server']['cbc_required']),

spec/libraries/devsec_ssh_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,30 @@ def self.debug(*); end
314314
subject.send(:get_ssh_client_version)
315315
end
316316
end
317+
318+
describe 'validate_permit_tunnel' do
319+
context 'with value of false' do
320+
it 'should return no' do
321+
expect(subject.send(:validate_permit_tunnel, false)).to eq 'no'
322+
end
323+
end
324+
325+
context 'with value of true' do
326+
it 'should return yes' do
327+
expect(subject.send(:validate_permit_tunnel, true)).to eq 'yes'
328+
end
329+
end
330+
331+
context 'with a valid string ethernet' do
332+
it 'should return ethernet' do
333+
expect(subject.send(:validate_permit_tunnel, 'ethernet')).to eq 'ethernet'
334+
end
335+
end
336+
337+
context 'with an invalid string' do
338+
it 'should raise exception' do
339+
expect { subject.send(:validate_permit_tunnel, 'IAmNotValid') }.to raise_exception('Incorrect value for attribute node[\'ssh-hardening\'][\'ssh\'][\'server\'][\'permit_tunnel\']: must be boolean or a string as defined in the sshd_config man pages, you passed "IAmNotValid"')
340+
end
341+
end
342+
end
317343
end

spec/recipes/server_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,36 @@
226226
end
227227
end
228228

229+
describe 'permit_tunnel options' do
230+
let(:permit_tunnel) { false }
231+
232+
let(:chef_run) do
233+
ChefSpec::ServerRunner.new do |node|
234+
node.normal['ssh-hardening']['ssh']['server']['permit_tunnel'] = permit_tunnel
235+
end.converge(described_recipe)
236+
end
237+
238+
context 'with default value of false' do
239+
it 'should set PermitTunnel to no' do
240+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('PermitTunnel no')
241+
end
242+
end
243+
244+
context 'with value of true' do
245+
let(:permit_tunnel) { true }
246+
it 'should set PermitTunnel to yes' do
247+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('PermitTunnel yes')
248+
end
249+
end
250+
251+
context 'with a valid string' do
252+
let(:permit_tunnel) { 'ethernet' }
253+
it 'should set PermitTunnel to ethernet' do
254+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('PermitTunnel ethernet')
255+
end
256+
end
257+
end
258+
229259
it 'should set UsePAM to yes per default' do
230260
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM yes')
231261
end

templates/default/opensshd.conf.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ ClientAliveInterval <%= @node['ssh-hardening']['ssh']['server']['client_alive_in
161161
ClientAliveCountMax <%= @node['ssh-hardening']['ssh']['server']['client_alive_count'] %>
162162

163163
# Disable tunneling
164-
PermitTunnel no
164+
PermitTunnel <%= @permit_tunnel %>
165165

166166
# Disable forwarding tcp connections.
167167
# no real advantage without denied shell access

0 commit comments

Comments
 (0)