Skip to content

Commit df73af5

Browse files
authored
Merge pull request #5 from magicalyak/selinux
Selinux Enable
2 parents 318dfc2 + bbf0bce commit df73af5

File tree

4 files changed

+148
-9
lines changed

4 files changed

+148
-9
lines changed

.gitignore

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
.vscode/settings.json
1+
# OSX leaves these everywhere on SMB shares
2+
._*
3+
4+
# OSX trash
5+
.DS_Store
6+
7+
# Eclipse files
8+
.classpath
9+
.project
10+
.settings/**
11+
12+
# Emacs save files
13+
*~
14+
\#*\#
15+
.\#*
16+
17+
# Vim-related files
18+
[._]*.s[a-w][a-z]
19+
[._]s[a-w][a-z]
20+
*.un~
21+
Session.vim
22+
.netrwhist
23+
24+
# NGINX Plus license files
25+
*.crt
26+
*.key
27+
28+
# Visual Studio Code settings
29+
.vscode
30+
31+
# Default certificate and key
32+
default.pem
33+
34+
# IntelliJ IDEA
35+
.idea
36+
37+
# Scratch Directory
38+
scratch/

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ log_policy_syslog_target: 127.0.0.1:514
8484

8585
nginx_demo_workload_protocol: http://
8686
nginx_demo_workload_host: 10.1.1.1:8080
87+
88+
# Enable enforcing selinux (you may need to open ports on your own)
89+
nginx_selinux: false

tasks/prerequisites/setup-centos.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
name: ca-certificates, epel-release
55
state: present
66

7-
# TODO: make this surgical rather than disabling SELinux globally
8-
- name: Disable SELinux
9-
selinux:
10-
state: disabled
11-
when:
12-
- ansible_selinux is defined
13-
- ansible_selinux != false
14-
- ansible_selinux.status == 'enabled'
7+
- name: "(Install: CentOS) Setup SELinux"
8+
import_tasks: setup-selinux.yml
9+
when: nginx_selinux

tasks/prerequisites/setup-selinux.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
- name: "(Install: SELinux) Install Required CentOS Dependencies"
3+
package:
4+
name: policycoreutils-python, setools
5+
state: present
6+
7+
- name: "(Install: SELinux) Permissive SELinux"
8+
selinux:
9+
state: permissive
10+
policy: targeted
11+
when: nginx_selinux
12+
13+
- name: "(Install: SELinux: Booleans) Allow HTTP network connection"
14+
seboolean:
15+
name: httpd_can_network_connect
16+
state: yes
17+
persistent: yes
18+
19+
- name: "(Install: SELinux: Booleans) Allow HTTP relay connection"
20+
seboolean:
21+
name: httpd_can_network_relay
22+
state: yes
23+
persistent: yes
24+
25+
- name: "(Install: SELinux: Booleans) Allow HTTP mod auth pam"
26+
seboolean:
27+
name: httpd_mod_auth_pam
28+
state: yes
29+
persistent: yes
30+
31+
- name: "(Install: SELinux: Booleans) enable NIS"
32+
seboolean:
33+
name: nis_enabled
34+
state: yes
35+
persistent: yes
36+
37+
- name: "(Install: SELinux: Contexts) App Protect Logs"
38+
sefcontext:
39+
target: '/var/log/app_protect(/.*)?'
40+
setype: httpd_log_t
41+
state: present
42+
43+
- name: "(Install: SELinux: Contexts) App Protect Opt"
44+
sefcontext:
45+
target: '/opt/app_protect(/.*)?'
46+
setype: httpd_var_run_t
47+
state: present
48+
49+
- name: "(Install: SELinux: Contexts) App Protect Pipe"
50+
sefcontext:
51+
target: '/opt/app_protect/pipe(/.*)?'
52+
setype: httpd_initrc_exec_t
53+
state: present
54+
55+
- name: "(Install: SELinux: Contexts) App Protect Config"
56+
sefcontext:
57+
target: '/opt/app_protect/config(/.*)?'
58+
setype: httpd_config_t
59+
state: present
60+
61+
- name: "(Install: SELinux: Contexts) App Protect bin"
62+
sefcontext:
63+
target: '/opt/app_protect/bin(/.*)?'
64+
setype: httpd_exec_t
65+
state: present
66+
67+
- name: "(Install: SELinux: Contexts) App Protect lock"
68+
sefcontext:
69+
target: '/opt/app_protect/lock(/.*)?'
70+
setype: httpd_lock_t
71+
state: present
72+
73+
- name: "(Install: SELinux: Contexts) App Protect Temp"
74+
sefcontext:
75+
target: '/opt/app_protect/temp(/.*)?'
76+
setype: httpd_tmp_t
77+
state: present
78+
79+
- name: "(Install: SELinux: Contexts) App Protect Tmp"
80+
sefcontext:
81+
target: '/opt/app_protect/tmp(/.*)?'
82+
setype: httpd_tmp_t
83+
state: present
84+
85+
- name: "(Install: SELinux: Contexts) Apply contexts to opt"
86+
command: restorecon -iRv /opt/app_protect
87+
88+
- name: "(Install: SELinux: Contexts) Apply contexts to log"
89+
command: restorecon -iRv /var/log/app_protect
90+
91+
- name: "(Install: SELinux: Custom) Generate policy"
92+
shell:
93+
cmd: cat /var/log/audit/audit.log | audit2allow -M local
94+
chdir: /tmp/
95+
args:
96+
executable: /bin/bash
97+
98+
- name: "(Install: SELinux: Custom) Apply local policy"
99+
command: semodule -i /tmp/local.pp
100+
101+
- name: "(Install: SELinux) Enforce SELinux"
102+
selinux:
103+
state: enforcing
104+
policy: targeted

0 commit comments

Comments
 (0)