Showing with 92 additions and 2 deletions.
  1. +10 −1 manifests/module.pp
  2. +7 −0 manifests/params.pp
  3. +41 −0 manifests/permissive.pp
  4. +1 −1 metadata.json
  5. +32 −0 spec/defines/selinux_module_spec.rb
  6. +1 −0 spec/spec_helper.rb
11 changes: 10 additions & 1 deletion manifests/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@
cwd => $selinux::params::sx_mod_dir,
}

case $ensure { # lint:ignore:case_without_default
present: {
$_checkloaded_notify = [Exec["${name}-buildmod"]]
}
absent: {
# buildmod doesn't exist in the absent case
$_checkloaded_notify = []
}
}
exec { "${name}-checkloaded":
refreshonly => false,
creates => "/etc/selinux/${selinux_policy}/modules/active/modules/${name}.pp",

command => 'true', # lint:ignore:quoted_booleans
notify => Exec["${name}-buildmod"],
notify => $_checkloaded_notify,
}

## Begin Configuration
Expand Down
7 changes: 7 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
$sx_fs_mount = '/selinux'
$package_name = 'policycoreutils'
}
'': {
# Fallback to lsbmajdistrelease, if puppet version is < 3.0
if($::lsbmajdistrelease == 5) {
$sx_fs_mount = '/selinux'
$package_name = 'policycoreutils'
}
}
default: {
fail("${::operatingsystem}-${::operatingsystemmajrelease} is not supported")
}
Expand Down
41 changes: 41 additions & 0 deletions manifests/permissive.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Definition: selinux::permissive
#
# Description
# This method will set a context to permissive
#
# Class create by David Twersky <dmtwersky@gmail.com>
# Based on selinux::fcontext by Erik M Jacobs<erikmjacobs@gmail.com>
# Adds to puppet-selinux by jfryman
# https://github.com/jfryman/puppet-selinux
# Originally written/sourced from Lance Dillon<>
# http://riffraff169.wordpress.com/2012/03/09/add-file-contexts-with-puppet/
#
# Parameters:
# - $context: A particular context, like "oddjob_mkhomedir_t"
#
# Actions:
# Runs "semanage permissive -a" with the context you wish to allow
#
# Requires:
# - SELinux
# - policycoreutils-python (for el-based systems)
#
# Sample Usage:
#
# selinux::permissive { 'allow-oddjob_mkhomedir_t':
# context => 'oddjob_mkhomedir_t',
# }
#
define selinux::permissive (
$context,
) {

include selinux

exec { "add_${context}":
command => "semanage permissive -a ${context}",
unless => "semanage permissive -l|grep ${context}",
path => '/bin:/sbin:/usr/bin:/usr/sbin',
require => Class['selinux::package']
}
}
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfryman/selinux",
"version": "0.2.5",
"version": "0.2.6",
"author": "jfryman",
"summary": "This class manages SELinux on RHEL based systems",
"license": "Apache-2.0",
Expand Down
32 changes: 32 additions & 0 deletions spec/defines/selinux_module_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe 'selinux::module' do
let(:title) { 'mymodule' }
include_context 'RedHat 7'

context 'present case' do

let(:params) {{
:source => 'test_value'
}}

it { should contain_exec("mymodule-checkloaded").
that_notifies("Exec[mymodule-buildmod]")
}

end # context

context 'absent case' do

let(:params) {{
:source => 'test_value',
:ensure => 'absent'
}}

it { should_not contain_exec("mymodule-checkloaded").
that_notifies("Exec[mymodule-buildmod]")
}

end # context

end # describe
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
:selinux_config_policy => 'targeted',
# concat facts
:concat_basedir => '/tmp',
:id => 0,
Expand Down