Puppet Class: selinux::config

Defined in:
manifests/config.pp

Overview

Class: selinux::config

THIS IS A PRIVATE CLASS

This class is designed to configure the system to use SELinux on the system.

It is included in the main class ::selinux

Parameters:

  • mode (Any) (defaults to: $::selinux::mode)

    See main class

  • type (Any) (defaults to: $::selinux::type)

    See main class

  • manage_package (Any) (defaults to: $::selinux::manage_package)

    See main class

  • package_name (Any) (defaults to: $::selinux::package_name)

    See main class

  • sx_mod_dir (Any) (defaults to: $::selinux::sx_mod_dir)

    See main class



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'manifests/config.pp', line 16

class selinux::config (
  $mode           = $::selinux::mode,
  $type           = $::selinux::type,
  $sx_mod_dir     = $::selinux::sx_mod_dir,
  $manage_package = $::selinux::manage_package,
  $package_name   = $::selinux::package_name,
) {

  if $caller_module_name != $module_name {
    fail("Use of private class ${name} by ${caller_module_name}")
  }

  file { $sx_mod_dir:
    ensure => directory,
    owner  => 'root',
    group  => 'root',
  }

  if $mode {
    file_line { "set-selinux-config-to-${mode}":
      path  => '/etc/selinux/config',
      line  => "SELINUX=${mode}",
      match => '^SELINUX=\w+',
    }

    case $mode {
      'permissive', 'disabled': {
        $sestatus = '0'
        if $mode == 'disabled' and defined('$::selinux_current_mode') and $::selinux_current_mode == 'permissive' {
          notice('A reboot is required to fully disable SELinux. SELinux will operate in Permissive mode until a reboot')
        }
      }
      'enforcing': {
        $sestatus = '1'
      }
      default : {
        fail('You must specify a mode (enforced, permissive, or disabled) for selinux operation')
      }
    }

    # 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 {
      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'",
      path    => '/bin:/sbin:/usr/bin:/usr/sbin',
    }
  }

  if $type {
    file_line { "set-selinux-config-type-to-${type}":
      path  => '/etc/selinux/config',
      line  => "SELINUXTYPE=${type}",
      match => '^SELINUXTYPE=\w+',
    }
  }
}