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