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