Puppet Class: ima::policy

Defined in:
manifests/policy.pp

Overview

Manage IMA Policy

* The term ``watch``, as used here, means both IMA policy fields
  ``dont_measure`` and ``dont_appraise``. Both lines will be dropped for
  each entry here.

Parameters:

  • manage (Boolean) (defaults to: true)

    Manage IMA policy capability. Setting to false will stop IMA policy services on the system.

  • dont_watch_proc (Boolean) (defaults to: true)

    Disable IMA hashing of “procfs“ filesystems

  • dont_watch_sysfs (Boolean) (defaults to: true)

    Disable IMA hashing of “sysfs“ filesystems

  • dont_watch_debugfs (Boolean) (defaults to: true)

    Disable IMA hashing of “debugfs“ filesystems

  • dont_watch_tmpfs (Boolean) (defaults to: true)

    Disable IMA hashing of “tmpfs“ filesystems

  • dont_watch_ramfs (Boolean) (defaults to: true)

    Disable IMA hashing of “ramfs“ filesystems

  • dont_watch_securityfs (Boolean) (defaults to: true)

    Disable IMA hashing of “securityfs“ filesystems

  • dont_watch_devpts (Boolean) (defaults to: true)

    Disable IMA hashing of “/dev/pts“ filesystems

  • dont_watch_binfmtfs (Boolean) (defaults to: true)

    Disable IMA hashing of “binfmtfs“ filesystems

  • dont_watch_selinux (Boolean) (defaults to: true)

    Disable IMA hashing of “selinux_fs“ filesystems

  • dont_watch_nfs (Boolean) (defaults to: true)

    Disable IMA hashing of “nfs“ filesystems

  • dont_watch_cgroup (Boolean) (defaults to: true)

    Disable IMA hashing of “cgroup“ filesystems

  • dont_watch_initrc_var_log_t (Boolean) (defaults to: true)
  • dont_watch_rpm_var_cache_t (Boolean) (defaults to: true)
  • dont_watch_puppet_log_t (Boolean) (defaults to: true)
  • dont_watch_auditd_log_t (Boolean) (defaults to: true)
  • dont_watch_auth_cache_t (Boolean) (defaults to: true)
  • dont_watch_fsadm_log_t (Boolean) (defaults to: true)
  • dont_watch_rsync_log_t (Boolean) (defaults to: true)
  • dont_watch_getty_log_t (Boolean) (defaults to: true)
  • dont_watch_nscd_log_t (Boolean) (defaults to: true)
  • dont_watch_cron_log_t (Boolean) (defaults to: true)
  • dont_watch_lastlog_t (Boolean) (defaults to: true)
  • dont_watch_var_log_t (Boolean) (defaults to: true)
  • dont_watch_wtmp_t (Boolean) (defaults to: true)
  • dont_watch_list (Array[String]) (defaults to: [])

    A list of selinux contexts that shouldn’t be watched, merged with all of the parameters above

  • measure_root_read_files (Boolean) (defaults to: false)

    Monitor all files opened by root

  • measure_file_mmap (Boolean) (defaults to: false)

    Monitor all files mmapped executable in “file_mmap“

  • measure_bprm_check (Boolean) (defaults to: false)

    Monitor all executables in “bprm_check“

  • measure_module_check (Boolean) (defaults to: false)
  • appraise_fowner (Boolean) (defaults to: false)

    Appraises all files **owned by root**

See Also:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'manifests/policy.pp', line 79

class ima::policy (
  Boolean       $manage                      = true,
  Boolean       $dont_watch_proc             = true,
  Boolean       $dont_watch_sysfs            = true,
  Boolean       $dont_watch_debugfs          = true,
  Boolean       $dont_watch_tmpfs            = true,
  Boolean       $dont_watch_ramfs            = true,
  Boolean       $dont_watch_securityfs       = true,
  Boolean       $dont_watch_devpts           = true,
  Boolean       $dont_watch_binfmtfs         = true,
  Boolean       $dont_watch_selinux          = true,
  Boolean       $dont_watch_nfs              = true,
  Boolean       $dont_watch_cgroup           = true,
  Boolean       $dont_watch_initrc_var_log_t = true,
  Boolean       $dont_watch_rpm_var_cache_t  = true,
  Boolean       $dont_watch_puppet_log_t     = true,
  Boolean       $dont_watch_auditd_log_t     = true,
  Boolean       $dont_watch_auth_cache_t     = true,
  Boolean       $dont_watch_fsadm_log_t      = true,
  Boolean       $dont_watch_rsync_log_t      = true,
  Boolean       $dont_watch_getty_log_t      = true,
  Boolean       $dont_watch_nscd_log_t       = true,
  Boolean       $dont_watch_cron_log_t       = true,
  Boolean       $dont_watch_lastlog_t        = true,
  Boolean       $dont_watch_var_log_t        = true,
  Boolean       $dont_watch_wtmp_t           = true,
  Array[String] $dont_watch_list             = [],
  Boolean       $measure_root_read_files     = false,
  Boolean       $measure_file_mmap           = false,
  Boolean       $measure_bprm_check          = false,
  Boolean       $measure_module_check        = false,
  Boolean       $appraise_fowner             = false,
) {

  include '::ima'

  # magic reference is in Kernel documentation Documentation/ABI/testing/ima_policy
  $magic_hash = {
    '0x9fa0'     => $dont_watch_proc,
    '0x62656572' => $dont_watch_sysfs,
    '0x64626720' => $dont_watch_debugfs,
    '0x01021994' => $dont_watch_tmpfs,
    '0x858458f6' => $dont_watch_ramfs,
    '0x73636673' => $dont_watch_securityfs,
    '0x1cd1'     => $dont_watch_devpts,
    '0x42494e4d' => $dont_watch_binfmtfs,
    '0xf97cff8c' => $dont_watch_selinux,
    '0x6969'     => $dont_watch_nfs,
    '0x27e0eb'   => $dont_watch_cgroup,
  }

  $sel_hash = {
    initrc_var_log_t => $dont_watch_initrc_var_log_t,
    rpm_var_cache_t  => $dont_watch_rpm_var_cache_t,
    puppet_log_t     => $dont_watch_puppet_log_t,
    auditd_log_t     => $dont_watch_auditd_log_t,
    auth_cache_t     => $dont_watch_auth_cache_t,
    fsadm_log_t      => $dont_watch_fsadm_log_t,
    rsync_log_t      => $dont_watch_rsync_log_t,
    getty_log_t      => $dont_watch_getty_log_t,
    nscd_log_t       => $dont_watch_nscd_log_t,
    cron_log_t       => $dont_watch_cron_log_t,
    lastlog_t        => $dont_watch_lastlog_t,
    var_log_t        => $dont_watch_var_log_t,
    wtmp_t           => $dont_watch_wtmp_t,
  }

  if $manage {

    file { '/etc/ima':
      ensure => directory,
      mode   => '0750',
    }

    file { '/etc/ima/policy.conf':
      ensure  => file,
      owner   => 'root',
      mode    => '0640',
      content => template("${module_name}/ima_policy.conf.erb"),
      require => File['/etc/ima']
    }

    if member($facts['init_systems'], 'systemd') {
    # Create a hardlink to the custom policy so it is loaded by
    # systemd at startup.
      file { '/usr/lib/systemd/system/import_ima_rules.service':
        ensure => file,
        mode   => '0644',
        source => "puppet:///modules/${module_name}/import_ima_rules.service"
      }
      service { 'import_ima_rules.service':
        ensure  => stopped,
        enable  => true,
        require => File['/usr/lib/systemd/system/import_ima_rules.service']
      }
      exec { 'systemd_load_policy':
        command => 'ln /etc/ima/policy.conf /etc/ima/ima-policy.systemd',
        creates => '/etc/ima/ima-policy.systemd',
        path    => '/sbin:/bin:/usr/sbin:/usr/bin',
        require => File['/etc/ima/policy.conf']
      }
    }
    else {
      file { '/etc/init.d/import_ima_rules':
        ensure => file,
        mode   => '0755',
        source => "puppet:///modules/${module_name}/import_ima_rules"
      }
      service { 'import_ima_rules':
        ensure  => stopped,
        enable  => true,
        require => File['/etc/init.d/import_ima_rules']
      }
    }

    if $facts['cmdline']['ima'] == 'on' {
      exec { 'load_ima_policy':
        command     => 'cat /etc/ima/policy.conf > /sys/kernel/security/ima/policy',
        refreshonly => true,
        path        => '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin',
        subscribe   => File['/etc/ima/policy.conf'],
        require     => Class['ima']
      }
    }
  }
  else {

    if member($facts['init_systems'], 'systemd') {

      file { '/usr/lib/systemd/system/import_ima_rules.service':
        ensure => absent,
      }
      service { 'import_ima_rules.service':
        ensure => stopped,
        enable => false,
      }
    }
    else {
      file { '/etc/init.d/import_ima_rules':
        ensure => absent,
      }
      service { 'import_ima_rules':
        ensure => stopped,
        enable => false,
      }
    }
  }
}