Skip to content

Commit 2b1aeba

Browse files
authored
Streamline configuring SELinux (#504)
1 parent e0efc7a commit 2b1aeba

File tree

5 files changed

+16
-33
lines changed

5 files changed

+16
-33
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ FEATURES:
99

1010
ENHANCEMENTS:
1111

12-
Bump the Ansible `community.general` collection to `4.6.1` and `community.docker` collection to `2.2.1`.
12+
* Bump the Ansible `community.general` collection to `4.6.1` and `community.docker` collection to `2.2.1`.
13+
* Streamline configuring SELinux.
1314

1415
BUG FIXES:
1516

defaults/main/selinux.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
nginx_selinux: false
44

55
# Enable enforcing mode if true. Permissive if false (audit only, no enforcing) globally (only works with nginx_selinux: true)
6-
76
nginx_selinux_enforcing: true
7+
88
# List of TCP ports to add to http_port_t type (80 and 443 have this type already)
99
# nginx_selinux_tcp_ports:
1010
# - 80
@@ -14,5 +14,6 @@ nginx_selinux_enforcing: true
1414
# nginx_selinux_udp_ports:
1515
# - 80
1616
# - 443
17+
1718
# Temporary directory to hold selinux modules
1819
nginx_selinux_tempdir: /tmp

molecule/default/converge.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
nginx_version: "{{ version }}"
2323
nginx_service_modify: true
2424
nginx_service_timeout: 95
25-
nginx_selinux: true
26-
nginx_selinux_tcp_ports:
27-
- 80
28-
- 443
2925
nginx_logrotate_conf_enable: true
3026
nginx_logrotate_conf:
3127
paths:

tasks/prerequisites/setup-selinux.yml

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
---
22
- name: (CentOS/RHEL) Install dependencies
3-
block:
4-
- name: (CentOS/RHEL 7) Install dependencies
5-
ansible.builtin.yum:
6-
name:
7-
- policycoreutils-python
8-
- setools
9-
when: ansible_facts['distribution_major_version'] is version('8', '!=')
10-
11-
- name: (RHEL 8) Install dependencies
12-
ansible.builtin.yum:
13-
name:
14-
- libselinux-utils
15-
- policycoreutils
16-
- selinux-policy-targeted
17-
when: ansible_facts['distribution_major_version'] is version('8', '==')
3+
ansible.builtin.yum:
4+
name:
5+
- libselinux-utils
6+
- policycoreutils
7+
- selinux-policy-targeted
188
when: ansible_facts['os_family'] == "RedHat"
199

2010
- name: Set SELinux mode to permissive
21-
ansible.builtin.selinux:
11+
ansible.posix.selinux:
2212
state: permissive
2313
policy: targeted
2414

2515
- name: Allow SELinux HTTP network connections
26-
ansible.builtin.seboolean:
27-
name: httpd_can_network_connect
28-
state: true
29-
persistent: true
30-
31-
- name: Allow SELinux HTTP network connections
32-
ansible.builtin.seboolean:
33-
name: httpd_can_network_relay
16+
ansible.posix.seboolean:
17+
name: "{{ item }}"
3418
state: true
3519
persistent: true
20+
loop:
21+
- httpd_can_network_connect
22+
- httpd_can_network_relay
3623

3724
- name: Allow SELinux TCP connections on specific ports
3825
community.general.seport:
@@ -75,7 +62,7 @@
7562
when: nginx_selinux_module.changed | bool
7663

7764
- name: Set SELinux mode to enforcing
78-
ansible.builtin.selinux:
65+
ansible.posix.selinux:
7966
state: enforcing
8067
policy: targeted
8168
when: nginx_selinux_enforcing | bool

templates/selinux/nginx-plus-module.te.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ require {
1313

1414
#============= httpd_t ==============
1515
allow httpd_t http_cache_port_t:tcp_socket name_connect;
16-
1716
allow httpd_t initrc_t:unix_stream_socket connectto;
18-
1917
allow httpd_t usr_t:file { create write };
2018
allow httpd_t usr_t:sock_file write;

0 commit comments

Comments
 (0)