Skip to content

Commit e43b135

Browse files
committed
feat(os-02): expand security control to check for other shadow files
Currently only `/etc/shadow` is checked to have the right permissions, but there are other files that can/could contain password hashes as well, which are not checked yet: - /etc/shadow- (a backup file for /etc/shadow) - /etc/gshadow (contains group password hashes) - /etc/gshadow- (a backup file for /etc/gshadow-) While the control requires `/etc/shadow` and `/etc/gshadow` to exist, the rules for their backup counterparts are a bit more relaxed. The checks will be skipped, if those files do not exist. Signed-off-by: Claudius Heine <ch@denx.de>
1 parent e503f97 commit e43b135

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

controls/os_spec.rb

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,40 @@
5252

5353
control 'os-02' do
5454
impact 1.0
55-
title 'Check owner and permissions for /etc/shadow'
56-
desc 'Check periodically the owner and permissions for /etc/shadow'
57-
describe file('/etc/shadow') do
58-
it { should exist }
59-
it { should be_file }
60-
it { should be_owned_by 'root' }
61-
its('group') { should eq shadow_group }
62-
it { should_not be_executable }
63-
it { should_not be_readable.by('other') }
64-
end
65-
if os.redhat? || os.name == 'fedora'
66-
describe file('/etc/shadow') do
67-
it { should_not be_writable.by('owner') }
68-
it { should_not be_readable.by('owner') }
69-
end
70-
else
71-
describe file('/etc/shadow') do
72-
it { should be_writable.by('owner') }
73-
it { should be_readable.by('owner') }
55+
title 'Check owner and permissions for shadow files'
56+
desc 'Check periodically the owner and permissions for shadow files'
57+
58+
shadow_files = ['/etc/shadow', '/etc/shadow-', '/etc/gshadow', '/etc/gshadow-']
59+
shadow_files.each do |shadow_file|
60+
next if shadow_file[-1] == '-' && !file(shadow_file).exist?
61+
62+
describe file(shadow_file) do
63+
it { should exist }
64+
it { should be_file }
65+
it { should be_owned_by 'root' }
66+
its('group') { should eq shadow_group }
67+
it { should_not be_executable }
68+
it { should_not be_readable.by('other') }
7469
end
75-
end
76-
if os.debian? || os.suse?
77-
describe file('/etc/shadow') do
78-
it { should be_readable.by('group') }
70+
if os.redhat? || os.name == 'fedora'
71+
describe file(shadow_file) do
72+
it { should_not be_writable.by('owner') }
73+
it { should_not be_readable.by('owner') }
74+
end
75+
else
76+
describe file(shadow_file) do
77+
it { should be_writable.by('owner') }
78+
it { should be_readable.by('owner') }
79+
end
7980
end
80-
else
81-
describe file('/etc/shadow') do
82-
it { should_not be_readable.by('group') }
81+
if os.debian? || os.suse?
82+
describe file(shadow_file) do
83+
it { should be_readable.by('group') }
84+
end
85+
else
86+
describe file(shadow_file) do
87+
it { should_not be_readable.by('group') }
88+
end
8389
end
8490
end
8591
end

0 commit comments

Comments
 (0)