16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,21 @@ matrix:
env: PUPPET_GEM_VERSION="~> 3.6.0" STRICT_VARIABLES="yes"
- rvm: 2.1.0
env: PUPPET_GEM_VERSION="~> 3.7.0" STRICT_VARIABLES="yes"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 4.0.0"
- rvm: 2.0
env: PUPPET_GEM_VERSION="~> 4.0.0"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 4.0.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 4.0.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 4.1.0"
- rvm: 2.0
env: PUPPET_GEM_VERSION="~> 4.1.0"
- rvm: 2.1
env: PUPPET_GEM_VERSION="~> 4.1.0"
- rvm: 2.2
env: PUPPET_GEM_VERSION="~> 4.1.0"
notifications:
email: false
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :unit_tests do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false, :git => 'https://github.com/rodjek/rspec-puppet.git', :tag => 'v2.0.0'
# https://github.com/rspec/rspec-core/issues/1864
gem 'rspec', '< 3.2.0', {"platforms"=>["ruby_18"]}
gem 'rspec-puppet', '~> 2.1', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', '1.0.1', :require => false
gem 'puppet-lint', '~> 1.0', :require => false
gem 'puppet-syntax', :require => false
gem 'metadata-json-lint', :require => false
gem 'json', :require => false
Expand Down
12 changes: 12 additions & 0 deletions lib/facter/selinux_custom_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# As a workaround for Facter bug with EL7:
# https://tickets.puppetlabs.com/browse/FACT-756
#

require 'facter'

Facter.add(:selinux_custom_policy) do
confine :kernel => 'Linux', :osfamily => 'RedHat', :operatingsystemmajrelease => '7', :selinux => ['true', true]
setcode do
Facter::Util::Resolution.exec("sestatus | grep 'Loaded policy name' | awk '{ print \$4 }'")
end
end
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
case $mode {
permissive, disabled: {
$sestatus = '0'
if $mode == 'disabled' and $::selinux_current_mode == 'permissive' {
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')
}
}
Expand Down
26 changes: 18 additions & 8 deletions manifests/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@

include selinux

if $::selinux_config_policy in ['targeted','strict']
{
$selinux_policy = $::selinux_config_policy
}
elsif $::selinux_custom_policy
{
$selinux_policy = $::selinux_custom_policy
}

# Set Resource Defaults
File {
owner => 'root',
Expand All @@ -51,32 +60,33 @@

exec { "${name}-checkloaded":
refreshonly => false,
creates => "/etc/selinux/${::selinux_config_policy}/modules/active/modules/${name}.pp",
command => 'true',
creates => "/etc/selinux/${selinux_policy}/modules/active/modules/${name}.pp",

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

## Begin Configuration
file { "${::selinux::params::sx_mod_dir}/${name}.te":
ensure => $ensure,
source => $source,
tag => 'selinux-module',
tag => "selinux-module-${name}",
}
if !$use_makefile {
file { "${::selinux::params::sx_mod_dir}/${name}.mod":
tag => ['selinux-module-build', 'selinux-module'],
tag => ["selinux-module-build-${name}", "selinux-module-${name}"],
}
}
file { "${::selinux::params::sx_mod_dir}/${name}.pp":
tag => ['selinux-module-build', 'selinux-module'],
tag => ["selinux-module-build-${name}", "selinux-module-${name}"],
}

# Specific executables based on present or absent.
case $ensure {
present: {
if $use_makefile {
exec { "${name}-buildmod":
command => "true",
command => 'true', # lint:ignore:quoted_booleans
}
exec { "${name}-buildpp":
command => "make -f ${makefile} ${name}.pp",
Expand All @@ -98,7 +108,7 @@
~> Exec["${name}-buildmod"]
~> Exec["${name}-buildpp"]
~> Exec["${name}-install"]
-> File<| tag == 'selinux-module-build' |>
-> File<| tag == "selinux-module-build-${name}" |>
}
absent: {
exec { "${name}-remove":
Expand All @@ -107,7 +117,7 @@

# Set dependency ordering
Exec["${name}-remove"]
-> File<| tag == 'selinux-module' |>
-> File<| tag == "selinux-module-${name}" |>
}
default: {
fail("Invalid status for SELinux Module: ${ensure}")
Expand Down
30 changes: 19 additions & 11 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@

case $::osfamily {
'RedHat': {
case $::operatingsystemmajrelease {
'7': {
case $::operatingsystem {
'Fedora': {
$sx_fs_mount = '/sys/fs/selinux'
$package_name = 'policycoreutils-python'
}
'6': {
$sx_fs_mount = '/selinux'
$package_name = 'policycoreutils-python'
}
'5': {
$sx_fs_mount = '/selinux'
$package_name = 'policycoreutils'
}
default: {
fail("${::osfamily}-${::operatingsystemmajrelease} is not supported")
case $::operatingsystemmajrelease {
'7': {
$sx_fs_mount = '/sys/fs/selinux'
$package_name = 'policycoreutils-python'
}
'6': {
$sx_fs_mount = '/selinux'
$package_name = 'policycoreutils-python'
}
'5': {
$sx_fs_mount = '/selinux'
$package_name = 'policycoreutils'
}
default: {
fail("${::operatingsystem}-${::operatingsystemmajrelease} is not supported")
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/port.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

exec { "add_${context}_${port}":
command => "semanage port -a -t ${context} ${protocol_switch}${port}",
unless => "semanage port -l|grep \"^${context}.*${protocol}.*${port}\"",
unless => "semanage port -l|grep \"^${context}.*${protocol}.*${port}\"|grep -w ${port}",
path => '/bin:/sbin:/usr/bin:/usr/sbin',
require => Class['selinux::package']
}
Expand Down
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.3",
"version": "0.2.5",
"author": "jfryman",
"summary": "This class manages SELinux on RHEL based systems",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/selinux_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'selinux' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystemmajrelease => '7', :selinux_current_mode => 'enforcing' } }
include_context 'RedHat 7'

context 'config' do

Expand Down
23 changes: 21 additions & 2 deletions spec/classes/selinux_package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,38 @@
context 'package' do

context 'on RedHat 5 based OSes' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystemmajrelease => '5', :selinux_current_mode => 'enforcing' } }
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => '5',
:selinux_current_mode => 'enforcing',
}
end

it { should contain_package('policycoreutils').with(:ensure => 'installed') }
end

[ '6', '7' ].each do |majrelease|
context "On RedHat #{majrelease} based OSes" do
let(:facts) { { :osfamily => 'RedHat', :operatingsystemmajrelease => majrelease, :selinux_current_mode => 'enforcing' } }
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemmajrelease => majrelease,
:selinux_current_mode => 'enforcing',
}
end

it { should contain_package('policycoreutils-python').with(:ensure => 'installed') }
end
end

context "On Fedora 22 based OSes" do
include_context 'Fedora 22'

it { should contain_package('policycoreutils-python').with(:ensure => 'installed') }
end

end

Expand Down
11 changes: 1 addition & 10 deletions spec/classes/selinux_restorecond_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
require 'spec_helper'

describe 'selinux::restorecond' do
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
# concat facts
:concat_basedir => '/tmp',
:id => 0,
:is_pe => false,
:path => '/tmp',
} }
include_context 'RedHat 7'

it { should contain_concat('/etc/selinux/restorecond.conf') }
it { should contain_concat__fragment('restorecond_config_default') }
Expand Down
11 changes: 1 addition & 10 deletions spec/classes/selinux_restorecond_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
require 'spec_helper'

describe 'selinux::restorecond' do
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
# concat facts
:concat_basedir => '/tmp',
:id => 0,
:is_pe => false,
:path => '/tmp',
} }
include_context 'RedHat 7'

it { should contain_service('restorecond') }

Expand Down
11 changes: 1 addition & 10 deletions spec/classes/selinux_restorecond_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
require 'spec_helper'

describe 'selinux::restorecond' do
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
# concat facts
:concat_basedir => '/tmp',
:id => 0,
:is_pe => false,
:path => '/tmp',
} }
include_context 'RedHat 7'

it { should contain_class('selinux::restorecond::config') }
it { should contain_class('selinux::restorecond::service') }
Expand Down
15 changes: 11 additions & 4 deletions spec/classes/selinux_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
require 'spec_helper'

describe 'selinux' do
let(:facts) { { :osfamily => 'RedHat', :operatingsystemmajrelease => '7', :selinux_current_mode => 'enforcing' } }

it { should contain_class('selinux::package') }
it { should contain_class('selinux::config') }
[
'RedHat 7',
'CentOS 7',
'Fedora 22',
].each do |ctx|
context ctx do
include_context ctx

it { should contain_class('selinux::package') }
it { should contain_class('selinux::config') }
end
end
end
6 changes: 1 addition & 5 deletions spec/defines/selinux_boolean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

describe 'selinux::boolean' do
let(:title) { 'mybool' }
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
} }
include_context 'RedHat 7'

context 'default' do
it { should contain_exec("setsebool -P 'mybool' true")}
Expand Down
6 changes: 1 addition & 5 deletions spec/defines/selinux_fcontext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

describe 'selinux::fcontext' do
let(:title) { 'myfile' }
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
} }
include_context 'RedHat 7'

context 'invalid pathname' do
it { expect { is_expected.to compile }.to raise_error }
Expand Down
6 changes: 1 addition & 5 deletions spec/defines/selinux_port_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

describe 'selinux::port' do
let(:title) { 'myapp' }
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
} }
include_context 'RedHat 7'

['tcp', 'udp', 'tcp6', 'udp6'].each do |protocol|
context "valid protocol #{protocol}" do
Expand Down
11 changes: 1 addition & 10 deletions spec/defines/selinux_restorecond_fragment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@
describe 'selinux::restorecond::fragment' do
let(:pre_condition) { 'class { "selinux::restorecond": }' }
let(:title) { 'cond' }
let(:facts) { {
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:selinux_current_mode => 'enforcing',
# concat facts
:concat_basedir => '/tmp',
:id => 0,
:is_pe => false,
:path => '/tmp',
} }
include_context 'RedHat 7'

context 'source' do
let(:params) { { :source => 'puppet:///data/cond.txt' } }
Expand Down
Loading