-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite.yml
202 lines (172 loc) · 5.07 KB
/
site.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
---
- name: Configure SELinux Sandbox
hosts: all
become: yes
vars:
user: poc_testuser
handlers:
- name: reload httpd
service: name=httpd state=reloaded
tasks:
- name: Set SELinux to Enforcing
selinux: policy=targeted state=enforcing
register: selinux_state
- name: Get SELinux label status
shell: ls -Z | grep redhat-release
args:
chdir: /etc/
register: selinux_label_state
ignore_errors: true
changed_when: false
- name: Enable relabel of filesystem during reboot
file:
path: /.autorelabel
state: touch
when: "'system_u:object_r:etc_t:s0' not in selinux_label_state.stdout"
- name: Reboot to set SELinux state
# shell: /sbin/shutdown -r now
shell: nohup bash -c sleep 2s && reboot &
async: 0
poll: 0
ignore_errors: true
when: selinux_state|changed
register: reboot_necessary
- name: Wait for reboot and relabeling to finish
wait_for:
host: "{{ inventory_hostname }}"
port: 22
delay: 10
timeout: 300
state: started
when: reboot_necessary|changed
- name: Install EPEL
yum:
name: epel-release
state: present
register: epelstate
- name: Install requirements
package:
name: "{{ item }}"
state: present
update_cache: "{{ epelstate | changed }}"
with_items:
- httpd
- setroubleshoot-server
- setools-console
- mcstrans
- policycoreutils-python
- policycoreutils-restorecond
- selinux-policy-devel
- htop
- python34
- zsh
- tmux
- rsync
- nc
- ruby
- git
- "@Development Tools"
- libcgroup-tools
- http://pkgs.repoforge.org/stress/stress-1.0.2-1.el7.rf.x86_64.rpm
- name: Start services
service:
name: "{{ item }}"
enabled: yes
state: started
with_items:
- httpd
- restorecond
- name: Open firewall for httpd
firewalld:
service: http
permanent: true
state: enabled
- name: Create group
group:
name: "{{ item }}"
state: present
with_items:
- "{{ user }}"
- name: Create user
user:
name: "{{ user }}"
state: present
group: "{{ item }}"
with_items:
- "{{ user }}"
- name: Get UID
stat:
path: /home/{{ user }}
register: homedir
ignore_errors: true
changed_when: false
- name: Enable User Slice for {{ homedir.stat.uid }}/{{ user }}
command: systemctl start user-{{ homedir.stat.uid }}.slice
register: slice_state
- name: Create Control Group
command: systemctl set-property user-{{ homedir.stat.uid }}.slice CPUShares=512 MemoryLimit=1024M
register: cgcreate_state
- name: Copy SELinux shelluser policy template
template:
src: shelluser.te.j2
dest: /tmp/uberspace_{{ user }}.te
- name: Compile SELinux policy
shell: make -f /usr/share/selinux/devel/Makefile uberspace_{{ user }}.pp
args:
chdir: /tmp/
register: shelluser_policy
- name: Import compiled SELinux policy
shell: semodule -i uberspace_{{ user }}.pp
args:
chdir: /tmp/
register: semodule_state
- name: Create SELinux user
shell: semanage user -a -R "uberspace_{{ user }}_r" "uberspace_{{ user }}_u"
register: semanage_state
- name: Add targeted user context
template:
src: shelluser_u.j2
dest: /etc/selinux/targeted/contexts/users/uberspace_{{ user }}_u
- name: Add UNIX user to SELinux context
shell: usermod -Z "uberspace_{{ user }}_u" "{{ user }}"
register: userstate
- name: Create user httpdocs
file:
path: /var/www/virtual/{{ user }}
state: directory
seuser: "uberspace_{{ user }}_u"
owner: "{{ user }}"
group: "{{ user }}"
- name: Confine user to home directory
file:
path: "{{ item }}"
state: directory
seuser: "uberspace_{{ user }}_u"
with_items:
- /home/{{ user }}
- /var/www/virtual/{{ user }}
- name: Create SSH configuration directory
file:
path: /home/{{ user }}/.ssh
state: directory
- name: Enable SSH access for {{ user }} using vagrant public key
command: cp /home/vagrant/.ssh/authorized_keys /home/{{ user }}/.ssh/authorized_keys
- name: Fix directory permissions
file:
path: /home/{{ user }}/.ssh
owner: "{{ user }}"
group: "{{ user }}"
recurse: true
- name: Enable VirtualHost configuration for {{ user }}
template:
src: virtualhost.conf.j2
dest: /etc/httpd/conf.d/
notify: reload httpd
# - name: Enable booleans for {{ user }}
# seeboolean: "{{ item }}"
# persistent: yes
# state: yes
# with_items:
# - allow_user_mysql_connect
# - allow_user_postgresql_connect
# - selinuxuser_ping