1 |
commit: 803076cd0dc344f6d04b6509508fcfd9f7de80f5 |
2 |
Author: Dominick Grift <dominick.grift <AT> gmail <DOT> com> |
3 |
AuthorDate: Mon Oct 1 07:27:01 2012 +0000 |
4 |
Commit: Sven Vermeulen <sven.vermeulen <AT> siphos <DOT> be> |
5 |
CommitDate: Tue Oct 2 18:05:40 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/hardened-refpolicy.git;a=commit;h=803076cd |
7 |
|
8 |
Changes to the fail2ban policy module |
9 |
|
10 |
Ported from Fedora with changes |
11 |
|
12 |
Signed-off-by: Dominick Grift <dominick.grift <AT> gmail.com> |
13 |
|
14 |
--- |
15 |
policy/modules/contrib/fail2ban.fc | 11 +++-- |
16 |
policy/modules/contrib/fail2ban.if | 85 +++++++++++++++++++++++++++++------ |
17 |
policy/modules/contrib/fail2ban.te | 74 ++++++++++++++++++++++++------- |
18 |
3 files changed, 133 insertions(+), 37 deletions(-) |
19 |
|
20 |
diff --git a/policy/modules/contrib/fail2ban.fc b/policy/modules/contrib/fail2ban.fc |
21 |
index 0de2b83..4da938f 100644 |
22 |
--- a/policy/modules/contrib/fail2ban.fc |
23 |
+++ b/policy/modules/contrib/fail2ban.fc |
24 |
@@ -1,8 +1,9 @@ |
25 |
-/etc/rc\.d/init\.d/fail2ban -- gen_context(system_u:object_r:fail2ban_initrc_exec_t,s0) |
26 |
+/etc/rc\.d/init\.d/fail2ban -- gen_context(system_u:object_r:fail2ban_initrc_exec_t,s0) |
27 |
|
28 |
/usr/bin/fail2ban -- gen_context(system_u:object_r:fail2ban_exec_t,s0) |
29 |
-/usr/bin/fail2ban-server -- gen_context(system_u:object_r:fail2ban_exec_t,s0) |
30 |
+/usr/bin/fail2ban-client -- gen_context(system_u:object_r:fail2ban_client_exec_t,s0) |
31 |
+/usr/bin/fail2ban-server -- gen_context(system_u:object_r:fail2ban_exec_t,s0) |
32 |
|
33 |
-/var/lib/fail2ban(/.*)? gen_context(system_u:object_r:fail2ban_var_lib_t,s0) |
34 |
-/var/log/fail2ban\.log -- gen_context(system_u:object_r:fail2ban_log_t,s0) |
35 |
-/var/run/fail2ban.* gen_context(system_u:object_r:fail2ban_var_run_t,s0) |
36 |
+/var/lib/fail2ban(/.*)? gen_context(system_u:object_r:fail2ban_var_lib_t,s0) |
37 |
+/var/log/fail2ban\.log.* -- gen_context(system_u:object_r:fail2ban_log_t,s0) |
38 |
+/var/run/fail2ban.* gen_context(system_u:object_r:fail2ban_var_run_t,s0) |
39 |
|
40 |
diff --git a/policy/modules/contrib/fail2ban.if b/policy/modules/contrib/fail2ban.if |
41 |
index f590a1f..a2f8aa2 100644 |
42 |
--- a/policy/modules/contrib/fail2ban.if |
43 |
+++ b/policy/modules/contrib/fail2ban.if |
44 |
@@ -15,13 +15,61 @@ interface(`fail2ban_domtrans',` |
45 |
type fail2ban_t, fail2ban_exec_t; |
46 |
') |
47 |
|
48 |
+ corecmd_search_bin($1) |
49 |
domtrans_pattern($1, fail2ban_exec_t, fail2ban_t) |
50 |
') |
51 |
|
52 |
+######################################## |
53 |
+## <summary> |
54 |
+## Execute the fail2ban client in |
55 |
+## the fail2ban client domain. |
56 |
+## </summary> |
57 |
+## <param name="domain"> |
58 |
+## <summary> |
59 |
+## Domain allowed to transition. |
60 |
+## </summary> |
61 |
+## </param> |
62 |
+# |
63 |
+interface(`fail2ban_domtrans_client',` |
64 |
+ gen_require(` |
65 |
+ type fail2ban_client_t, fail2ban_client_exec_t; |
66 |
+ ') |
67 |
+ |
68 |
+ corecmd_search_bin($1) |
69 |
+ domtrans_pattern($1, fail2ban_client_exec_t, fail2ban_client_t) |
70 |
+') |
71 |
+ |
72 |
+######################################## |
73 |
+## <summary> |
74 |
+## Execute fail2ban client in the |
75 |
+## fail2ban client domain, and allow |
76 |
+## the specified role the fail2ban |
77 |
+## client domain. |
78 |
+## </summary> |
79 |
+## <param name="domain"> |
80 |
+## <summary> |
81 |
+## Domain allowed to transition. |
82 |
+## </summary> |
83 |
+## </param> |
84 |
+## <param name="role"> |
85 |
+## <summary> |
86 |
+## Role allowed access. |
87 |
+## </summary> |
88 |
+## </param> |
89 |
+# |
90 |
+interface(`fail2ban_run_client',` |
91 |
+ gen_require(` |
92 |
+ attribute_role fail2ban_client_roles; |
93 |
+ ') |
94 |
+ |
95 |
+ fail2ban_domtrans_client($1) |
96 |
+ roleattribute $2 fail2ban_client_roles; |
97 |
+') |
98 |
+ |
99 |
##################################### |
100 |
## <summary> |
101 |
-## Connect to fail2ban over a unix domain |
102 |
-## stream socket. |
103 |
+## Connect to fail2ban over a |
104 |
+## unix domain stream socket. |
105 |
## </summary> |
106 |
## <param name="domain"> |
107 |
## <summary> |
108 |
@@ -40,7 +88,8 @@ interface(`fail2ban_stream_connect',` |
109 |
|
110 |
######################################## |
111 |
## <summary> |
112 |
-## Read and write to an fail2ban unix stream socket. |
113 |
+## Read and write fail2ban unix |
114 |
+## stream sockets. |
115 |
## </summary> |
116 |
## <param name="domain"> |
117 |
## <summary> |
118 |
@@ -77,7 +126,7 @@ interface(`fail2ban_read_lib_files',` |
119 |
|
120 |
######################################## |
121 |
## <summary> |
122 |
-## Allow the specified domain to read fail2ban's log files. |
123 |
+## Read fail2ban log files. |
124 |
## </summary> |
125 |
## <param name="domain"> |
126 |
## <summary> |
127 |
@@ -92,14 +141,12 @@ interface(`fail2ban_read_log',` |
128 |
') |
129 |
|
130 |
logging_search_logs($1) |
131 |
- allow $1 fail2ban_log_t:dir list_dir_perms; |
132 |
allow $1 fail2ban_log_t:file read_file_perms; |
133 |
') |
134 |
|
135 |
######################################## |
136 |
## <summary> |
137 |
-## Allow the specified domain to append |
138 |
-## fail2ban log files. |
139 |
+## Append fail2ban log files. |
140 |
## </summary> |
141 |
## <param name="domain"> |
142 |
## <summary> |
143 |
@@ -113,13 +160,12 @@ interface(`fail2ban_append_log',` |
144 |
') |
145 |
|
146 |
logging_search_logs($1) |
147 |
- allow $1 fail2ban_log_t:dir list_dir_perms; |
148 |
allow $1 fail2ban_log_t:file append_file_perms; |
149 |
') |
150 |
|
151 |
######################################## |
152 |
## <summary> |
153 |
-## Read fail2ban PID files. |
154 |
+## Read fail2ban pid files. |
155 |
## </summary> |
156 |
## <param name="domain"> |
157 |
## <summary> |
158 |
@@ -138,8 +184,8 @@ interface(`fail2ban_read_pid_files',` |
159 |
|
160 |
######################################## |
161 |
## <summary> |
162 |
-## All of the rules required to administrate |
163 |
-## an fail2ban environment |
164 |
+## All of the rules required to |
165 |
+## administrate an fail2ban environment. |
166 |
## </summary> |
167 |
## <param name="domain"> |
168 |
## <summary> |
169 |
@@ -148,19 +194,20 @@ interface(`fail2ban_read_pid_files',` |
170 |
## </param> |
171 |
## <param name="role"> |
172 |
## <summary> |
173 |
-## The role to be allowed to manage the fail2ban domain. |
174 |
+## Role allowed access. |
175 |
## </summary> |
176 |
## </param> |
177 |
## <rolecap/> |
178 |
# |
179 |
interface(`fail2ban_admin',` |
180 |
gen_require(` |
181 |
- type fail2ban_t, fail2ban_log_t; |
182 |
+ type fail2ban_t, fail2ban_log_t, fail2ban_tmp_t; |
183 |
type fail2ban_var_run_t, fail2ban_initrc_exec_t; |
184 |
+ type fail2ban_var_lib_t, fail2ban_client_t; |
185 |
') |
186 |
|
187 |
- allow $1 fail2ban_t:process { ptrace signal_perms }; |
188 |
- ps_process_pattern($1, fail2ban_t) |
189 |
+ allow $1 { fail2ban_t fail2ban_client_t }:process { ptrace signal_perms }; |
190 |
+ ps_process_pattern($1, { fail2ban_t fail2ban_client_t }) |
191 |
|
192 |
init_labeled_script_domtrans($1, fail2ban_initrc_exec_t) |
193 |
domain_system_change_exemption($1) |
194 |
@@ -172,4 +219,12 @@ interface(`fail2ban_admin',` |
195 |
|
196 |
files_list_pids($1) |
197 |
admin_pattern($1, fail2ban_var_run_t) |
198 |
+ |
199 |
+ files_search_var_lib($1) |
200 |
+ admin_pattern($1, fail2ban_var_lib_t) |
201 |
+ |
202 |
+ files_search_tmp($1) |
203 |
+ admin_pattern($1, fail2ban_tmp_t) |
204 |
+ |
205 |
+ fail2ban_run_client($1, $2) |
206 |
') |
207 |
|
208 |
diff --git a/policy/modules/contrib/fail2ban.te b/policy/modules/contrib/fail2ban.te |
209 |
index 4cdbca5..b498e66 100644 |
210 |
--- a/policy/modules/contrib/fail2ban.te |
211 |
+++ b/policy/modules/contrib/fail2ban.te |
212 |
@@ -1,10 +1,12 @@ |
213 |
-policy_module(fail2ban, 1.4.0) |
214 |
+policy_module(fail2ban, 1.4.1) |
215 |
|
216 |
######################################## |
217 |
# |
218 |
# Declarations |
219 |
# |
220 |
|
221 |
+attribute_role fail2ban_client_roles; |
222 |
+ |
223 |
type fail2ban_t; |
224 |
type fail2ban_exec_t; |
225 |
init_daemon_domain(fail2ban_t, fail2ban_exec_t) |
226 |
@@ -12,43 +14,51 @@ init_daemon_domain(fail2ban_t, fail2ban_exec_t) |
227 |
type fail2ban_initrc_exec_t; |
228 |
init_script_file(fail2ban_initrc_exec_t) |
229 |
|
230 |
-# log files |
231 |
type fail2ban_log_t; |
232 |
logging_log_file(fail2ban_log_t) |
233 |
|
234 |
type fail2ban_var_lib_t; |
235 |
files_type(fail2ban_var_lib_t) |
236 |
|
237 |
-# pid files |
238 |
type fail2ban_var_run_t; |
239 |
files_pid_file(fail2ban_var_run_t) |
240 |
|
241 |
+type fail2ban_tmp_t; |
242 |
+files_tmp_file(fail2ban_tmp_t) |
243 |
+ |
244 |
+type fail2ban_client_t; |
245 |
+type fail2ban_client_exec_t; |
246 |
+init_system_domain(fail2ban_client_t, fail2ban_client_exec_t) |
247 |
+role fail2ban_client_roles types fail2ban_client_t; |
248 |
+ |
249 |
######################################## |
250 |
# |
251 |
-# fail2ban local policy |
252 |
+# Server Local policy |
253 |
# |
254 |
|
255 |
-allow fail2ban_t self:capability { sys_tty_config }; |
256 |
+allow fail2ban_t self:capability { dac_read_search dac_override sys_tty_config }; |
257 |
allow fail2ban_t self:process signal; |
258 |
allow fail2ban_t self:fifo_file rw_fifo_file_perms; |
259 |
-allow fail2ban_t self:unix_stream_socket { connectto create_stream_socket_perms }; |
260 |
-allow fail2ban_t self:unix_dgram_socket create_socket_perms; |
261 |
-allow fail2ban_t self:tcp_socket create_stream_socket_perms; |
262 |
+allow fail2ban_t self:unix_stream_socket { accept connectto listen }; |
263 |
+allow fail2ban_t self:tcp_socket { accept listen }; |
264 |
|
265 |
-# log files |
266 |
-allow fail2ban_t fail2ban_log_t:dir setattr; |
267 |
-manage_files_pattern(fail2ban_t, fail2ban_log_t, fail2ban_log_t) |
268 |
+append_files_pattern(fail2ban_t, fail2ban_log_t, fail2ban_log_t) |
269 |
+create_files_pattern(fail2ban_t, fail2ban_log_t, fail2ban_log_t) |
270 |
+setattr_files_pattern(fail2ban_t, fail2ban_log_t, fail2ban_log_t) |
271 |
logging_log_filetrans(fail2ban_t, fail2ban_log_t, file) |
272 |
|
273 |
+manage_dirs_pattern(fail2ban_t, fail2ban_tmp_t, fail2ban_tmp_t) |
274 |
+manage_files_pattern(fail2ban_t, fail2ban_tmp_t, fail2ban_tmp_t) |
275 |
+exec_files_pattern(fail2ban_t, fail2ban_tmp_t, fail2ban_tmp_t) |
276 |
+files_tmp_filetrans(fail2ban_t, fail2ban_tmp_t, { dir file }) |
277 |
+ |
278 |
manage_dirs_pattern(fail2ban_t, fail2ban_var_lib_t, fail2ban_var_lib_t) |
279 |
manage_files_pattern(fail2ban_t, fail2ban_var_lib_t, fail2ban_var_lib_t) |
280 |
-files_var_lib_filetrans(fail2ban_t, fail2ban_var_lib_t, { dir file }) |
281 |
|
282 |
-# pid file |
283 |
manage_dirs_pattern(fail2ban_t, fail2ban_var_run_t, fail2ban_var_run_t) |
284 |
manage_sock_files_pattern(fail2ban_t, fail2ban_var_run_t, fail2ban_var_run_t) |
285 |
manage_files_pattern(fail2ban_t, fail2ban_var_run_t, fail2ban_var_run_t) |
286 |
-files_pid_filetrans(fail2ban_t, fail2ban_var_run_t, { dir file sock_file }) |
287 |
+files_pid_filetrans(fail2ban_t, fail2ban_var_run_t, file) |
288 |
|
289 |
# FAM support needs this (/proc/self and parent stuff) |
290 |
read_files_pattern(fail2ban_t, fail2ban_t, fail2ban_t) |
291 |
@@ -62,15 +72,16 @@ corenet_all_recvfrom_unlabeled(fail2ban_t) |
292 |
corenet_all_recvfrom_netlabel(fail2ban_t) |
293 |
corenet_tcp_sendrecv_generic_if(fail2ban_t) |
294 |
corenet_tcp_sendrecv_generic_node(fail2ban_t) |
295 |
-corenet_tcp_sendrecv_all_ports(fail2ban_t) |
296 |
-corenet_tcp_connect_whois_port(fail2ban_t) |
297 |
+ |
298 |
corenet_sendrecv_whois_client_packets(fail2ban_t) |
299 |
+corenet_tcp_connect_whois_port(fail2ban_t) |
300 |
+corenet_tcp_sendrecv_whois_port(fail2ban_t) |
301 |
|
302 |
dev_read_urand(fail2ban_t) |
303 |
|
304 |
domain_use_interactive_fds(fail2ban_t) |
305 |
+domain_dontaudit_read_all_domains_state(fail2ban_t) |
306 |
|
307 |
-files_read_etc_files(fail2ban_t) |
308 |
files_read_etc_runtime_files(fail2ban_t) |
309 |
files_read_usr_files(fail2ban_t) |
310 |
files_list_var(fail2ban_t) |
311 |
@@ -87,6 +98,8 @@ logging_send_syslog_msg(fail2ban_t) |
312 |
|
313 |
miscfiles_read_localization(fail2ban_t) |
314 |
|
315 |
+sysnet_manage_config(fail2ban_t) |
316 |
+ |
317 |
mta_send_mail(fail2ban_t) |
318 |
|
319 |
optional_policy(` |
320 |
@@ -100,3 +113,30 @@ optional_policy(` |
321 |
optional_policy(` |
322 |
iptables_domtrans(fail2ban_t) |
323 |
') |
324 |
+ |
325 |
+optional_policy(` |
326 |
+ libs_exec_ldconfig(fail2ban_t) |
327 |
+') |
328 |
+ |
329 |
+optional_policy(` |
330 |
+ shorewall_domtrans(fail2ban_t) |
331 |
+') |
332 |
+ |
333 |
+######################################## |
334 |
+# |
335 |
+# Client Local policy |
336 |
+# |
337 |
+ |
338 |
+domtrans_pattern(fail2ban_client_t, fail2ban_exec_t, fail2ban_t) |
339 |
+ |
340 |
+stream_connect_pattern(fail2ban_client_t, fail2ban_var_run_t, fail2ban_var_run_t, fail2ban_t) |
341 |
+ |
342 |
+kernel_read_system_state(fail2ban_client_t) |
343 |
+ |
344 |
+corecmd_exec_bin(fail2ban_client_t) |
345 |
+ |
346 |
+files_read_etc_files(fail2ban_client_t) |
347 |
+files_read_usr_files(fail2ban_client_t) |
348 |
+files_search_pids(fail2ban_client_t) |
349 |
+ |
350 |
+miscfiles_read_localization(fail2ban_client_t) |