Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selinux enforcing support for RHEL/Centos #173

Merged
merged 1 commit into from Oct 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ suites:
- path: test/integration/default
attributes:
kernel_modules_disabled: 1
- name: selinux_enabled
run_list:
- recipe[os-hardening::default]
includes:
- centos-7.3
attributes:
os-hardening:
security:
selinux_mode: enforcing
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ It will not:
* ypserv ([NSA](http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf), Chapter 3.2.4)
* telnet-server ([NSA](http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf), Chapter 3.2.2)
* rsh-server ([NSA](http://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf), Chapter 3.2.3)
* `['os-hardening']['security']['selinux_mode'] = 'unmanaged'`
set to `unmanaged` if you want to let selinux configuration as it is. Set to `enforcing` to enforce or `permissive` to permissive SELinux.

## Usage

Expand Down
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
'rsh-server'
]

# SELinux enforcing (enforcing, permissive, unmanaged)
default['os-hardening']['security']['selinux_mode'] = 'unmanaged'

# SYSTEM CONFIGURATION
# ====================
# These are not meant to be modified by the user
Expand Down
1 change: 1 addition & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
include_recipe('os-hardening::suid_sgid') if node['os-hardening']['security']['suid_sgid']['enforce']
include_recipe('os-hardening::sysctl')
include_recipe('os-hardening::auditd')
include_recipe('os-hardening::selinux') if node['platform_family'] == 'rhel' || node['platform_family'] == 'fedora'
51 changes: 51 additions & 0 deletions recipes/selinux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# encoding: utf-8

#
# Cookbook Name: os-hardening
# Recipe: selinux.rv
#
# Copyright 2017, Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# SELinux enforcing support

case node['platform_family']
when 'rhel', 'fedora'
unless node['os-hardening']['security']['selinux_mode'] == 'unmanaged'
semode = case node['os-hardening']['security']['selinux_mode']
when 'enforcing'
'Enforcing'
when 'permissive'
'Permissive'
else
raise "Unsupported selinuxmode #{node['os-hardening']['security']['selinux_mode']}"
end

execute "Set selinux mode to #{semode}" do
command "setenforce #{semode}"
not_if "getenforce | grep -F #{semode}"
end

template '/etc/selinux/config' do
source 'rhel_selinuxconfig.erb'
mode 0644
owner 'root'
group 'root'
variables selinux_mode: node['os-hardening']['security']['selinux_mode']
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: add an else condition to raise an exception on unsupported systems, e.g.

case node['platform_family']
when 'rhel', 'fedora'
  ...
else
  raise "Selinux recipe is not supported on the platform family #{node['platform_family']}"
end

else
raise "Selinux recipe is not supported on the platform family #{node['platform_family']}"
end
15 changes: 15 additions & 0 deletions templates/default/rhel_selinuxconfig.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% node['config_disclaimer'].to_s.split("\n").each do |l| %>
# <%= l %>
<% end %>

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=<%= @selinux_mode %>
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
1 change: 1 addition & 0 deletions test/integration/default/inspec.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: os-hardening-integration-tests
version: 1.0.0
depends:
- name: linux-baseline
url: https://github.com/dev-sec/linux-baseline
16 changes: 16 additions & 0 deletions test/integration/selinux_enabled/controls/tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include_controls 'os-hardening-integration-tests'

control 'SELinux-01' do
impact 1.0
title 'Verify SELinux enforcing'
desc 'Verify SELinux enforcing'

describe file('/etc/selinux/config') do
its('content') { should include 'SELINUX=enforcing' }
end

describe command('getenforce') do
its('stdout') { should eq "Enforcing\n" }
its('stderr') { should eq '' }
end
end
5 changes: 5 additions & 0 deletions test/integration/selinux_enabled/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: os-hardening-integration-tests-selinux
version: 1.0.0
depends:
- name: os-hardening-integration-tests
path: test/integration/default