Skip to content

Instantly share code, notes, and snippets.

@jfryman
Created August 17, 2011 17:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfryman/1152021 to your computer and use it in GitHub Desktop.
Save jfryman/1152021 to your computer and use it in GitHub Desktop.
## Concepts incorporated from:
## http://stuckinadoloop.wordpress.com/2011/06/15/puppet-managed-deployment-of-selinux-modules/
define selinux::module(
$ensure = 'present',
$mod_dir = '/usr/share/selinux',
$source
) {
# Set Resource Defaults
File {
owner => 'root',
group => 'root',
mode => '0644',
}
# Only allow refresh in the event that the initial .te file is updated.
Exec {
path => '/sbin:/usr/sbin:/bin:/usr/bin',
resfreshonly => 'true',
cwd => "${mod_dir}",
}
## Begin Configuration
file { $mod_dir:
ensure => directory,
}
file { "${mod_dir}/${name}.te":
ensure => $ensure,
source => $source,
tag => 'selinux-module',
}
file { "${mod_dir}/${name}.mod":
tag => ['selinux-module-build', 'selinux-module'],
}
file { "${mod_dir}/${name}.pp":
tag => ['selinux-module-build', 'selinux-module'],
}
# Specific executables based on present or absent.
case $ensure {
present: {
exec { "${name}-buildmod":
command => "checkmodule -M -m -o ${name}.mod ${name}.te",
notify => Exec["${name}-buildpp"],
}
exec { "${name}-buildpp":
command => "semodule_package -m ${name}.mod -o ${name}.pp",
notify => Exec["${name}-install"],
}
exec { "${name}-install":
command => 'semodule -i ${name}.pp',
}
# Set dependency ordering
File["${mod_dir}/${name}.te"]
~> Exec["${name}-buildmod"]
~> Exec["${name}-buildpp"]
~> Exec["${name}-install"]
-> File<| tag == 'selinux-module-build' |>
}
absent: {
exec { "${name}-remove":
command => "semodule -r ${name}.pp > /dev/null 2>&1",
}
# Set dependency ordering
Exec["${name}-remove"]
-> File<| tag == 'selinux-module' |>
}
default: {
fail("Invalid status for SELinux Module: ${ensure}")
}
}
}
## Concepts incorporated from:
## http://stuckinadoloop.wordpress.com/2011/06/15/puppet-managed-deployment-of-selinux-modules/
define selinux::module(
$ensure = 'present',
$mod_dir = '/usr/share/selinux',
$source
) {
# Set Resource Defaults
File {
owner => 'root',
group => 'root',
mode => '0644',
}
# Only allow refresh in the event that the initial .te file is updated.
Exec {
path => '/sbin:/usr/sbin:/bin:/usr/bin',
resfreshonly => 'true',
cwd => "${mod_dir}",
}
## Begin Configuration
file { $mod_dir:
ensure => directory,
}
file { "${mod_dir}/${name}.te":
ensure => $ensure,
source => $source,
tag => 'selinux-module',
}
file { "${mod_dir}/${name}.mod":
tag => ['selinux-module-build', 'selinux-module'],
}
file { "${mod_dir}/${name}.pp":
tag => ['selinux-module-build', 'selinux-module'],
}
# Specific executables based on present or absent.
case $ensure {
present: {
exec { "${name}-buildmod":
command => "checkmodule -M -m -o ${name}.mod ${name}.te",
notify => Exec["${name}-buildpp"],
}
exec { "${name}-buildpp":
command => "semodule_package -m ${name}.mod -o ${name}.pp",
notify => Exec["${name}-install"],
}
exec { "${name}-install":
command => 'semodule -i ${name}.pp',
}
# Set dependency ordering
File["${mod_dir}/${name}.te"]
~> Exec["${name}-buildmod"]
~> Exec["${name}-buildpp"]
~> Exec["${name}-install"]
-> File<| tag == 'selinux-module-build' |>
}
absent: {
exec { "${name}-remove":
command => "semodule -r ${name}.pp > /dev/null 2>&1",
}
# Set dependency ordering
Exec["${name}-remove"]
-> File<| tag == 'selinux-module' |>
}
default: {
fail("Invalid status for SELinux Module: ${ensure}")
}
}
}
@djjudas21
Copy link

At the risk of sounding stupid, how do I actually use this code? I've placed both of these files in /etc/puppet/modules/selinux/lib/ and they get synced to clients, but puppet throws a vast number of errors on each run.

@jfryman
Copy link
Author

jfryman commented Jan 5, 2012 via email

@djjudas21
Copy link

djjudas21 commented Jan 5, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment