mta.te 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. policy_module(mta, 2.8.6)
  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. init_rw_stream_sockets(system_mail_t)
  147. init_use_fds(system_mail_t)
  148. apt_use_fds(system_mail_t)
  149. apt_use_ptys(system_mail_t)
  150. optional_policy(`
  151. gen_require(`
  152. type crond_tmp_t;
  153. ')
  154. allow system_mail_t crond_tmp_t:file write;
  155. ')
  156. optional_policy(`
  157. apache_read_squirrelmail_data(system_mail_t)
  158. apache_append_squirrelmail_data(system_mail_t)
  159. apache_dontaudit_append_log(system_mail_t)
  160. apache_dontaudit_rw_stream_sockets(system_mail_t)
  161. apache_dontaudit_rw_tcp_sockets(system_mail_t)
  162. apache_dontaudit_rw_sys_script_stream_sockets(system_mail_t)
  163. ')
  164. optional_policy(`
  165. phpfpm_dontaudit_rw_stream_sockets(system_mail_t)
  166. phpfpm_dontaudit_rw_tcp_sockets(system_mail_t)
  167. ')
  168. optional_policy(`
  169. permit_in_unconfined_r(system_mail_t)
  170. unconfined_use_fds(system_mail_t)
  171. ')
  172. optional_policy(`
  173. arpwatch_manage_tmp_files(system_mail_t)
  174. ifdef(`hide_broken_symptoms',`
  175. arpwatch_dontaudit_rw_packet_sockets(system_mail_t)
  176. ')
  177. ')
  178. optional_policy(`
  179. bugzilla_search_content(system_mail_t)
  180. bugzilla_dontaudit_rw_stream_sockets(system_mail_t)
  181. ')
  182. optional_policy(`
  183. clamav_stream_connect(system_mail_t)
  184. clamav_append_log(system_mail_t)
  185. ')
  186. optional_policy(`
  187. cron_read_system_job_tmp_files(system_mail_t)
  188. cron_dontaudit_write_pipes(system_mail_t)
  189. cron_rw_system_job_stream_sockets(system_mail_t)
  190. ')
  191. optional_policy(`
  192. courier_stream_connect_authdaemon(system_mail_t)
  193. ')
  194. optional_policy(`
  195. cvs_read_data(system_mail_t)
  196. ')
  197. optional_policy(`
  198. fail2ban_dontaudit_rw_stream_sockets(system_mail_t)
  199. fail2ban_append_log(system_mail_t)
  200. fail2ban_rw_inherited_tmp_files(system_mail_t)
  201. ')
  202. optional_policy(`
  203. logrotate_read_tmp_files(system_mail_t)
  204. ')
  205. optional_policy(`
  206. logwatch_read_tmp_files(system_mail_t)
  207. ')
  208. optional_policy(`
  209. milter_getattr_all_sockets(system_mail_t)
  210. ')
  211. optional_policy(`
  212. nagios_read_tmp_files(system_mail_t)
  213. ')
  214. optional_policy(`
  215. manage_dirs_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  216. manage_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  217. manage_lnk_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  218. manage_fifo_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  219. manage_sock_files_pattern(system_mail_t, etc_aliases_t, etc_aliases_t)
  220. files_etc_filetrans(system_mail_t, etc_aliases_t, { file lnk_file sock_file fifo_file })
  221. ')
  222. optional_policy(`
  223. sxid_read_log(system_mail_t)
  224. ')
  225. optional_policy(`
  226. userdom_dontaudit_use_user_ptys(system_mail_t)
  227. optional_policy(`
  228. cron_dontaudit_append_system_job_tmp_files(system_mail_t)
  229. ')
  230. ')
  231. optional_policy(`
  232. spamassassin_stream_connect_spamd(system_mail_t)
  233. ')
  234. optional_policy(`
  235. smartmon_read_tmp_files(system_mail_t)
  236. ')
  237. ########################################
  238. #
  239. # MTA user agent local policy
  240. #
  241. userdom_use_user_terminals(mta_user_agent)
  242. optional_policy(`
  243. apache_append_log(mta_user_agent)
  244. ')
  245. optional_policy(`
  246. arpwatch_manage_tmp_files(mta_user_agent)
  247. ifdef(`hide_broken_symptoms',`
  248. arpwatch_dontaudit_rw_packet_sockets(mta_user_agent)
  249. ')
  250. optional_policy(`
  251. cron_read_system_job_tmp_files(mta_user_agent)
  252. ')
  253. ')
  254. ########################################
  255. #
  256. # Mailserver delivery local policy
  257. #
  258. allow mailserver_delivery self:fifo_file rw_fifo_file_perms;
  259. allow mailserver_delivery mail_spool_t:dir list_dir_perms;
  260. create_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  261. read_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  262. append_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  263. create_lnk_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  264. read_lnk_files_pattern(mailserver_delivery, mail_spool_t, mail_spool_t)
  265. manage_dirs_pattern(mailserver_delivery, mail_home_rw_t, mail_home_rw_t)
  266. manage_files_pattern(mailserver_delivery, { mail_home_t mail_home_rw_t }, { mail_home_t mail_home_rw_t })
  267. manage_lnk_files_pattern(mailserver_delivery, mail_home_rw_t, mail_home_rw_t)
  268. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, ".esmtp_queue")
  269. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, ".forward")
  270. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, ".mailrc")
  271. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_t, file, "dead.letter")
  272. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_rw_t, dir, "Maildir")
  273. userdom_user_home_dir_filetrans(mailserver_delivery, mail_home_rw_t, dir, ".maildir")
  274. read_files_pattern(mailserver_delivery, system_mail_tmp_t, system_mail_tmp_t)
  275. tunable_policy(`use_samba_home_dirs',`
  276. fs_manage_cifs_dirs(mailserver_delivery)
  277. fs_manage_cifs_files(mailserver_delivery)
  278. fs_read_cifs_symlinks(mailserver_delivery)
  279. ')
  280. tunable_policy(`use_nfs_home_dirs',`
  281. fs_manage_nfs_dirs(mailserver_delivery)
  282. fs_manage_nfs_files(mailserver_delivery)
  283. fs_read_nfs_symlinks(mailserver_delivery)
  284. ')
  285. optional_policy(`
  286. arpwatch_search_data(mailserver_delivery)
  287. ')
  288. optional_policy(`
  289. dovecot_manage_spool(mailserver_delivery)
  290. dovecot_domtrans_deliver(mailserver_delivery)
  291. ')
  292. optional_policy(`
  293. files_search_var_lib(mailserver_delivery)
  294. mailman_domtrans(mailserver_delivery)
  295. mailman_read_data_symlinks(mailserver_delivery)
  296. ')
  297. optional_policy(`
  298. postfix_rw_inherited_master_pipes(mailserver_delivery)
  299. ')
  300. optional_policy(`
  301. uucp_domtrans_uux(mailserver_delivery)
  302. ')
  303. ########################################
  304. #
  305. # User local policy
  306. #
  307. manage_files_pattern(user_mail_t, mail_home_t, mail_home_t)
  308. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, ".esmtp_queue")
  309. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, ".forward")
  310. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, ".mailrc")
  311. userdom_user_home_dir_filetrans(user_mail_t, mail_home_t, file, "dead.letter")
  312. dev_read_sysfs(user_mail_t)
  313. userdom_use_user_terminals(user_mail_t)
  314. mta_manage_aliases(user_mail_t)
  315. optional_policy(`
  316. allow user_mail_t self:capability dac_override;
  317. userdom_rw_user_tmp_files(user_mail_t)
  318. postfix_read_config(user_mail_t)
  319. postfix_list_spool(user_mail_t)
  320. ')