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