ssh.te 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. policy_module(ssh, 2.8.0)
  2. ########################################
  3. #
  4. # Declarations
  5. #
  6. ## <desc>
  7. ## <p>
  8. ## allow host key based authentication
  9. ## </p>
  10. ## </desc>
  11. gen_tunable(allow_ssh_keysign, false)
  12. ## <desc>
  13. ## <p>
  14. ## Allow ssh logins as sysadm_r:sysadm_t
  15. ## </p>
  16. ## </desc>
  17. gen_tunable(ssh_sysadm_login, false)
  18. ## <desc>
  19. ## <p>
  20. ## Allow ssh to use gpg-agent
  21. ## </p>
  22. ## </desc>
  23. gen_tunable(ssh_use_gpg_agent, false)
  24. attribute ssh_server;
  25. attribute ssh_agent_type;
  26. type ssh_keygen_t;
  27. type ssh_keygen_exec_t;
  28. init_system_domain(ssh_keygen_t, ssh_keygen_exec_t)
  29. role system_r types ssh_keygen_t;
  30. type sshd_exec_t;
  31. corecmd_executable_file(sshd_exec_t)
  32. ssh_server_template(sshd)
  33. init_daemon_domain(sshd_t, sshd_exec_t)
  34. type sshd_key_t;
  35. files_type(sshd_key_t)
  36. type sshd_tmp_t;
  37. files_tmp_file(sshd_tmp_t)
  38. files_poly_parent(sshd_tmp_t)
  39. type sshd_keygen_unit_t;
  40. init_unit_file(sshd_keygen_unit_t)
  41. type sshd_unit_t;
  42. init_unit_file(sshd_unit_t)
  43. ifdef(`enable_mcs',`
  44. init_ranged_daemon_domain(sshd_t, sshd_exec_t, s0 - mcs_systemhigh)
  45. ')
  46. type ssh_t;
  47. type ssh_exec_t;
  48. typealias ssh_t alias { user_ssh_t staff_ssh_t sysadm_ssh_t };
  49. typealias ssh_t alias { auditadm_ssh_t secadm_ssh_t };
  50. userdom_user_application_domain(ssh_t, ssh_exec_t)
  51. type ssh_agent_exec_t;
  52. corecmd_executable_file(ssh_agent_exec_t)
  53. type ssh_agent_tmp_t;
  54. typealias ssh_agent_tmp_t alias { user_ssh_agent_tmp_t staff_ssh_agent_tmp_t sysadm_ssh_agent_tmp_t };
  55. typealias ssh_agent_tmp_t alias { auditadm_ssh_agent_tmp_t secadm_ssh_agent_tmp_t };
  56. userdom_user_tmp_file(ssh_agent_tmp_t)
  57. type ssh_keysign_t;
  58. type ssh_keysign_exec_t;
  59. typealias ssh_keysign_t alias { user_ssh_keysign_t staff_ssh_keysign_t sysadm_ssh_keysign_t };
  60. typealias ssh_keysign_t alias { auditadm_ssh_keysign_t secadm_ssh_keysign_t };
  61. userdom_user_application_domain(ssh_keysign_t, ssh_keysign_exec_t)
  62. type ssh_tmpfs_t;
  63. typealias ssh_tmpfs_t alias { user_ssh_tmpfs_t staff_ssh_tmpfs_t sysadm_ssh_tmpfs_t };
  64. typealias ssh_tmpfs_t alias { auditadm_ssh_tmpfs_t secadm_ssh_tmpfs_t };
  65. userdom_user_tmpfs_file(ssh_tmpfs_t)
  66. type ssh_home_t;
  67. typealias ssh_home_t alias { home_ssh_t user_ssh_home_t user_home_ssh_t staff_home_ssh_t sysadm_home_ssh_t };
  68. typealias ssh_home_t alias { auditadm_home_ssh_t secadm_home_ssh_t };
  69. userdom_user_home_content(ssh_home_t)
  70. type sshd_keytab_t;
  71. files_type(sshd_keytab_t)
  72. ifdef(`distro_debian',`
  73. init_daemon_pid_file(sshd_var_run_t, dir, "sshd")
  74. ')
  75. ##############################
  76. #
  77. # SSH client local policy
  78. #
  79. allow ssh_t self:capability { setuid setgid dac_override dac_read_search };
  80. allow ssh_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
  81. allow ssh_t self:fd use;
  82. allow ssh_t self:fifo_file rw_fifo_file_perms;
  83. allow ssh_t self:unix_dgram_socket { create_socket_perms sendto };
  84. allow ssh_t self:unix_stream_socket { create_stream_socket_perms connectto };
  85. allow ssh_t self:shm create_shm_perms;
  86. allow ssh_t self:sem create_sem_perms;
  87. allow ssh_t self:msgq create_msgq_perms;
  88. allow ssh_t self:msg { send receive };
  89. allow ssh_t self:tcp_socket create_stream_socket_perms;
  90. # Read the ssh key file.
  91. allow ssh_t sshd_key_t:file read_file_perms;
  92. # Access the ssh temporary files.
  93. allow ssh_t sshd_tmp_t:dir manage_dir_perms;
  94. allow ssh_t sshd_tmp_t:file manage_file_perms;
  95. files_tmp_filetrans(ssh_t, sshd_tmp_t, { file dir })
  96. manage_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
  97. manage_lnk_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
  98. manage_fifo_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
  99. manage_sock_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
  100. fs_tmpfs_filetrans(ssh_t, ssh_tmpfs_t, { dir file lnk_file sock_file fifo_file })
  101. manage_dirs_pattern(ssh_t, ssh_home_t, ssh_home_t)
  102. manage_sock_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
  103. userdom_user_home_dir_filetrans(ssh_t, ssh_home_t, { dir sock_file })
  104. # Allow the ssh program to communicate with ssh-agent.
  105. stream_connect_pattern(ssh_t, ssh_agent_tmp_t, ssh_agent_tmp_t, ssh_agent_type)
  106. allow ssh_t sshd_t:unix_stream_socket connectto;
  107. # ssh client can manage the keys and config
  108. manage_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
  109. read_lnk_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
  110. # ssh servers can read the user keys and config
  111. allow ssh_server ssh_home_t:dir list_dir_perms;
  112. read_files_pattern(ssh_server, ssh_home_t, ssh_home_t)
  113. read_lnk_files_pattern(ssh_server, ssh_home_t, ssh_home_t)
  114. kernel_read_kernel_sysctls(ssh_t)
  115. kernel_read_system_state(ssh_t)
  116. corenet_all_recvfrom_unlabeled(ssh_t)
  117. corenet_all_recvfrom_netlabel(ssh_t)
  118. corenet_tcp_sendrecv_generic_if(ssh_t)
  119. corenet_tcp_sendrecv_generic_node(ssh_t)
  120. corenet_tcp_sendrecv_all_ports(ssh_t)
  121. corenet_tcp_connect_ssh_port(ssh_t)
  122. corenet_sendrecv_ssh_client_packets(ssh_t)
  123. dev_read_urand(ssh_t)
  124. fs_getattr_all_fs(ssh_t)
  125. fs_search_auto_mountpoints(ssh_t)
  126. # run helper programs - needed eg for x11-ssh-askpass
  127. corecmd_exec_shell(ssh_t)
  128. corecmd_exec_bin(ssh_t)
  129. domain_use_interactive_fds(ssh_t)
  130. files_list_home(ssh_t)
  131. files_read_usr_files(ssh_t)
  132. files_read_etc_runtime_files(ssh_t)
  133. files_read_etc_files(ssh_t)
  134. files_read_var_files(ssh_t)
  135. logging_send_syslog_msg(ssh_t)
  136. logging_read_generic_logs(ssh_t)
  137. auth_use_nsswitch(ssh_t)
  138. miscfiles_read_localization(ssh_t)
  139. seutil_read_config(ssh_t)
  140. userdom_dontaudit_list_user_home_dirs(ssh_t)
  141. userdom_search_user_home_dirs(ssh_t)
  142. # Write to the user domain tty.
  143. userdom_use_user_terminals(ssh_t)
  144. # needs to read krb tgt
  145. userdom_read_user_tmp_files(ssh_t)
  146. tunable_policy(`allow_ssh_keysign',`
  147. domain_auto_trans(ssh_t, ssh_keysign_exec_t, ssh_keysign_t)
  148. allow ssh_keysign_t ssh_t:fd use;
  149. allow ssh_keysign_t ssh_t:process sigchld;
  150. allow ssh_keysign_t ssh_t:fifo_file rw_file_perms;
  151. ')
  152. tunable_policy(`use_nfs_home_dirs',`
  153. fs_manage_nfs_dirs(ssh_t)
  154. fs_manage_nfs_files(ssh_t)
  155. ')
  156. tunable_policy(`use_samba_home_dirs',`
  157. fs_manage_cifs_dirs(ssh_t)
  158. fs_manage_cifs_files(ssh_t)
  159. ')
  160. # for port forwarding
  161. tunable_policy(`user_tcp_server',`
  162. corenet_tcp_bind_ssh_port(ssh_t)
  163. corenet_tcp_bind_generic_node(ssh_t)
  164. ')
  165. optional_policy(`
  166. tunable_policy(`ssh_use_gpg_agent',`
  167. gpg_stream_connect_agent(ssh_t)
  168. ')
  169. ')
  170. optional_policy(`
  171. xserver_user_x_domain_template(ssh, ssh_t, ssh_tmpfs_t)
  172. xserver_domtrans_xauth(ssh_t)
  173. ')
  174. ##############################
  175. #
  176. # ssh_keysign_t local policy
  177. #
  178. allow ssh_keysign_t self:capability { setgid setuid };
  179. allow ssh_keysign_t self:unix_stream_socket create_socket_perms;
  180. allow ssh_keysign_t sshd_key_t:file { getattr read };
  181. dev_read_urand(ssh_keysign_t)
  182. files_read_etc_files(ssh_keysign_t)
  183. optional_policy(`
  184. nscd_use(ssh_keysign_t)
  185. ')
  186. #################################
  187. #
  188. # sshd local policy
  189. #
  190. # sshd_t is the domain for the sshd program.
  191. #
  192. # so a tunnel can point to another ssh tunnel
  193. allow sshd_t self:netlink_route_socket r_netlink_socket_perms;
  194. allow sshd_t self:key { search link write };
  195. allow sshd_t self:capability net_admin;
  196. allow sshd_t sshd_keytab_t:file read_file_perms;
  197. manage_dirs_pattern(sshd_t, sshd_tmp_t, sshd_tmp_t)
  198. manage_files_pattern(sshd_t, sshd_tmp_t, sshd_tmp_t)
  199. manage_sock_files_pattern(sshd_t, sshd_tmp_t, sshd_tmp_t)
  200. files_tmp_filetrans(sshd_t, sshd_tmp_t, { dir file sock_file })
  201. kernel_search_key(sshd_t)
  202. kernel_link_key(sshd_t)
  203. term_use_all_ptys(sshd_t)
  204. term_setattr_all_ptys(sshd_t)
  205. term_relabelto_all_ptys(sshd_t)
  206. # for X forwarding
  207. corenet_tcp_bind_xserver_port(sshd_t)
  208. corenet_sendrecv_xserver_server_packets(sshd_t)
  209. ifdef(`distro_debian',`
  210. allow sshd_t self:process { getcap setcap };
  211. ')
  212. ifdef(`init_systemd',`
  213. systemd_dbus_chat_logind(sshd_t)
  214. init_rw_stream_sockets(sshd_t)
  215. ')
  216. tunable_policy(`ssh_sysadm_login',`
  217. # Relabel and access ptys created by sshd
  218. # ioctl is necessary for logout() processing for utmp entry and for w to
  219. # display the tty.
  220. # some versions of sshd on the new SE Linux require setattr
  221. userdom_spec_domtrans_all_users(sshd_t)
  222. userdom_signal_all_users(sshd_t)
  223. ',`
  224. userdom_spec_domtrans_unpriv_users(sshd_t)
  225. userdom_signal_unpriv_users(sshd_t)
  226. ')
  227. optional_policy(`
  228. systemd_write_inherited_logind_sessions_pipes(sshd_t)
  229. systemd_dbus_chat_logind(sshd_t)
  230. ')
  231. optional_policy(`
  232. daemontools_service_domain(sshd_t, sshd_exec_t)
  233. ')
  234. optional_policy(`
  235. inetd_tcp_service_domain(sshd_t, sshd_exec_t)
  236. ')
  237. optional_policy(`
  238. kerberos_read_keytab(sshd_t)
  239. kerberos_use(sshd_t)
  240. ')
  241. optional_policy(`
  242. oddjob_domtrans_mkhomedir(sshd_t)
  243. ')
  244. optional_policy(`
  245. rpm_use_script_fds(sshd_t)
  246. ')
  247. optional_policy(`
  248. rssh_spec_domtrans(sshd_t)
  249. # For reading /home/user/.ssh
  250. rssh_read_ro_content(sshd_t)
  251. ')
  252. optional_policy(`
  253. unconfined_shell_domtrans(sshd_t)
  254. ')
  255. optional_policy(`
  256. xserver_domtrans_xauth(sshd_t)
  257. ')
  258. ########################################
  259. #
  260. # ssh_keygen local policy
  261. #
  262. # ssh_keygen_t is the type of the ssh-keygen program when run at install time
  263. # and by sysadm_t
  264. dontaudit ssh_keygen_t self:capability sys_tty_config;
  265. allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };
  266. allow ssh_keygen_t self:unix_stream_socket create_stream_socket_perms;
  267. allow ssh_keygen_t sshd_key_t:file manage_file_perms;
  268. files_etc_filetrans(ssh_keygen_t, sshd_key_t, file)
  269. kernel_read_kernel_sysctls(ssh_keygen_t)
  270. fs_search_auto_mountpoints(ssh_keygen_t)
  271. dev_read_sysfs(ssh_keygen_t)
  272. dev_read_urand(ssh_keygen_t)
  273. term_dontaudit_use_console(ssh_keygen_t)
  274. domain_use_interactive_fds(ssh_keygen_t)
  275. files_read_etc_files(ssh_keygen_t)
  276. init_use_fds(ssh_keygen_t)
  277. init_use_script_ptys(ssh_keygen_t)
  278. auth_use_nsswitch(ssh_keygen_t)
  279. logging_send_syslog_msg(ssh_keygen_t)
  280. userdom_dontaudit_use_unpriv_user_fds(ssh_keygen_t)
  281. optional_policy(`
  282. seutil_sigchld_newrole(ssh_keygen_t)
  283. ')
  284. optional_policy(`
  285. udev_read_db(ssh_keygen_t)
  286. ')