Skip to content

Commit a1ab063

Browse files
committed
Improve Apparmor detection, using the sys virtual fs (sous-chefs#260)
1 parent 188e6af commit a1ab063

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

attributes/default.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
when 'debian'
103103
default['ntp']['leapfile_managed_by_os'] = true
104104
default['ntp']['service'] = 'ntp'
105-
default['ntp']['apparmor_enabled'] = true if File.exist?('/etc/init.d/apparmor')
105+
default['ntp']['apparmor_enabled'] = true if File.exist?('/sys/module/apparmor/parameters/enabled') && (File.open('/sys/module/apparmor/parameters/enabled') == 'Y')
106106
default['ntp']['leapfile'] = '/usr/share/zoneinfo/leap-seconds.list'
107107
when 'rhel', 'fedora', 'amazon'
108108
default['ntp']['leapfile_managed_by_os'] = true

spec/unit/attributes_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@
196196
describe 'on Ubuntu' do
197197
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '20.04').converge('ntp::default') }
198198

199-
it 'sets the apparmor_enabled attribute to true when /etc/init.d/apparmor exists' do
199+
it 'sets the apparmor_enabled attribute to true when /sys/module/apparmor/parameters/enabled exists' do
200200
allow(File).to receive(:exist?).and_call_original
201-
allow(File).to receive(:exist?).with('/etc/init.d/apparmor').and_return(true)
201+
allow(File).to receive(:exist?).with('/sys/module/apparmor/parameters/enabled').and_return(true)
202202
expect(ntp['apparmor_enabled']).to eq(true)
203203
end
204204

205-
it 'sets the apparmor_enabled attribute to false when /etc/init.d/apparmor does not exist' do
205+
it 'sets the apparmor_enabled attribute to false when /sys/module/apparmor/parameters/enabled does not exist' do
206206
allow(File).to receive(:exist?).and_call_original
207-
allow(File).to receive(:exist?).with('/etc/init.d/apparmor').and_return(false)
207+
allow(File).to receive(:exist?).with('/sys/module/apparmor/parameters/enabled').and_return(false)
208208
expect(ntp['apparmor_enabled']).to eq(false)
209209
end
210210
end

0 commit comments

Comments
 (0)