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