Skip to content

Commit 5dc04cb

Browse files
In a container, ssh should not run as root
Add the option to choose the owner of configurations files and their locations. Signed-off-by: Michée Lengronne <michee.lengronne@coppint.com>
1 parent 7f15d47 commit 5dc04cb

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

controls/ssh_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,28 @@
2222
command('ssh').exist?
2323
end
2424

25+
custom_user = attribute(
26+
'custom_user',
27+
value: 'root',
28+
description: 'The SSH user is not always root. It must be an unprivileged user in a container'
29+
)
30+
31+
custom_path = attribute(
32+
'custom_path',
33+
value: '/etc/ssh',
34+
description: 'Sometimes ssh configuration files are present in another location and ssh use them with the -f flag'
35+
)
36+
2537
control 'ssh-01' do
2638
impact 1.0
2739
title 'client: Check ssh_config owner, group and permissions.'
28-
desc 'The ssh_config should owned by root, only be writable by owner and readable to all.'
40+
desc 'The ssh_config should owned by root or a specified user, only be writable by owner and readable to all.'
2941

30-
describe file('/etc/ssh/ssh_config') do
42+
describe file(custom_path + '/ssh_config') do
3143
it { should exist }
3244
it { should be_file }
33-
it { should be_owned_by 'root' }
34-
it { should be_grouped_into os.darwin? ? 'wheel' : 'root' }
45+
it { should be_owned_by custom_user }
46+
it { should be_grouped_into os.darwin? ? 'wheel' : custom_user }
3547
it { should_not be_executable }
3648
it { should be_readable.by('owner') }
3749
it { should be_readable.by('group') }

0 commit comments

Comments
 (0)