Skip to content

Streamline configuring SELinux #504

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

Merged
merged 1 commit into from
Apr 4, 2022
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
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;