]> git.ipfire.org Git - people/stevee/selinux-policy.git/blob - policy/modules/services/ssh.te
Add SELinux support for ssh pre-auth net process in F17
[people/stevee/selinux-policy.git] / policy / modules / services / ssh.te
1 policy_module(ssh, 2.2.0)
2
3 ########################################
4 #
5 # Declarations
6 #
7
8 ## <desc>
9 ## <p>
10 ## allow host key based authentication
11 ## </p>
12 ## </desc>
13 gen_tunable(allow_ssh_keysign, false)
14
15 ## <desc>
16 ## <p>
17 ## Allow ssh logins as sysadm_r:sysadm_t
18 ## </p>
19 ## </desc>
20 gen_tunable(ssh_sysadm_login, false)
21
22 ## <desc>
23 ## <p>
24 ## allow sshd to forward port connections
25 ## </p>
26 ## </desc>
27 gen_tunable(sshd_forward_ports, false)
28
29 ## <desc>
30 ## <p>
31 ## Allow ssh with chroot env to read and write files
32 ## in the user home directories
33 ## </p>
34 ## </desc>
35 gen_tunable(ssh_chroot_rw_homedirs, false)
36
37 attribute ssh_dyntrasition_domain;
38 attribute ssh_server;
39 attribute ssh_agent_type;
40
41 ssh_dyntransition_domain_template(chroot_user_t)
42 ssh_dyntransition_domain_template(sshd_sandbox_t)
43
44 type chroot_user_t;
45 domain_type(chroot_user_t)
46 role system_r types chroot_user_t;
47
48 type ssh_keygen_t;
49 type ssh_keygen_exec_t;
50 init_system_domain(ssh_keygen_t, ssh_keygen_exec_t)
51
52 type sshd_exec_t;
53 corecmd_executable_file(sshd_exec_t)
54
55 ssh_server_template(sshd)
56 init_daemon_domain(sshd_t, sshd_exec_t)
57
58 type sshd_initrc_exec_t;
59 init_script_file(sshd_initrc_exec_t)
60
61 type sshd_key_t;
62 files_type(sshd_key_t)
63
64 type ssh_t;
65 type ssh_exec_t;
66 typealias ssh_t alias { user_ssh_t staff_ssh_t sysadm_ssh_t };
67 typealias ssh_t alias { auditadm_ssh_t secadm_ssh_t };
68 application_domain(ssh_t, ssh_exec_t)
69 ubac_constrained(ssh_t)
70
71 type ssh_agent_exec_t;
72 corecmd_executable_file(ssh_agent_exec_t)
73
74 type ssh_agent_tmp_t;
75 typealias ssh_agent_tmp_t alias { user_ssh_agent_tmp_t staff_ssh_agent_tmp_t sysadm_ssh_agent_tmp_t };
76 typealias ssh_agent_tmp_t alias { auditadm_ssh_agent_tmp_t secadm_ssh_agent_tmp_t };
77 files_tmp_file(ssh_agent_tmp_t)
78 ubac_constrained(ssh_agent_tmp_t)
79
80 type ssh_keysign_t;
81 type ssh_keysign_exec_t;
82 typealias ssh_keysign_t alias { user_ssh_keysign_t staff_ssh_keysign_t sysadm_ssh_keysign_t };
83 typealias ssh_keysign_t alias { auditadm_ssh_keysign_t secadm_ssh_keysign_t };
84 application_domain(ssh_keysign_t, ssh_keysign_exec_t)
85 ubac_constrained(ssh_keysign_t)
86
87 type ssh_tmpfs_t;
88 typealias ssh_tmpfs_t alias { user_ssh_tmpfs_t staff_ssh_tmpfs_t sysadm_ssh_tmpfs_t };
89 typealias ssh_tmpfs_t alias { auditadm_ssh_tmpfs_t secadm_ssh_tmpfs_t };
90 files_tmpfs_file(ssh_tmpfs_t)
91 ubac_constrained(ssh_tmpfs_t)
92
93 type ssh_home_t;
94 typealias ssh_home_t alias { home_ssh_t user_ssh_home_t user_home_ssh_t staff_home_ssh_t sysadm_home_ssh_t };
95 typealias ssh_home_t alias { auditadm_home_ssh_t secadm_home_ssh_t };
96 userdom_user_home_content(ssh_home_t)
97 files_poly_parent(ssh_home_t)
98
99 ifdef(`enable_mcs',`
100 init_ranged_daemon_domain(sshd_t, sshd_exec_t, s0 - mcs_systemhigh)
101 ')
102
103 ##############################
104 #
105 # SSH client local policy
106 #
107
108 allow ssh_t self:capability { setuid setgid dac_override dac_read_search };
109 allow ssh_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
110 allow ssh_t self:fd use;
111 allow ssh_t self:fifo_file rw_fifo_file_perms;
112 allow ssh_t self:unix_dgram_socket { create_socket_perms sendto };
113 allow ssh_t self:unix_stream_socket { create_stream_socket_perms connectto };
114 allow ssh_t self:shm create_shm_perms;
115 allow ssh_t self:sem create_sem_perms;
116 allow ssh_t self:msgq create_msgq_perms;
117 allow ssh_t self:msg { send receive };
118 allow ssh_t self:tcp_socket create_stream_socket_perms;
119 can_exec(ssh_t, ssh_exec_t)
120
121 # Read the ssh key file.
122 allow ssh_t sshd_key_t:file read_file_perms;
123
124 manage_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
125 manage_lnk_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
126 manage_fifo_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
127 manage_sock_files_pattern(ssh_t, ssh_tmpfs_t, ssh_tmpfs_t)
128 fs_tmpfs_filetrans(ssh_t, ssh_tmpfs_t, { dir file lnk_file sock_file fifo_file })
129
130 manage_dirs_pattern(ssh_t, ssh_home_t, ssh_home_t)
131 manage_sock_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
132 userdom_user_home_dir_filetrans(ssh_t, ssh_home_t, { dir sock_file })
133 userdom_stream_connect(ssh_t)
134 userdom_search_admin_dir(sshd_t)
135 userdom_admin_home_dir_filetrans(ssh_t, ssh_home_t, { dir sock_file })
136
137 # Allow the ssh program to communicate with ssh-agent.
138 stream_connect_pattern(ssh_t, ssh_agent_tmp_t, ssh_agent_tmp_t, ssh_agent_type)
139
140 allow ssh_t sshd_t:unix_stream_socket connectto;
141 allow ssh_t sshd_t:peer recv;
142
143 # ssh client can manage the keys and config
144 manage_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
145 read_lnk_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
146
147 # ssh servers can read the user keys and config
148 manage_dirs_pattern(ssh_server, ssh_home_t, ssh_home_t)
149 manage_files_pattern(ssh_server, ssh_home_t, ssh_home_t)
150 userdom_user_home_dir_filetrans(ssh_server, ssh_home_t, dir)
151 userdom_admin_home_dir_filetrans(ssh_server, ssh_home_t, dir)
152
153 kernel_read_kernel_sysctls(ssh_t)
154 kernel_read_system_state(ssh_t)
155
156 corenet_all_recvfrom_unlabeled(ssh_t)
157 corenet_all_recvfrom_netlabel(ssh_t)
158 corenet_tcp_sendrecv_generic_if(ssh_t)
159 corenet_tcp_sendrecv_generic_node(ssh_t)
160 corenet_tcp_sendrecv_all_ports(ssh_t)
161 corenet_tcp_connect_ssh_port(ssh_t)
162 corenet_sendrecv_ssh_client_packets(ssh_t)
163 corenet_tcp_bind_generic_node(ssh_t)
164 corenet_tcp_bind_all_unreserved_ports(ssh_t)
165 corenet_rw_tun_tap_dev(ssh_t)
166
167 dev_read_rand(ssh_t)
168 dev_read_urand(ssh_t)
169
170 fs_getattr_all_fs(ssh_t)
171 fs_search_auto_mountpoints(ssh_t)
172
173 # run helper programs - needed eg for x11-ssh-askpass
174 corecmd_exec_shell(ssh_t)
175 corecmd_exec_bin(ssh_t)
176
177 domain_use_interactive_fds(ssh_t)
178
179 files_list_home(ssh_t)
180 files_read_usr_files(ssh_t)
181 files_read_etc_runtime_files(ssh_t)
182 files_read_etc_files(ssh_t)
183 files_read_var_files(ssh_t)
184
185 logging_send_syslog_msg(ssh_t)
186 logging_read_generic_logs(ssh_t)
187
188 auth_use_nsswitch(ssh_t)
189
190 miscfiles_read_localization(ssh_t)
191 miscfiles_read_generic_certs(ssh_t)
192
193 seutil_read_config(ssh_t)
194
195 userdom_dontaudit_list_user_home_dirs(ssh_t)
196 userdom_search_user_home_dirs(ssh_t)
197 userdom_search_admin_dir(ssh_t)
198 # Write to the user domain tty.
199 userdom_use_inherited_user_terminals(ssh_t)
200 # needs to read krb/write tgt
201 userdom_read_user_tmp_files(ssh_t)
202 userdom_write_user_tmp_files(ssh_t)
203 userdom_read_user_home_content_symlinks(ssh_t)
204 userdom_read_home_certs(ssh_t)
205
206 tunable_policy(`allow_ssh_keysign',`
207 domtrans_pattern(ssh_t, ssh_keysign_exec_t, ssh_keysign_t)
208 ')
209
210 tunable_policy(`use_fusefs_home_dirs',`
211 fs_manage_fusefs_dirs(ssh_t)
212 fs_manage_fusefs_files(ssh_t)
213 ')
214
215 tunable_policy(`use_nfs_home_dirs',`
216 fs_manage_nfs_dirs(ssh_t)
217 fs_manage_nfs_files(ssh_t)
218 ')
219
220 tunable_policy(`use_samba_home_dirs',`
221 fs_manage_cifs_dirs(ssh_t)
222 fs_manage_cifs_files(ssh_t)
223 ')
224
225 # for port forwarding
226 tunable_policy(`user_tcp_server',`
227 corenet_tcp_bind_ssh_port(ssh_t)
228 corenet_tcp_bind_generic_node(ssh_t)
229 ')
230
231 optional_policy(`
232 gnome_stream_connect_all_gkeyringd(ssh_t)
233 ')
234
235 optional_policy(`
236 xserver_user_x_domain_template(ssh, ssh_t, ssh_tmpfs_t)
237 xserver_domtrans_xauth(ssh_t)
238 ')
239
240
241 ##############################
242 #
243 # ssh_keysign_t local policy
244 #
245
246 tunable_policy(`allow_ssh_keysign',`
247 allow ssh_keysign_t self:capability { setgid setuid };
248 allow ssh_keysign_t self:unix_stream_socket create_socket_perms;
249
250 allow ssh_keysign_t sshd_key_t:file read_file_perms;
251
252 dev_read_rand(ssh_keysign_t)
253 dev_read_urand(ssh_keysign_t)
254
255 files_read_etc_files(ssh_keysign_t)
256 ')
257
258 #################################
259 #
260 # sshd local policy
261 #
262 # sshd_t is the domain for the sshd program.
263 #
264
265 # so a tunnel can point to another ssh tunnel
266 allow sshd_t self:netlink_route_socket r_netlink_socket_perms;
267 allow sshd_t self:key { search link write };
268 allow sshd_t self:process setcurrent;
269
270 kernel_search_key(sshd_t)
271 kernel_link_key(sshd_t)
272
273 term_use_all_ptys(sshd_t)
274 term_setattr_all_ptys(sshd_t)
275 term_setattr_all_ttys(sshd_t)
276 term_relabelto_all_ptys(sshd_t)
277 term_use_ptmx(sshd_t)
278
279 # for X forwarding
280 corenet_tcp_bind_xserver_port(sshd_t)
281 corenet_sendrecv_xserver_server_packets(sshd_t)
282
283 userdom_read_user_home_content_files(sshd_t)
284 userdom_read_user_home_content_symlinks(sshd_t)
285 userdom_manage_tmp_role(system_r, sshd_t)
286 userdom_spec_domtrans_unpriv_users(sshd_t)
287 userdom_signal_unpriv_users(sshd_t)
288 userdom_dyntransition_unpriv_users(sshd_t)
289
290 tunable_policy(`sshd_forward_ports',`
291 corenet_tcp_bind_all_unreserved_ports(sshd_t)
292 corenet_tcp_connect_all_ports(sshd_t)
293 ')
294
295 tunable_policy(`ssh_sysadm_login',`
296 # Relabel and access ptys created by sshd
297 # ioctl is necessary for logout() processing for utmp entry and for w to
298 # display the tty.
299 # some versions of sshd on the new SE Linux require setattr
300 userdom_signal_all_users(sshd_t)
301 userdom_spec_domtrans_all_users(sshd_t)
302 ')
303
304 optional_policy(`
305 amanda_search_var_lib(sshd_t)
306 ')
307
308 optional_policy(`
309 daemontools_service_domain(sshd_t, sshd_exec_t)
310 ')
311
312 optional_policy(`
313 kerberos_keytab_template(sshd, sshd_t)
314 ')
315
316 optional_policy(`
317 ftp_dyntrans_sftpd(sshd_t)
318 ftp_dyntrans_anon_sftpd(sshd_t)
319 ')
320
321 optional_policy(`
322 gitosis_manage_lib_files(sshd_t)
323 ')
324
325 optional_policy(`
326 inetd_tcp_service_domain(sshd_t, sshd_exec_t)
327 ')
328
329 optional_policy(`
330 nx_read_home_files(sshd_t)
331 ')
332
333 optional_policy(`
334 rpm_use_script_fds(sshd_t)
335 ')
336
337 optional_policy(`
338 rssh_spec_domtrans(sshd_t)
339 # For reading /home/user/.ssh
340 rssh_read_ro_content(sshd_t)
341 ')
342
343 optional_policy(`
344 systemd_exec_systemctl(sshd_t)
345 ')
346
347 optional_policy(`
348 usermanage_domtrans_passwd(sshd_t)
349 usermanage_read_crack_db(sshd_t)
350 ')
351
352 optional_policy(`
353 unconfined_shell_domtrans(sshd_t)
354 ')
355
356 optional_policy(`
357 xserver_domtrans_xauth(sshd_t)
358 ')
359
360 ifdef(`TODO',`
361 tunable_policy(`ssh_sysadm_login',`
362 # Relabel and access ptys created by sshd
363 # ioctl is necessary for logout() processing for utmp entry and for w to
364 # display the tty.
365 # some versions of sshd on the new SE Linux require setattr
366 allow sshd_t ptyfile:chr_file relabelto;
367
368 optional_policy(`
369 domain_trans(sshd_t, xauth_exec_t, userdomain)
370 ')
371 ',`
372 optional_policy(`
373 domain_trans(sshd_t, xauth_exec_t, unpriv_userdomain)
374 ')
375 # Relabel and access ptys created by sshd
376 # ioctl is necessary for logout() processing for utmp entry and for w to
377 # display the tty.
378 # some versions of sshd on the new SE Linux require setattr
379 allow sshd_t userpty_type:chr_file { relabelto rw_inherited_chr_file_perms setattr_chr_file_perms };
380 ')
381 ') dnl endif TODO
382
383 ########################################
384 #
385 # ssh_keygen local policy
386 #
387
388 # ssh_keygen_t is the type of the ssh-keygen program when run at install time
389 # and by sysadm_t
390
391 allow ssh_keygen_t self:capability dac_override;
392 dontaudit ssh_keygen_t self:capability sys_tty_config;
393 allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };
394 allow ssh_keygen_t self:unix_stream_socket create_stream_socket_perms;
395
396 allow ssh_keygen_t sshd_key_t:file manage_file_perms;
397 files_etc_filetrans(ssh_keygen_t, sshd_key_t, file)
398
399 manage_dirs_pattern(ssh_keygen_t, ssh_home_t, ssh_home_t)
400 manage_files_pattern(ssh_keygen_t, ssh_home_t, ssh_home_t)
401 userdom_admin_home_dir_filetrans(ssh_keygen_t, ssh_home_t, dir)
402 userdom_user_home_dir_filetrans(ssh_keygen_t, ssh_home_t, dir)
403
404 kernel_read_system_state(ssh_keygen_t)
405 kernel_read_kernel_sysctls(ssh_keygen_t)
406
407 fs_search_auto_mountpoints(ssh_keygen_t)
408
409 dev_read_sysfs(ssh_keygen_t)
410 dev_read_rand(ssh_keygen_t)
411 dev_read_urand(ssh_keygen_t)
412
413 term_dontaudit_use_console(ssh_keygen_t)
414
415 domain_use_interactive_fds(ssh_keygen_t)
416
417 files_read_etc_files(ssh_keygen_t)
418
419 init_use_fds(ssh_keygen_t)
420 init_use_script_ptys(ssh_keygen_t)
421
422 auth_use_nsswitch(ssh_keygen_t)
423
424 logging_send_syslog_msg(ssh_keygen_t)
425
426 userdom_dontaudit_use_unpriv_user_fds(ssh_keygen_t)
427 userdom_use_user_terminals(ssh_keygen_t)
428
429 optional_policy(`
430 seutil_sigchld_newrole(ssh_keygen_t)
431 ')
432
433 optional_policy(`
434 udev_read_db(ssh_keygen_t)
435 ')
436
437 ####################################
438 #
439 # ssh_dyntransition domain local policy
440 #
441
442 allow ssh_dyntransition_domain self:capability { setuid sys_chroot setgid };
443
444 allow ssh_dyntransition_domain self:fifo_file rw_fifo_file_perms;
445
446 optional_policy(`
447 ssh_rw_stream_sockets(ssh_dyntransition_domain)
448 ssh_rw_tcp_sockets(ssh_dyntransition_domain)
449 ')
450
451 #####################################
452 #
453 # ssh_sandbox local policy
454 #
455
456 allow sshd_t sshd_sandbox_t:process signal;
457
458 init_ioctl_stream_sockets(sshd_sandbox_t)
459
460 logging_send_audit_msgs(sshd_sandbox_t)
461
462 ######################################
463 #
464 # chroot_user_t local policy
465 #
466
467
468 userdom_read_user_home_content_files(chroot_user_t)
469 userdom_read_inherited_user_home_content_files(chroot_user_t)
470 userdom_read_user_home_content_symlinks(chroot_user_t)
471 userdom_exec_user_home_content_files(chroot_user_t)
472
473 tunable_policy(`ssh_chroot_rw_homedirs',`
474 files_list_home(chroot_user_t)
475 userdom_read_user_home_content_files(chroot_user_t)
476 userdom_manage_user_home_content(chroot_user_t)
477 ', `
478
479 userdom_user_home_dir_filetrans_pattern(chroot_user_t, { dir file lnk_file })
480 ')
481
482 tunable_policy(`ssh_chroot_rw_homedirs && use_nfs_home_dirs',`
483 fs_manage_nfs_dirs(chroot_user_t)
484 fs_manage_nfs_files(chroot_user_t)
485 fs_manage_nfs_symlinks(chroot_user_t)
486 ')
487
488 tunable_policy(`ssh_chroot_rw_homedirs && use_samba_home_dirs',`
489 fs_manage_cifs_dirs(chroot_user_t)
490 fs_manage_cifs_files(chroot_user_t)
491 fs_manage_cifs_symlinks(chroot_user_t)
492 ')
493
494 tunable_policy(`use_samba_home_dirs',`
495 fs_read_cifs_files(chroot_user_t)
496 fs_read_cifs_symlinks(chroot_user_t)
497 ')
498
499 tunable_policy(`use_nfs_home_dirs',`
500 fs_read_nfs_files(chroot_user_t)
501 fs_read_nfs_symlinks(chroot_user_t)
502 ')
503
504 optional_policy(`
505 ssh_rw_dgram_sockets(chroot_user_t)
506 ')