Skip to content

Commit 7722313

Browse files
author
Marc Chamberland
committed
Allowing all possible values of PermitTunnnel
Signed-off-by: Marc Chamberland <[email protected]>
1 parent b838ef4 commit 7722313

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +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
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`.
5959
* `['ssh-hardening']['ssh']['server']['use_pam']` - `true`. Set to `false` to disable the pam authentication of sshd
6060
* `['ssh-hardening']['ssh']['server']['challenge_response_authentication']` - `false`. Set to `true` to enable challenge response authentication.
6161
* `['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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
server['client_alive_interval'] = 300 # 5min
8787
server['client_alive_count'] = 3 # ~> 3 x interval
8888
server['allow_root_with_key'] = false
89-
9089
server['permit_tunnel'] = false
9190
server['allow_tcp_forwarding'] = false
9291
server['allow_agent_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/recipes/server_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,37 @@
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 value of true' do
239+
let(:permit_tunnel) { true }
240+
it 'should set PermitTunnel to yes' do
241+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('PermitTunnel yes')
242+
end
243+
end
244+
245+
context 'with a valid string' do
246+
let(:permit_tunnel) { 'ethernet' }
247+
it 'should set PermitTunnel to ethernet' do
248+
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('PermitTunnel ethernet')
249+
end
250+
end
251+
252+
context 'with an invalid string' do
253+
let(:permit_tunnel) { 'IAmNotValid' }
254+
it 'abort the Chef run' do
255+
expect { chef_run }.not_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"')
256+
end
257+
end
258+
end
259+
229260
it 'should set UsePAM to yes per default' do
230261
expect(chef_run).to render_file('/etc/ssh/sshd_config').with_content('UsePAM yes')
231262
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 <%= ((@node['ssh-hardening']['ssh']['server']['permit_tunnel']) ? 'yes' : 'no' ) %>
164+
PermitTunnel <%= @permit_tunnel %>
165165

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

0 commit comments

Comments
 (0)