fail2ban.if 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. ## <summary>Update firewall filtering to ban IP addresses with too many password failures.</summary>
  2. ########################################
  3. ## <summary>
  4. ## Execute a domain transition to run fail2ban.
  5. ## </summary>
  6. ## <param name="domain">
  7. ## <summary>
  8. ## Domain allowed to transition.
  9. ## </summary>
  10. ## </param>
  11. #
  12. interface(`fail2ban_domtrans',`
  13. gen_require(`
  14. type fail2ban_t, fail2ban_exec_t;
  15. ')
  16. corecmd_search_bin($1)
  17. domtrans_pattern($1, fail2ban_exec_t, fail2ban_t)
  18. ')
  19. ########################################
  20. ## <summary>
  21. ## Execute the fail2ban client in
  22. ## the fail2ban client domain.
  23. ## </summary>
  24. ## <param name="domain">
  25. ## <summary>
  26. ## Domain allowed to transition.
  27. ## </summary>
  28. ## </param>
  29. #
  30. interface(`fail2ban_domtrans_client',`
  31. gen_require(`
  32. type fail2ban_client_t, fail2ban_client_exec_t;
  33. ')
  34. corecmd_search_bin($1)
  35. domtrans_pattern($1, fail2ban_client_exec_t, fail2ban_client_t)
  36. ')
  37. ########################################
  38. ## <summary>
  39. ## Execute fail2ban client in the
  40. ## fail2ban client domain, and allow
  41. ## the specified role the fail2ban
  42. ## client domain.
  43. ## </summary>
  44. ## <param name="domain">
  45. ## <summary>
  46. ## Domain allowed to transition.
  47. ## </summary>
  48. ## </param>
  49. ## <param name="role">
  50. ## <summary>
  51. ## Role allowed access.
  52. ## </summary>
  53. ## </param>
  54. #
  55. interface(`fail2ban_run_client',`
  56. gen_require(`
  57. attribute_role fail2ban_client_roles;
  58. ')
  59. fail2ban_domtrans_client($1)
  60. roleattribute $2 fail2ban_client_roles;
  61. ')
  62. #####################################
  63. ## <summary>
  64. ## Connect to fail2ban over a
  65. ## unix domain stream socket.
  66. ## </summary>
  67. ## <param name="domain">
  68. ## <summary>
  69. ## Domain allowed access.
  70. ## </summary>
  71. ## </param>
  72. #
  73. interface(`fail2ban_stream_connect',`
  74. gen_require(`
  75. type fail2ban_t, fail2ban_var_run_t;
  76. ')
  77. files_search_pids($1)
  78. stream_connect_pattern($1, fail2ban_var_run_t, fail2ban_var_run_t, fail2ban_t)
  79. ')
  80. ########################################
  81. ## <summary>
  82. ## Read and write inherited temporary files.
  83. ## </summary>
  84. ## <param name="domain">
  85. ## <summary>
  86. ## Domain allowed access.
  87. ## </summary>
  88. ## </param>
  89. #
  90. interface(`fail2ban_rw_inherited_tmp_files',`
  91. gen_require(`
  92. type fail2ban_tmp_t;
  93. ')
  94. files_search_tmp($1)
  95. allow $1 fail2ban_tmp_t:file { read write };
  96. ')
  97. ########################################
  98. ## <summary>
  99. ## Do not audit attempts to use
  100. ## fail2ban file descriptors.
  101. ## </summary>
  102. ## <param name="domain">
  103. ## <summary>
  104. ## Domain to not audit.
  105. ## </summary>
  106. ## </param>
  107. #
  108. interface(`fail2ban_dontaudit_use_fds',`
  109. gen_require(`
  110. type fail2ban_t;
  111. ')
  112. dontaudit $1 fail2ban_t:fd use;
  113. ')
  114. ########################################
  115. ## <summary>
  116. ## Do not audit attempts to read and
  117. ## write fail2ban unix stream sockets
  118. ## </summary>
  119. ## <param name="domain">
  120. ## <summary>
  121. ## Domain to not audit.
  122. ## </summary>
  123. ## </param>
  124. #
  125. interface(`fail2ban_dontaudit_rw_stream_sockets',`
  126. gen_require(`
  127. type fail2ban_t;
  128. ')
  129. dontaudit $1 fail2ban_t:unix_stream_socket { read write };
  130. ')
  131. ########################################
  132. ## <summary>
  133. ## Read and write fail2ban unix
  134. ## stream sockets.
  135. ## </summary>
  136. ## <param name="domain">
  137. ## <summary>
  138. ## Domain allowed access.
  139. ## </summary>
  140. ## </param>
  141. #
  142. interface(`fail2ban_rw_stream_sockets',`
  143. gen_require(`
  144. type fail2ban_t;
  145. ')
  146. allow $1 fail2ban_t:unix_stream_socket rw_stream_socket_perms;
  147. ')
  148. ########################################
  149. ## <summary>
  150. ## Read fail2ban lib files.
  151. ## </summary>
  152. ## <param name="domain">
  153. ## <summary>
  154. ## Domain allowed access.
  155. ## </summary>
  156. ## </param>
  157. #
  158. interface(`fail2ban_read_lib_files',`
  159. gen_require(`
  160. type fail2ban_var_lib_t;
  161. ')
  162. files_search_var_lib($1)
  163. allow $1 fail2ban_var_lib_t:file read_file_perms;
  164. ')
  165. ########################################
  166. ## <summary>
  167. ## Read fail2ban log files.
  168. ## </summary>
  169. ## <param name="domain">
  170. ## <summary>
  171. ## Domain allowed access.
  172. ## </summary>
  173. ## </param>
  174. ## <rolecap/>
  175. #
  176. interface(`fail2ban_read_log',`
  177. gen_require(`
  178. type fail2ban_log_t;
  179. ')
  180. logging_search_logs($1)
  181. allow $1 fail2ban_log_t:file read_file_perms;
  182. ')
  183. ########################################
  184. ## <summary>
  185. ## Append fail2ban log files.
  186. ## </summary>
  187. ## <param name="domain">
  188. ## <summary>
  189. ## Domain allowed access.
  190. ## </summary>
  191. ## </param>
  192. #
  193. interface(`fail2ban_append_log',`
  194. gen_require(`
  195. type fail2ban_log_t;
  196. ')
  197. logging_search_logs($1)
  198. allow $1 fail2ban_log_t:file append_file_perms;
  199. ')
  200. ########################################
  201. ## <summary>
  202. ## Read fail2ban pid files.
  203. ## </summary>
  204. ## <param name="domain">
  205. ## <summary>
  206. ## Domain allowed access.
  207. ## </summary>
  208. ## </param>
  209. #
  210. interface(`fail2ban_read_pid_files',`
  211. gen_require(`
  212. type fail2ban_var_run_t;
  213. ')
  214. files_search_pids($1)
  215. allow $1 fail2ban_var_run_t:file read_file_perms;
  216. ')
  217. ########################################
  218. ## <summary>
  219. ## All of the rules required to
  220. ## administrate an fail2ban environment.
  221. ## </summary>
  222. ## <param name="domain">
  223. ## <summary>
  224. ## Domain allowed access.
  225. ## </summary>
  226. ## </param>
  227. ## <param name="role">
  228. ## <summary>
  229. ## Role allowed access.
  230. ## </summary>
  231. ## </param>
  232. ## <rolecap/>
  233. #
  234. interface(`fail2ban_admin',`
  235. gen_require(`
  236. type fail2ban_t, fail2ban_log_t, fail2ban_tmp_t;
  237. type fail2ban_var_run_t, fail2ban_initrc_exec_t;
  238. type fail2ban_var_lib_t, fail2ban_client_t;
  239. ')
  240. allow $1 { fail2ban_t fail2ban_client_t }:process { ptrace signal_perms };
  241. ps_process_pattern($1, { fail2ban_t fail2ban_client_t })
  242. init_labeled_script_domtrans($1, fail2ban_initrc_exec_t)
  243. domain_system_change_exemption($1)
  244. role_transition $2 fail2ban_initrc_exec_t system_r;
  245. allow $2 system_r;
  246. logging_list_logs($1)
  247. admin_pattern($1, fail2ban_log_t)
  248. files_list_pids($1)
  249. admin_pattern($1, fail2ban_var_run_t)
  250. files_search_var_lib($1)
  251. admin_pattern($1, fail2ban_var_lib_t)
  252. files_search_tmp($1)
  253. admin_pattern($1, fail2ban_tmp_t)
  254. fail2ban_run_client($1, $2)
  255. ')