mta.te 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. policy_module(mta, 2.8.5)
  2. ########################################
  3. #
  4. # Declarations
  5. #
  6. attribute mailcontent_type;
  7. attribute mta_exec_type;
  8. attribute mta_user_agent;
  9. attribute mailserver_delivery;
  10. attribute mailserver_domain;
  11. attribute mailserver_sender;
  12. attribute user_mail_domain;
  13. attribute_role user_mail_roles;
  14. type etc_aliases_t;
  15. files_type(etc_aliases_t)
  16. type etc_mail_t;
  17. files_config_file(etc_mail_t)
  18. type mail_home_t alias mail_forward_t;
  19. userdom_user_home_content(mail_home_t)
  20. type mail_home_rw_t;
  21. userdom_user_home_content(mail_home_rw_t)
  22. type mqueue_spool_t;
  23. files_mountpoint(mqueue_spool_t)
  24. type mail_spool_t;
  25. files_mountpoint(mail_spool_t)
  26. type sendmail_exec_t;
  27. mta_agent_executable(sendmail_exec_t)
  28. mta_base_mail_template(system)
  29. role system_r types system_mail_t;
  30. mta_base_mail_template(user)
  31. typealias user_mail_t alias { staff_mail_t sysadm_mail_t };
  32. typealias user_mail_t alias { auditadm_mail_t secadm_mail_t };
  33. userdom_user_application_type(user_mail_t)
  34. role user_mail_roles types user_mail_t;
  35. typealias user_mail_tmp_t alias { staff_mail_tmp_t sysadm_mail_tmp_t };
  36. typealias user_mail_tmp_t alias { auditadm_mail_tmp_t secadm_mail_tmp_t };
  37. userdom_user_tmp_file(user_mail_tmp_t)
  38. ########################################
  39. #
  40. # Common base mail policy
  41. #
  42. allow user_mail_domain self:capability { setuid setgid chown };
  43. allow user_mail_domain self:process { signal_perms setrlimit };
  44. allow user_mail_domain self:fifo_file rw_fifo_file_perms;
  45. allow user_mail_domain mta_exec_type:file entrypoint;
  46. allow user_mail_domain mail_home_t:file { append_file_perms read_file_perms };
  47. manage_dirs_pattern(user_mail_domain, mail_home_rw_t, mail_home_rw_t)
  48. manage_files_pattern(user_mail_domain, mail_home_rw_t, mail_home_rw_t)
  49. manage_lnk_files_pattern(user_mail_domain, mail_home_rw_t, mail_home_rw_t)
  50. userdom_user_home_dir_filetrans(user_mail_domain, mail_home_rw_t, dir, "Maildir")
  51. userdom_user_home_dir_filetrans(user_mail_domain, mail_home_rw_t, dir, ".maildir")
  52. read_files_pattern(user_mail_domain, { etc_mail_t etc_aliases_t }, { etc_mail_t etc_aliases_t })
  53. manage_files_pattern(user_mail_domain, { mqueue_spool_t mail_spool_t }, { mqueue_spool_t mail_spool_t })
  54. read_lnk_files_pattern(user_mail_domain, { mqueue_spool_t mail_spool_t }, { mqueue_spool_t mail_spool_t })
  55. allow user_mail_domain sendmail_exec_t:lnk_file read_lnk_file_perms;
  56. can_exec(user_mail_domain, { mta_exec_type sendmail_exec_t })
  57. kernel_read_crypto_sysctls(user_mail_domain)
  58. kernel_read_system_state(user_mail_domain)
  59. kernel_read_kernel_sysctls(user_mail_domain)
  60. kernel_read_network_state(user_mail_domain)
  61. kernel_request_load_module(user_mail_domain)
  62. corenet_all_recvfrom_netlabel(user_mail_domain)
  63. corenet_tcp_sendrecv_generic_if(user_mail_domain)
  64. corenet_tcp_sendrecv_generic_node(user_mail_domain)
  65. corenet_sendrecv_all_client_packets(user_mail_domain)
  66. corenet_tcp_connect_all_ports(user_mail_domain)
  67. corenet_tcp_sendrecv_all_ports(user_mail_domain)
  68. corecmd_exec_bin(user_mail_domain)
  69. dev_read_urand(user_mail_domain)
  70. domain_use_interactive_fds(user_mail_domain)
  71. files_read_etc_runtime_files(user_mail_domain)
  72. files_read_usr_files(user_mail_domain)
  73. files_search_spool(user_mail_domain)
  74. files_dontaudit_search_pids(user_mail_domain)
  75. fs_getattr_all_fs(user_mail_domain)
  76. init_dontaudit_rw_utmp(user_mail_domain)
  77. logging_send_syslog_msg(user_mail_domain)
  78. miscfiles_read_localization(user_mail_domain)
  79. tunable_policy(`use_samba_home_dirs',`
  80. fs_manage_cifs_dirs(user_mail_domain)
  81. fs_manage_cifs_files(user_mail_domain)
  82. fs_read_cifs_symlinks(user_mail_domain)
  83. ')
  84. tunable_policy(`use_nfs_home_dirs',`
  85. fs_manage_nfs_dirs(user_mail_domain)
  86. fs_manage_nfs_files(user_mail_domain)
  87. fs_read_nfs_symlinks(user_mail_domain)
  88. ')
  89. optional_policy(`
  90. courier_manage_spool_dirs(user_mail_domain)
  91. courier_manage_spool_files(user_mail_domain)
  92. courier_rw_spool_pipes(user_mail_domain)
  93. ')
  94. optional_policy(`
  95. exim_domtrans(user_mail_domain)
  96. exim_manage_log(user_mail_domain)
  97. exim_manage_spool_files(user_mail_domain)
  98. exim_read_var_lib_files(user_mail_domain)
  99. ')
  100. optional_policy(`
  101. files_getattr_tmp_dirs(user_mail_domain)
  102. postfix_exec_master(user_mail_domain)
  103. postfix_read_config(user_mail_domain)
  104. postfix_search_spool(user_mail_domain)
  105. postfix_rw_inherited_master_pipes(user_mail_domain)
  106. ifdef(`distro_redhat',`
  107. postfix_config_filetrans(user_mail_domain, etc_aliases_t, { dir file lnk_file sock_file fifo_file })
  108. ')
  109. ')
  110. optional_policy(`
  111. procmail_exec(user_mail_domain)
  112. ')
  113. optional_policy(`
  114. qmail_domtrans_inject(user_mail_domain)
  115. ')
  116. optional_policy(`
  117. sendmail_manage_log(user_mail_domain)
  118. sendmail_log_filetrans_sendmail_log(user_mail_domain, file)
  119. ')
  120. optional_policy(`
  121. uucp_manage_spool(user_mail_domain)
  122. ')
  123. ########################################
  124. #
  125. # System local policy
  126. #
  127. allow system_mail_t self:capability { dac_override fowner };
  128. read_files_pattern(system_mail_t, etc_mail_t, etc_mail_t)
  129. read_files_pattern(system_mail_t, mailcontent_type, mailcontent_type)
  130. allow system_mail_t mail_home_t:file manage_file_perms;
  131. userdom_user_home_dir_filetrans(system_mail_t, mail_home_t, file, ".esmtp_queue")
  132. userdom_user_home_dir_filetrans(system_mail_t, mail_home_t, file, ".forward")
  133. userdom_user_home_dir_filetrans(system_mail_t, mail_home_t, file, ".mailrc")
  134. userdom_user_home_dir_filetrans(system_mail_t, mail_home_t, file, "dead.letter")
  135. allow system_mail_t user_mail_domain:dir list_dir_perms;
  136. allow system_mail_t user_mail_domain:file read_file_perms;
  137. allow system_mail_t user_mail_domain:lnk_file read_lnk_file_perms;
  138. corecmd_exec_shell(system_mail_t)
  139. dev_read_rand(system_mail_t)
  140. dev_read_sysfs(system_mail_t)
  141. fs_rw_anon_inodefs_files(system_mail_t)
  142. selinux_getattr_fs(system_mail_t)
  143. term_dontaudit_use_unallocated_ttys(system_mail_t)
  144. init_use_script_ptys(system_mail_t)
  145. userdom_use_user_terminals(system_mail_t)
  146. optional_policy(`
  147. gen_require(`
  148. type crond_tmp_t;
  149. ')
  150. allow system_mail_t crond_tmp_t:file write;
  151. ')
  152. optional_policy(`
  153. apache_read_squirrelmail_data(system_mail_t)
  154. apache_append_squirrelmail_data(system_mail_t)
  155. apache_dontaudit_append_log(system_mail_t)
  156. apache_dontaudit_rw_stream_sockets(system_mail_t)
  157. apache_dontaudit_rw_tcp_sockets(system_mail_t)
  158. apache_dontaudit_rw_sys_script_stream_sockets(system_mail_t)
  159. ')
  160. optional_policy(`
  161. phpfpm_dontaudit_rw_stream_sockets(system_mail_t)
  162. phpfpm_dontaudit_rw_tcp_sockets(system_mail_t)
  163. ')
  164. optional_policy(`
  165. arpwatch_manage_tmp_files(system_mail_t)
  166. ifdef(`hide_broken_symptoms',`
  167. arpwatch_dontaudit_rw_packet_sockets(system_mail_t)
  168. ')
  169. ')
  170. optional_policy(`
  171. bugzilla_search_content(system_mail_t)
  172. bugzilla_dontaudit_rw_stream_sockets(system_mail_t)
  173. ')
  174. optional_policy(`
  175. clamav_stream_connect(system_mail_t)
  176. clamav_append_log(system_mail_t)
  177. ')
  178. optional_policy(`
  179. cron_read_system_job_tmp_files(system_mail_t)
  180. cron_dontaudit_write_pipes(system_mail_t)
  181. cron_rw_system_job_stream_sockets(system_mail_t)
  182. ')
  183. optional_policy(`
  184. courier_stream_connect_authdaemon(system_mail_t)
  185. ')
  186. optional_policy(`
  187. cvs_read_data(system_mail_t)
  188. ')
  189. optional_policy(`
  190. fail2ban_dontaudit_rw_stream_sockets(system_mail_t)
  191. fail2ban_append_log(system_mail_t)
  192. fail2ban_rw_inherited_tmp_files(system_mail_t)
  193. ')
  194. optional_policy(`
  195. logrotate_read_tmp_files(system_mail_t)
  196. ')
  197. optional_policy(`
  198. logwatch_read_tmp_files(system_mail_t)
  199. ')
  200. optional_policy(`
  201. milter_getattr_all_sockets(system_mail_t)
  202. ')
  203. optional_policy(`
  204. nagios_read_tmp_files(system_mail_t)
  205. ')
  206. optional_policy(`
  207. manage_dirs_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  208. manage_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  209. manage_lnk_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  210. manage_fifo_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  211. manage_sock_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  212. files_etc_filetrans(system_mail_t, etc_aliases_t, { file lnk_file sock_file fifo_file })
  213. ')
  214. optional_policy(`
  215. sxid_read_log(system_mail_t)
  216. ')
  217. optional_policy(`
  218. userdom_dontaudit_use_user_ptys(system_mail_t)
  219. optional_policy(`
  220. cron_dontaudit_append_system_job_tmp_files(system_mail_t)
  221. ')
  222. ')
  223. optional_policy(`
  224. spamassassin_stream_connect_spamd(system_mail_t)
  225. ')
  226. optional_policy(`
  227. smartmon_read_tmp_files(system_mail_t)
  228. ')
  229. ########################################
  230. #
  231. # MTA user agent local policy
  232. #
  233. userdom_use_user_terminals(mta_user_agent)
  234. optional_policy(`
  235. apache_append_log(mta_user_agent)
  236. ')
  237. optional_policy(`
  238. arpwatch_manage_tmp_files(mta_user_agent)
  239. ifdef(`hide_broken_symptoms',`
  240. arpwatch_dontaudit_rw_packet_sockets(mta_user_agent)
  241. ')
  242. optional_policy(`
  243. cron_read_system_job_tmp_files(mta_user_agent)
  244. ')
  245. ')
  246. ########################################
  247. #
  248. # Mailserver delivery local policy
  249. #
  250. allow mailserver_delivery self:fifo_file rw_fifo_file_perms;
  251. allow mailserver_delivery mail_spool_t:dir list_dir_perms;
  252. create_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  253. read_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  254. append_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  255. create_lnk_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  256. read_lnk_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  257. manage_dirs_pattern(mailserver_delivery, mail_home_rw_t, mail_home_rw_t)
  258. manage_files_pattern(mailserver_delivery, { mail_home_t mail_home_rw_t }, { mail_home_t mail_home_rw_t })
  259. manage_lnk_files_pattern(mailserver_delivery, mail_home_rw_t, mail_home_rw_t)
  260. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, ".esmtp_queue")
  261. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, ".forward")
  262. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, ".mailrc")
  263. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, "dead.letter")
  264. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_rw_t, dir, "Maildir")
  265. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_rw_t, dir, ".maildir")
  266. read_files_pattern(mailserver_delivery, system_mail_tmp_t, system_mail_tmp_t)
  267. tunable_policy(`use_samba_home_dirs',`
  268. fs_manage_cifs_dirs(mailserver_delivery)
  269. fs_manage_cifs_files(mailserver_delivery)
  270. fs_read_cifs_symlinks(mailserver_delivery)
  271. ')
  272. tunable_policy(`use_nfs_home_dirs',`
  273. fs_manage_nfs_dirs(mailserver_delivery)
  274. fs_manage_nfs_files(mailserver_delivery)
  275. fs_read_nfs_symlinks(mailserver_delivery)
  276. ')
  277. optional_policy(`
  278. arpwatch_search_data(mailserver_delivery)
  279. ')
  280. optional_policy(`
  281. dovecot_manage_spool(mailserver_delivery)
  282. dovecot_domtrans_deliver(mailserver_delivery)
  283. ')
  284. optional_policy(`
  285. files_search_var_lib(mailserver_delivery)
  286. mailman_domtrans(mailserver_delivery)
  287. mailman_read_data_symlinks(mailserver_delivery)
  288. ')
  289. optional_policy(`
  290. postfix_rw_inherited_master_pipes(mailserver_delivery)
  291. ')
  292. optional_policy(`
  293. uucp_domtrans_uux(mailserver_delivery)
  294. ')
  295. ########################################
  296. #
  297. # User local policy
  298. #
  299. manage_files_pattern(user_mail_t, mail_home_t, mail_home_t)
  300. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, ".esmtp_queue")
  301. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, ".forward")
  302. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, ".mailrc")
  303. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, "dead.letter")
  304. dev_read_sysfs(user_mail_t)
  305. userdom_use_user_terminals(user_mail_t)
  306. mta_manage_aliases(user_mail_t)
  307. optional_policy(`
  308. allow user_mail_t self:capability dac_override;
  309. userdom_rw_user_tmp_files(user_mail_t)
  310. postfix_read_config(user_mail_t)
  311. postfix_list_spool(user_mail_t)
  312. ')