Skip to content

Commit

Permalink
Merge pull request #151 from vinzent/issue_18_autorelabel
Browse files Browse the repository at this point in the history
Create /.autorelabel when switching from disabled
  • Loading branch information
bastelfreak authored Dec 24, 2016
2 parents 41a28dc + e37bfe9 commit 422cd7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@
}
}

# a complete relabeling is required when switching from disabled to
# permissive or enforcing. Ensure the autorelabel trigger file is created.
if $mode in ['enforcing','permissive'] and
!$::selinux_enabled {
file { '/.autorelabel':
ensure => 'file',
owner => 'root',
group => 'root',
content => "# created by puppet for disabled to ${mode} switch\n",
}
}

exec { "change-selinux-status-to-${mode}":
command => "setenforce ${sestatus}",
unless => "getenforce | grep -Eqi '${mode}|disabled'",
Expand Down
20 changes: 20 additions & 0 deletions spec/classes/selinux_config_mode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
it { is_expected.not_to contain_exec('change-selinux-status-to-enforcing') }
it { is_expected.not_to contain_exec('change-selinux-status-to-permissive') }
it { is_expected.not_to contain_exec('change-selinux-status-to-disabled') }
it { is_expected.not_to contain_file('/.autorelabel') }
end

context 'enforcing' do
Expand All @@ -32,20 +33,39 @@
it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-enforcing').with(line: 'SELINUX=enforcing') }
it { is_expected.to contain_exec('change-selinux-status-to-enforcing').with(command: 'setenforce 1') }
it { is_expected.not_to contain_file('/.autorelabel') }
end

context 'permissive' do
let(:params) { { mode: 'permissive' } }
it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-permissive').with(line: 'SELINUX=permissive') }
it { is_expected.to contain_exec('change-selinux-status-to-permissive').with(command: 'setenforce 0') }
it { is_expected.not_to contain_file('/.autorelabel') }
end

context 'disabled' do
let(:params) { { mode: 'disabled' } }
it { is_expected.to contain_file('/usr/share/selinux').with(ensure: 'directory') }
it { is_expected.to contain_file_line('set-selinux-config-to-disabled').with(line: 'SELINUX=disabled') }
it { is_expected.to contain_exec('change-selinux-status-to-disabled').with(command: 'setenforce 0') }
it { is_expected.not_to contain_file('/.autorelabel') }
end

context 'disabled to permissive creates autorelabel trigger file' do
let(:facts) do
facts.merge(selinux_enabled: false)
end
let(:params) { { mode: 'permissive' } }
it { is_expected.to contain_file('/.autorelabel').with(ensure: 'file') }
end

context 'disabled to enforcing creates autorelabel trigger file' do
let(:facts) do
facts.merge(selinux_enabled: false)
end
let(:params) { { mode: 'enforcing' } }
it { is_expected.to contain_file('/.autorelabel').with(ensure: 'file') }
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/default_module_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ operatingsystem: RedHat
operatingsystemmajrelease: '7'
selinux_config_mode: enforcing
selinux_current_mode: enforcing
selinux_enabled: true
selinux_config_policy: targeted
# concat facts
id: 0
Expand Down

0 comments on commit 422cd7f

Please sign in to comment.