All Projects → sous-chefs → selinux_policy

sous-chefs / selinux_policy

Licence: Apache-2.0 license
Development repository for the selinux_policy cookbook

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to selinux policy

confluence
Development repository for the confluence cookbook
Stars: ✭ 42 (+147.06%)
Mutual labels:  chef-cookbook, chef, chef-resource
stunnel
Development repository for the stunnel cookbook
Stars: ✭ 14 (-17.65%)
Mutual labels:  chef-cookbook, chef, chef-resource
sssd ldap
Development repository for the sssd_ldap cookbook
Stars: ✭ 17 (+0%)
Mutual labels:  chef-cookbook, chef, chef-resource
memcached
Development repository for the memcached cookbook
Stars: ✭ 50 (+194.12%)
Mutual labels:  chef-cookbook, chef, chef-resource
transmission
Development repository for the transmission cookbook
Stars: ✭ 14 (-17.65%)
Mutual labels:  chef-cookbook, chef, chef-resource
drbd
Development repository for the drbd cookbook
Stars: ✭ 19 (+11.76%)
Mutual labels:  chef-cookbook, chef, chef-resource
squid
Development repository for the squid cookbook
Stars: ✭ 27 (+58.82%)
Mutual labels:  chef-cookbook, chef, chef-resource
apparmor
Development repository for the apparmor cookbook
Stars: ✭ 13 (-23.53%)
Mutual labels:  chef-cookbook, chef, chef-resource
line
Development repository for the line cookbook
Stars: ✭ 96 (+464.71%)
Mutual labels:  chef-cookbook, chef, chef-resource
github
Development repository for the github cookbook
Stars: ✭ 22 (+29.41%)
Mutual labels:  chef-cookbook, chef, chef-resource
selinux
Development repository for the selinux cookbook
Stars: ✭ 57 (+235.29%)
Mutual labels:  chef-cookbook, chef, chef-resource
kafka
Development repository for the kafka cookbook
Stars: ✭ 87 (+411.76%)
Mutual labels:  chef-cookbook, chef, chef-resource
mac os x
This cookbook has been deprecated
Stars: ✭ 75 (+341.18%)
Mutual labels:  chef-cookbook, chef, chef-resource
firewall
Development repository for the firewall cookbook
Stars: ✭ 97 (+470.59%)
Mutual labels:  chef-cookbook, chef, chef-resource
samba
Development repository for the samba cookbook
Stars: ✭ 30 (+76.47%)
Mutual labels:  chef-cookbook, chef, chef-resource
ossec
Development repository for the ossec cookbook
Stars: ✭ 42 (+147.06%)
Mutual labels:  chef-cookbook, chef, chef-resource
Apt
Development repository for the apt cookbook
Stars: ✭ 201 (+1082.35%)
Mutual labels:  chef-cookbook, chef, chef-resource
Nodejs
Development repository for the nodejs cookbook
Stars: ✭ 225 (+1223.53%)
Mutual labels:  chef-cookbook, chef, chef-resource
yum-epel
Development repository for the yum-epel cookbook
Stars: ✭ 23 (+35.29%)
Mutual labels:  chef-cookbook, chef, chef-resource
freebsd
Development repository for the freebsd cookbook
Stars: ✭ 27 (+58.82%)
Mutual labels:  chef-cookbook, chef, chef-resource

selinux_policy Cookbook

Cookbook Version License

This cookbook can be used to manage SELinux policies and components (rather than just enable / disable enforcing). I made it because I needed some SELinux settings done, and the executes started to look annoying.

Requirements

Needs an SELinux policy active (so its values can be managed). Can work with a disabled SELinux system (see attribute allow_disabled), which will generate warnings and do nothing (but won't break the run). Also requires SELinux's management tools, namely semanage, setsebool and getsebool. Tools are installed by the selinux_policy::install recipe (for RHEL/Debian and the like).

Chef Infra Client

  • 13 or later

Platforms

  • rhel
  • fedora

Attributes

These attributes affect the way all of the resource behave.

  • node['selinux_policy']['allow_disabled'] - Whether to allow runs when SELinux is disabled. Will generate warnings, but the run won't fail. Defaults to true, set to false if you don't have any machines with disabled SELinux.

Usage

  • selinux_policy::install - Installs SELinux policy management tools

This cookbook's functionality is exposed via resources, so it should be called from a wrapper cookbook. Remember to add depends 'selinux_policy' to your metadata.rb.

boolean

Represents an SELinux boolean. You can either set it, meaning it will be changed without persistence (it will revert to default in the next reboot), or setpersist it (default action), so it'll keep it value after rebooting. Using setpersist requires an active policy (so that the new value can be saved somewhere).

Properties:

  • name: boolean's name. Defaults to resource name.
  • value: Its new value (true/false).
  • force: Use setsebool even if the current value agrees with the requested one.

Example usage:

include_recipe 'selinux_policy::install'

selinux_policy_boolean 'httpd_can_network_connect' do
    value true
    # Make sure nginx is started if this value was modified
    notifies :start,'service[nginx]', :immediate
end

Note: Due to ruby interperting 0 as true, using value 0 is unwise.

port

Allows assigning a network port to a certain SELinux context. As explained here, it can be useful for running Apache on a non-standard port.

Actions:

  • addormodify (default): Assigns the port to the right context, whether it's already listed another context or not at all.
  • add: Assigns the port to the right context it's if not listed (only uses -a).
  • modify: Changes the port's context if it's already listed (only uses -m).
  • delete: Removes the port's context if it's listed (uses -d).

Properties:

  • port: The port in question, defaults to resource name.
  • protocol: tcp/udp.
  • secontext: The SELinux context to assign the port to. Unnecessary when using delete.

Example usage:

include_recipe 'selinux_policy::install'

# Allow nginx to bind to port 5678, by giving it the http_port_t context
selinux_policy_port '5678' do
    protocol 'tcp'
    secontext 'http_port_t'
end

module

Manages SEModules

Actions:

  • fetch: Prepares the module's files for compilation. Allow remote_directory-like behavior
  • compile: Translates a module source directory into a NAME.pp file. Uses make logic for idempotence.
  • install: Adds a compiled module (pp) to the current policy. Only installs if the module was modified this run, force is enabled or it's missing from the current policy. Note: I wish I could compare the existing module to the one generated, but the extract capability was only added in Aug 15. I'll be happy to see a better idea.
  • deploy (default): Runs fetch, compile, install in that order.
  • remove: Removes a module.

Properties:

  • name: The module name. Defaults to resource name.
  • directory: Directory where module is stored. Defaults to a directory inside the Chef cache.
  • content: The module content, can be extracted from audit2allow -m NAME. This can be used to create simple modules without using external files.
  • directory_source: Copies files cookbook to the module directory (uses remote_directory). Allows keeping all of the module's source files in the cookbook. Note: You can pre-create the module directory and populate it in any other way you'd choose.
  • cookbook: Modifies the source cookbook for the remote_directory.
  • force: Installs the module even if it seems fine. Ruins idempotence but should help solve some weird cases.

Example usage:

include_recipe 'selinux_policy::install'

# Allow openvpn to write/delete in '/etc/openvpn'
selinux_policy_module 'openvpn-googleauthenticator' do
  content <<-eos
    module dy-openvpn-googleauthenticator 1.0;

    require {
        type openvpn_t;
        type openvpn_etc_t;
        class file { write unlink };
    }


    #============= openvpn_t ==============
    allow openvpn_t openvpn_etc_t:file { write unlink };
  eos
  action :deploy
end

fcontext

Allows managing the SELinux context of files. This can be used to grant SELinux-protected daemons access to additional / moved files.

Actions:

  • addormodify (default): Assigns the file regexp to the right context, whether it's already listed another context or not at all.
  • add: Assigns the file regexp to the right context it's if not listed (only uses -a).
  • modify: Changes the file regexp context if it's already listed (only uses -m).
  • delete: Removes the file regexp context if it's listed (uses -d).

Properties:

  • file_spec: This is the file regexp in question, defaults to resource name.
  • secontext: The SELinux context to assign the file regexp to. Not required for :delete
  • file_type: Restrict the fcontext to specific file types. See the table below for an overview. See also https://en.wikipedia.org/wiki/Unix_file_types for more info
  • a All files
  • f Regular files
  • d Directory
  • c Character device
  • b Block device
  • s Socket
  • l Symbolic link
  • p Namedpipe

Example usage (see mysql cookbook for example daemons ):

include_recipe 'selinux_policy::install'

# Allow http servers (nginx/apache) to modify moodle files
selinux_policy_fcontext '/var/www/moodle(/.*)?' do
  secontext 'httpd_sys_rw_content_t'
end

# Allow a custom mysql daemon to access its files.
{'mysqld_etc_t' => "/etc/mysql-#{service_name}(/.*)?",
'mysqld_etc_t' => "/etc/mysql-#{service_name}/my\.cnf",
'mysqld_log_t' => "/var/log/mysql-#{service_name}(/.*)?",
'mysqld_db_t' => "/opt/mysql_data_#{service_name}(/.*)?",
'mysqld_var_run_t' => "/var/run/mysql-#{service_name}(/.*)?",
'mysqld_initrc_exec_t' => "/etc/rc\.d/init\.d/mysql-#{service_name}"}.each do |sc, f|
  selinux_policy_fcontext f do
    secontext sc
  end
end

# Adapt a symbolic link
selinux_policy_fcontext '/var/www/symlink_to_webroot' do
  secontext 'httpd_sys_rw_content_t'
  filetype 'l'
end

permissive

Allows some types to misbehave without stopping them. Not as good as specific policies, but better than disabling SELinux entirely.

Actions:

  • add: Adds a permissive, unless it's already added
  • delete: Deletes a permissive if it's listed

Example usage:

include_recipe 'selinux_policy::install'

# Disable enforcement on Nginx
# As described on http://nginx.com/blog/nginx-se-linux-changes-upgrading-rhel-6-6/

selinux_policy_permissive 'nginx' do
  notifies :restart, 'service[nginx]'
end

Original Author

Nitzan Raz (backslasher)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].