Skip to content

Commit

Permalink
Streamline configuring SELinux (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
alessfg authored Apr 4, 2022
1 parent e0efc7a commit 2b1aeba
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ FEATURES:

ENHANCEMENTS:

Bump the Ansible `community.general` collection to `4.6.1` and `community.docker` collection to `2.2.1`.
* Bump the Ansible `community.general` collection to `4.6.1` and `community.docker` collection to `2.2.1`.
* Streamline configuring SELinux.

BUG FIXES:

Expand Down
3 changes: 2 additions & 1 deletion defaults/main/selinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
nginx_selinux: false

# Enable enforcing mode if true. Permissive if false (audit only, no enforcing) globally (only works with nginx_selinux: true)

nginx_selinux_enforcing: true

# List of TCP ports to add to http_port_t type (80 and 443 have this type already)
# nginx_selinux_tcp_ports:
# - 80
Expand All @@ -14,5 +14,6 @@ nginx_selinux_enforcing: true
# nginx_selinux_udp_ports:
# - 80
# - 443

# Temporary directory to hold selinux modules
nginx_selinux_tempdir: /tmp
4 changes: 0 additions & 4 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
nginx_version: "{{ version }}"
nginx_service_modify: true
nginx_service_timeout: 95
nginx_selinux: true
nginx_selinux_tcp_ports:
- 80
- 443
nginx_logrotate_conf_enable: true
nginx_logrotate_conf:
paths:
Expand Down
37 changes: 12 additions & 25 deletions tasks/prerequisites/setup-selinux.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
---
- name: (CentOS/RHEL) Install dependencies
block:
- name: (CentOS/RHEL 7) Install dependencies
ansible.builtin.yum:
name:
- policycoreutils-python
- setools
when: ansible_facts['distribution_major_version'] is version('8', '!=')

- name: (RHEL 8) Install dependencies
ansible.builtin.yum:
name:
- libselinux-utils
- policycoreutils
- selinux-policy-targeted
when: ansible_facts['distribution_major_version'] is version('8', '==')
ansible.builtin.yum:
name:
- libselinux-utils
- policycoreutils
- selinux-policy-targeted
when: ansible_facts['os_family'] == "RedHat"

- name: Set SELinux mode to permissive
ansible.builtin.selinux:
ansible.posix.selinux:
state: permissive
policy: targeted

- name: Allow SELinux HTTP network connections
ansible.builtin.seboolean:
name: httpd_can_network_connect
state: true
persistent: true

- name: Allow SELinux HTTP network connections
ansible.builtin.seboolean:
name: httpd_can_network_relay
ansible.posix.seboolean:
name: "{{ item }}"
state: true
persistent: true
loop:
- httpd_can_network_connect
- httpd_can_network_relay

- name: Allow SELinux TCP connections on specific ports
community.general.seport:
Expand Down Expand Up @@ -75,7 +62,7 @@
when: nginx_selinux_module.changed | bool

- name: Set SELinux mode to enforcing
ansible.builtin.selinux:
ansible.posix.selinux:
state: enforcing
policy: targeted
when: nginx_selinux_enforcing | bool
2 changes: 0 additions & 2 deletions templates/selinux/nginx-plus-module.te.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ require {

#============= httpd_t ==============
allow httpd_t http_cache_port_t:tcp_socket name_connect;

allow httpd_t initrc_t:unix_stream_socket connectto;

allow httpd_t usr_t:file { create write };
allow httpd_t usr_t:sock_file write;

0 comments on commit 2b1aeba

Please sign in to comment.