Skip to content

Commit bcc94e7

Browse files
elliotkendallUCSFSean OMeara
authored andcommitted
[COOK-4218] Support setting SELinux boolean values
Signed-off-by: Sean OMeara <someara@opscode.com>
1 parent c486cdb commit bcc94e7

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Node Attributes
1919
The state to set by default, to match the default SELinux state on
2020
RHEL. Can be "enforcing", "permissive", "disabled"
2121

22+
* `node['selinux']['booleans']` - A hash of SELinux boolean names and the
23+
values they should be set to. Values can be off, false, or 0 to disable;
24+
or on, true, or 1 to enable.
25+
2226
Resources/Providers
2327
===================
2428

attributes/default.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
default['selinux']['state'] = 'enforcing'
2+
default['selinux']['booleans'] = {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module SELinuxServiceHelpers
2+
def self.selinux_bool(bool)
3+
if ['on', 'true', '1'].include? bool
4+
'on'
5+
elsif ['off', 'false', '0'].include? bool
6+
'off'
7+
else
8+
Chef::Log.warn "Not a valid boolean value: #{bool}"
9+
nil
10+
end
11+
end
12+
end
13+

recipes/default.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@
2020
action node['selinux']['state'].downcase.to_sym
2121
end
2222

23+
node['selinux']['booleans'].each do |boolean, value|
24+
value = SELinuxServiceHelpers.selinux_bool(value)
25+
unless value.nil?
26+
script "boolean_#{boolean}" do
27+
interpreter "bash"
28+
code "setsebool -P #{boolean} #{value}"
29+
not_if "getsebool #{boolean} |egrep -q \" #{value}\"$"
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)