Skip to content

Commit d51d334

Browse files
committed
feat: 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 d51d334

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

controls/os_spec.rb

+106
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,112 @@
8484
end
8585
end
8686

87+
control 'os-02b' do
88+
impact 1.0
89+
title 'Check owner and permissions for /etc/gshadow'
90+
desc 'Check periodically the owner and permissions for /etc/gshadow'
91+
describe file('/etc/gshadow') do
92+
it { should exist }
93+
it { should be_file }
94+
it { should be_owned_by 'root' }
95+
its('group') { should eq shadow_group }
96+
it { should_not be_executable }
97+
it { should_not be_readable.by('other') }
98+
end
99+
if os.redhat? || os.name == 'fedora'
100+
describe file('/etc/gshadow') do
101+
it { should_not be_writable.by('owner') }
102+
it { should_not be_readable.by('owner') }
103+
end
104+
else
105+
describe file('/etc/gshadow') do
106+
it { should be_writable.by('owner') }
107+
it { should be_readable.by('owner') }
108+
end
109+
end
110+
if os.debian? || os.suse?
111+
describe file('/etc/gshadow') do
112+
it { should be_readable.by('group') }
113+
end
114+
else
115+
describe file('/etc/gshadow') do
116+
it { should_not be_readable.by('group') }
117+
end
118+
end
119+
end
120+
121+
control 'os-02c' do
122+
impact 1.0
123+
title 'Check owner and permissions for /etc/shadow-'
124+
desc 'Check periodically the owner and permissions for /etc/shadow-'
125+
only_if('/etc/shadow- exists') do
126+
file('/etc/shadow-').exist?
127+
end
128+
describe file('/etc/shadow-') do
129+
it { should be_file }
130+
it { should be_owned_by 'root' }
131+
its('group') { should eq shadow_group }
132+
it { should_not be_executable }
133+
it { should_not be_readable.by('other') }
134+
end
135+
if os.redhat? || os.name == 'fedora'
136+
describe file('/etc/shadow-') do
137+
it { should_not be_writable.by('owner') }
138+
it { should_not be_readable.by('owner') }
139+
end
140+
else
141+
describe file('/etc/shadow-') do
142+
it { should be_writable.by('owner') }
143+
it { should be_readable.by('owner') }
144+
end
145+
end
146+
if os.debian? || os.suse?
147+
describe file('/etc/shadow-') do
148+
it { should be_readable.by('group') }
149+
end
150+
else
151+
describe file('/etc/shadow-') do
152+
it { should_not be_readable.by('group') }
153+
end
154+
end
155+
end
156+
157+
control 'os-02d' do
158+
impact 1.0
159+
title 'Check owner and permissions for /etc/gshadow-'
160+
desc 'Check periodically the owner and permissions for /etc/gshadow-'
161+
only_if('/etc/gshadow- exists') do
162+
file('/etc/gshadow-').exist?
163+
end
164+
describe file('/etc/gshadow-') do
165+
it { should be_file }
166+
it { should be_owned_by 'root' }
167+
its('group') { should eq shadow_group }
168+
it { should_not be_executable }
169+
it { should_not be_readable.by('other') }
170+
end
171+
if os.redhat? || os.name == 'fedora'
172+
describe file('/etc/shadow-') do
173+
it { should_not be_writable.by('owner') }
174+
it { should_not be_readable.by('owner') }
175+
end
176+
else
177+
describe file('/etc/gshadow-') do
178+
it { should be_writable.by('owner') }
179+
it { should be_readable.by('owner') }
180+
end
181+
end
182+
if os.debian? || os.suse?
183+
describe file('/etc/gshadow-') do
184+
it { should be_readable.by('group') }
185+
end
186+
else
187+
describe file('/etc/gshadow-') do
188+
it { should_not be_readable.by('group') }
189+
end
190+
end
191+
end
192+
87193
control 'os-03' do
88194
impact 1.0
89195
title 'Check owner and permissions for /etc/passwd'

0 commit comments

Comments
 (0)