Skip to content

Commit fdf15e2

Browse files
authored
Streamline configuring SELinux (#239)
1 parent 9be8adc commit fdf15e2

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ENHANCEMENTS:
1111
* Bump the Ansible `community.general` collection to `4.6.1` and `community.docker` collection to `2.2.1`.
1212
* Add labels to loops in `tasks/config/template-config.yml` to reduce amount of output data.
1313
* Add the `map` and `split_clients` directives into the `http` core template.
14+
* Streamline configuring SELinux.
1415

1516
BUG FIXES:
1617

defaults/main/selinux.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
22
# Set SELinux enforcing for NGINX (Centos/Redhat only) - you may need to open ports on your own
33
nginx_config_selinux: false
4+
45
# Enable enforcing mode if true. Permissive if false (audit only, no enforcing) globally (only works with nginx_config_selinux: true)
56
nginx_config_selinux_enforcing: true
7+
68
# List of TCP ports to add to http_port_t type (80 and 443 have this type already)
79
# nginx_config_selinux_tcp_ports:
810
# - 80
911
# - 443
12+
1013
# List of UDP ports to add to http_port_t type
1114
# nginx_config_selinux_udp_ports:
1215
# - 80

tasks/prerequisites/setup-selinux.yml

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
---
22
- name: (CentOS/RHEL) Install dependencies
3-
block:
4-
- name: (CentOS/RHEL 6/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: (CentOS/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
@@ -25,42 +15,39 @@
2515

2616
- name: Allow SELinux HTTP network connections
2717
ansible.posix.seboolean:
28-
name: httpd_can_network_connect
29-
state: true
30-
persistent: true
31-
32-
- name: Allow SELinux HTTP network connections
33-
ansible.posix.seboolean:
34-
name: httpd_can_network_relay
18+
name: "{{ item }}"
3519
state: true
3620
persistent: true
21+
loop:
22+
- httpd_can_network_connect
23+
- httpd_can_network_relay
3724

3825
- name: Allow SELinux TCP connections on status ports
39-
community.general.selinux:
26+
community.general.seport:
4027
ports: "{{ nginx_config_status_port }}"
4128
proto: tcp
4229
setype: http_port_t
4330
state: present
4431
when: nginx_config_status_port is defined
4532

4633
- name: Allow SELinux TCP connections on Rest API ports
47-
community.general.selinux:
34+
community.general.seport:
4835
ports: "{{ nginx_config_rest_api_port }}"
4936
proto: tcp
5037
setype: http_port_t
5138
state: present
5239
when: nginx_config_rest_api_port is defined
5340

5441
- name: Allow SELinux TCP connections on specific ports
55-
community.general.selinux:
42+
community.general.seport:
5643
ports: "{{ nginx_config_selinux_tcp_ports }}"
5744
proto: tcp
5845
setype: http_port_t
5946
state: present
6047
when: nginx_config_selinux_tcp_ports is defined
6148

6249
- name: Allow SELinux UDP connections on specific ports
63-
community.general.selinux:
50+
community.general.seport:
6451
ports: "{{ nginx_config_selinux_udp_ports }}"
6552
proto: udp
6653
setype: http_port_t

0 commit comments

Comments
 (0)