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