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

Selinux enforcing support for RHEL/Centos #173

merged 1 commit into from Oct 21, 2017

Conversation

ghost
Copy link

@ghost ghost commented Oct 19, 2017

lets have an attribute for enforcing or permissiving SELinuxon RHEL/Centos.
Implementation like suggested in issue: #106

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling bff2370 on AnMoeller:selinux-hardening into d7ea263 on dev-sec:master.

Copy link
Member

@artem-sidorenko artem-sidorenko left a comment

Choose a reason for hiding this comment

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

@AnMoeller good work!:) I've only nitpicks

We could also make a spec tests here to verify/test the exceptions, but I do not think its really required

README.md Outdated
@@ -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)
* `default['os-hardening']['security']['selinux_mode'] = 'unmanaged'`
Copy link
Member

Choose a reason for hiding this comment

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

Could you please remove the default here? We do not mention the precedence level in the docs, as it might differ (e.g. use can use it with override level)

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -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')
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: do something like

include_recipe('os-hardening::selinux') if node['platform_family'] == 'rhel' || node['platform_family'] == 'fedora'

So this recipe would be invoked only on RHEL systems, which are SELinux capable

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

case node['platform_family']
when 'rhel', 'fedora'
unless node['os-hardening']['security']['selinux_mode'] == 'unmanaged'
if node['os-hardening']['security']['selinux_mode'] == 'enforcing'
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion:

unless ...
  semode = case node['os-hardening']['security']['selinux_mode']
                    when 'enforcing'
                      'Enforcing'
                    when 'permissive'
                      'Permissive'
                     else
                       raise "Unsupported selinux mode #{node['os-hardening']['security']['selinux_mode']}"
                    end

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

...
end

Copy link
Author

Choose a reason for hiding this comment

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

tanks for this suggestion. So it is easier to read.


template '/etc/selinux/config' do
source 'rhel_selinuxconfig.erb'
mode 0544
Copy link
Member

Choose a reason for hiding this comment

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

unsure, do we need 0544 here? not 0644 ?

lets have an attribute that allows to set SELinux mode to enforce/
permissive or let it as it is.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 28b54ed on AnMoeller:selinux-hardening into 805471d on dev-sec:master.

@ghost
Copy link
Author

ghost commented Oct 20, 2017

Many thanks for your hints and suggestions. They are implemented.

@artem-sidorenko
Copy link
Member

Full CI test is available here: https://travis-ci.org/artem-forks/chef-os-hardening/builds/290410563

Copy link
Member

@artem-sidorenko artem-sidorenko left a comment

Choose a reason for hiding this comment

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

@AnMoeller many thanks! Looks good to me

@atomic111 any remarks?

@artem-sidorenko
Copy link
Member

artem-sidorenko commented Oct 20, 2017

@atomic111 there is some issue with DO image name (centos 7), I'll fix it in another PR today. Then we probably can rebase this PR

@artem-sidorenko
Copy link
Member

It looks like the issue with centos DO image was already fixed in master, so I'm merging this.

@AnMoeller many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants