|
28 | 28 | sshd_x11forwarding = attribute('sshd_x11forwarding', value: 'no', description: 'Expected value for sshd_config X11Forwarding')
|
29 | 29 | sshd_banner = attribute('sshd_banner', value: 'none', description: 'Expected value for sshd_config Banner')
|
30 | 30 | sshd_max_auth_tries = attribute('sshd_max_auth_tries', value: 2, description: 'Expected value for max_auth_retries')
|
| 31 | +sshd_custom_user = attribute('sshd_custom_user', value: 'root', description: 'The SSH user is not always root. It must be an unprivileged user in a container') |
| 32 | +sshd_custom_path = attribute('sshd_custom_path', value: '/etc/ssh', description: 'Sometimes ssh configuration files are present in another location and ssh use them with the -f flag') |
| 33 | + |
| 34 | +sshd_valid_privseparation = if sshd_custom_user != 'root' |
| 35 | + 'no' |
| 36 | + else |
| 37 | + ssh_crypto.valid_privseparation |
| 38 | + end |
31 | 39 |
|
32 | 40 | only_if do
|
33 | 41 | command('sshd').exist?
|
|
63 | 71 | control 'sshd-04' do
|
64 | 72 | impact 1.0
|
65 | 73 | title 'Server: Check SSH folder owner, group and permissions.'
|
66 |
| - desc 'The SSH folder should owned by root, only be writable by owner and readable by others.' |
67 |
| - describe file('/etc/ssh') do |
| 74 | + desc 'The SSH folder should owned by root or a defined user, only be writable by owner and readable by others.' |
| 75 | + describe file(sshd_custom_path) do |
68 | 76 | it { should exist }
|
69 | 77 | it { should be_directory }
|
70 | 78 | it { should be_owned_by 'root' }
|
71 |
| - it { should be_grouped_into os.darwin? ? 'wheel' : 'root' } |
| 79 | + it { should be_grouped_into os.darwin? ? 'wheel' : sshd_custom_user } |
72 | 80 | it { should be_executable }
|
73 | 81 | it { should be_readable.by('owner') }
|
74 | 82 | it { should be_readable.by('group') }
|
|
84 | 92 | title 'Server: Check sshd_config owner, group and permissions.'
|
85 | 93 | desc 'The sshd_config should owned by root, only be writable/readable by owner and not be executable.'
|
86 | 94 |
|
87 |
| - describe file('/etc/ssh/sshd_config') do |
| 95 | + describe file(sshd_custom_path + '/sshd_config') do |
88 | 96 | it { should exist }
|
89 | 97 | it { should be_file }
|
90 | 98 | it { should be_owned_by 'root' }
|
|
194 | 202 | title 'Server: Use privilege separation'
|
195 | 203 | desc 'UsePrivilegeSeparation is an option, when enabled will allow the OpenSSH server to run a small (necessary) amount of code as root and the of the code in a chroot jail environment. This enables ssh to deal incoming network traffic in an unprivileged child process to avoid privilege escalation by an attacker.'
|
196 | 204 | describe sshd_config do
|
197 |
| - its('UsePrivilegeSeparation') { should eq(ssh_crypto.valid_privseparation) } |
| 205 | + its('UsePrivilegeSeparation') { should eq(sshd_valid_privseparation) } |
198 | 206 | end
|
199 | 207 | end
|
200 | 208 |
|
|
481 | 489 | impact 1.0
|
482 | 490 | title 'Server: DH primes'
|
483 | 491 | desc 'Verifies if strong DH primes are used in /etc/ssh/moduli'
|
484 |
| - describe bash("test $(awk '$5 < 2047 && $5 ~ /^[0-9]+$/ { print $5 }' /etc/ssh/moduli | uniq | wc -c) -eq 0") do |
| 492 | + describe bash("test $(awk '$5 < 2047 && $5 ~ /^[0-9]+$/ { print $5 }' #{sshd_custom_path}/moduli | uniq | wc -c) -eq 0") do |
485 | 493 | its('exit_status') { should eq 0 }
|
486 | 494 | its('stdout') { should eq '' }
|
487 | 495 | its('stderr') { should eq '' }
|
|
0 commit comments