Skip to content

Commit

Permalink
feat: expand security check: add other passwd and group files
Browse files Browse the repository at this point in the history
Currently only `/etc/passwd` is checked to have the right permissions,
but there are other files that contain unix account related configuration:

 - /etc/passwd- (a backup file for /etc/passwd)
 - /etc/group (contains group configuration and membership)
 - /etc/group- (a backup file for /etc/group-)

While the control requires `/etc/passwd` and `/etc/group` 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]>
  • Loading branch information
cmhe committed Nov 3, 2021
1 parent 5d29e31 commit 4b67c2d
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions controls/os_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,63 @@
it { should_not be_readable.by('other') }
end
end

control 'os-17' do
impact 1.0
title 'Check owner and permissions for /etc/group'
desc 'Check periodically the owner and permissions for /etc/group'
describe file('/etc/group') do
it { should exist }
it { should be_file }
it { should be_owned_by 'root' }
its('group') { should eq 'root' }
it { should_not be_executable }
it { should be_writable.by('owner') }
it { should be_readable.by('owner') }
it { should_not be_writable.by('group') }
it { should be_readable.by('group') }
it { should_not be_writable.by('other') }
it { should be_readable.by('other') }
end
end

control 'os-18' do
impact 1.0
title 'Check owner and permissions for /etc/passwd-'
desc 'Check periodically the owner and permissions for /etc/passwd-'
only_if('/etc/passwd- exists') do
file('/etc/passwd-').exist?
end
describe file('/etc/passwd-') do
it { should be_file }
it { should be_owned_by 'root' }
its('group') { should eq 'root' }
it { should_not be_executable }
it { should be_writable.by('owner') }
it { should be_readable.by('owner') }
it { should_not be_writable.by('group') }
it { should be_readable.by('group') }
it { should_not be_writable.by('other') }
it { should be_readable.by('other') }
end
end

control 'os-19' do
impact 1.0
title 'Check owner and permissions for /etc/group-'
desc 'Check periodically the owner and permissions for /etc/group-'
only_if('/etc/group- exists') do
file('/etc/group-').exist?
end
describe file('/etc/group-') do
it { should be_owned_by 'root' }
its('group') { should eq 'root' }
it { should_not be_executable }
it { should be_writable.by('owner') }
it { should be_readable.by('owner') }
it { should_not be_writable.by('group') }
it { should be_readable.by('group') }
it { should_not be_writable.by('other') }
it { should be_readable.by('other') }
end
end

0 comments on commit 4b67c2d

Please sign in to comment.