Skip to content

Commit 31b8fb7

Browse files
committed
Merge pull request #72 from TelekomLabs/priv-sep-sandbox
add privilege separation via sandbox mode for ssh >= 5.9
2 parents 4953f40 + da703e7 commit 31b8fb7

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

attributes/default.rb

+2
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@
5959
default['ssh']['allow_tcp_forwarding'] = false # sshd
6060
default['ssh']['allow_agent_forwarding'] = false # sshd
6161
default['ssh']['use_pam'] = false # sshd
62+
# set this to nil to let us detect the attribute based on the node platform
63+
default['ssh']['use_privilege_separation'] = nil

libraries/use_privilege_separation.rb

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# encoding: utf-8
2+
#
3+
# Cookbook Name:: ssh-hardening
4+
# Library:: use_privilege_separation
5+
#
6+
# Copyright 2015, Dominik Richter
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
class Chef
22+
class Recipe
23+
class UsePrivilegeSeparation
24+
def self.get(node)
25+
# define cipher set
26+
ps53 = 'yes'
27+
ps59 = 'sandbox'
28+
ps = ps59
29+
30+
# ubuntu 12.04 and newer has ssh 5.9+
31+
32+
# redhat/centos/oracle 6.x has ssh 5.3
33+
if node['platform_family'] == 'rhel'
34+
ps = ps53
35+
36+
# debian 7.x and newer has ssh 5.9+
37+
elsif node['platform'] == 'debian' && node['platform_version'].to_f <= 6
38+
ps = ps53
39+
end
40+
41+
Chef::Log.info("UsePrivilegeSeparation: #{ps}")
42+
ps
43+
end
44+
end
45+
end
46+
end

recipes/server.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
variables(
9393
mac: SshMac.get_macs(node, node['ssh']['server']['weak_hmac']),
9494
kex: SshKex.get_kexs(node, node['ssh']['server']['weak_kex']),
95-
cipher: SshCipher.get_ciphers(node, node['ssh']['server']['cbc_required'])
95+
cipher: SshCipher.get_ciphers(node, node['ssh']['server']['cbc_required']),
96+
use_priv_sep: node['ssh']['use_privilege_separation'] || UsePrivilegeSeparation.get(node)
9697
)
9798
notifies :restart, 'service[sshd]'
9899
end

templates/default/opensshd.conf.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ KexAlgorithms <%= @kex %>
8686

8787
# Secure Login directives.
8888
UseLogin no
89-
UsePrivilegeSeparation yes
89+
UsePrivilegeSeparation <%= @use_priv_sep %>
9090
PermitUserEnvironment no
9191
LoginGraceTime 30s
9292
MaxAuthTries 2

0 commit comments

Comments
 (0)