Skip to content

Commit 8c8d8ec

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 <[email protected]>
1 parent e503f97 commit 8c8d8ec

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

controls/os_spec.rb

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,41 @@
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+
'(/etc/shadow, /etc/shadow-, /etc/gshadow, /etc/gshadow-)'
58+
59+
shadow_files = ['/etc/shadow', '/etc/shadow-', '/etc/gshadow', '/etc/gshadow-']
60+
shadow_files.each do |shadow_file|
61+
next if shadow_file[-1] == '-' && !file(shadow_file).exist?
62+
63+
describe file(shadow_file) do
64+
it { should exist }
65+
it { should be_file }
66+
it { should be_owned_by 'root' }
67+
its('group') { should eq shadow_group }
68+
it { should_not be_executable }
69+
it { should_not be_readable.by('other') }
7470
end
75-
end
76-
if os.debian? || os.suse?
77-
describe file('/etc/shadow') do
78-
it { should be_readable.by('group') }
71+
if os.redhat? || os.name == 'fedora'
72+
describe file(shadow_file) do
73+
it { should_not be_writable.by('owner') }
74+
it { should_not be_readable.by('owner') }
75+
end
76+
else
77+
describe file(shadow_file) do
78+
it { should be_writable.by('owner') }
79+
it { should be_readable.by('owner') }
80+
end
7981
end
80-
else
81-
describe file('/etc/shadow') do
82-
it { should_not be_readable.by('group') }
82+
if os.debian? || os.suse?
83+
describe file(shadow_file) do
84+
it { should be_readable.by('group') }
85+
end
86+
else
87+
describe file(shadow_file) do
88+
it { should_not be_readable.by('group') }
89+
end
8390
end
8491
end
8592
end

0 commit comments

Comments
 (0)