|
52 | 52 |
|
53 | 53 | control 'os-02' do |
54 | 54 | 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') } |
74 | 70 | 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 |
79 | 81 | 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 |
83 | 90 | end |
84 | 91 | end |
85 | 92 | end |
|
0 commit comments