Module: Chef::Util::Selinux

Includes:
Mixin::ShellOut, Mixin::Which
Included in:
Provider::File
Defined in:
lib/chef/util/selinux.rb

Overview

IMPORTANT: We assume that selinux utilities are installed on an selinux enabled server. Provisioning an selinux enabled server without selinux utilities is not supported.

Constant Summary collapse

@@selinux_enabled =

We want to initialize below variables once during a chef-client run therefore they are class variables.

nil
@@restorecon_path =
nil
@@selinuxenabled_path =
nil

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Method Summary collapse

Methods included from Mixin::Which

#which

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!

Instance Method Details

#restore_security_context(file_path, recursive = false) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/chef/util/selinux.rb', line 49

def restore_security_context(file_path, recursive = false)
  if restorecon_path
    restorecon_command = recursive ? "#{restorecon_path} -R -r" : "#{restorecon_path} -R"
    restorecon_command += " \"#{file_path}\""
    Chef::Log.debug("Restoring selinux security content with #{restorecon_command}")
    shell_out!(restorecon_command)
  else
    Chef::Log.warn "Can not find 'restorecon' on the system. Skipping selinux security context restore."
  end
end

#selinux_enabled?Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/chef/util/selinux.rb', line 44

def selinux_enabled?
  @@selinux_enabled = check_selinux_enabled? if @@selinux_enabled.nil?
  @@selinux_enabled
end