]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - policy/modules/services/ssh.te
Sudo patch from Dan Walsh.
[people/stevee/selinux-policy.git] / policy / modules / services / ssh.te
CommitLineData
0404a390 1
cde15072 2policy_module(ssh, 2.1.1)
0404a390
CP
3
4########################################
5#
6# Declarations
7#
8
56e1b3d2
CP
9## <desc>
10## <p>
11## allow host key based authentication
12## </p>
13## </desc>
0bfccda4 14gen_tunable(allow_ssh_keysign, false)
56e1b3d2
CP
15
16## <desc>
17## <p>
18## Allow ssh logins as sysadm_r:sysadm_t
19## </p>
20## </desc>
0bfccda4 21gen_tunable(ssh_sysadm_login, false)
56e1b3d2 22
45239964 23attribute ssh_server;
296273a7 24attribute ssh_agent_type;
0404a390 25
75beb950 26type ssh_keygen_t;
0404a390 27type ssh_keygen_exec_t;
0bfccda4 28init_system_domain(ssh_keygen_t, ssh_keygen_exec_t)
75beb950 29role system_r types ssh_keygen_t;
0404a390 30
e070dd2d 31type sshd_exec_t;
fb63d0b5 32corecmd_executable_file(sshd_exec_t)
c3812748 33
6b19be33 34ssh_server_template(sshd)
0bfccda4 35init_daemon_domain(sshd_t, sshd_exec_t)
6b19be33 36
375c2415
CP
37type sshd_key_t;
38files_type(sshd_key_t)
9ccd96df 39
6b19be33
CP
40type sshd_tmp_t;
41files_tmp_file(sshd_tmp_t)
42files_poly_parent(sshd_tmp_t)
e070dd2d 43
6b19be33 44ifdef(`enable_mcs',`
3f67f722 45 init_ranged_daemon_domain(sshd_t, sshd_exec_t, s0 - mcs_systemhigh)
375c2415 46')
0404a390 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 };
80files_type(ssh_home_t)
81userdom_user_home_content(ssh_home_t)
296273a7
CP
82
83##############################
84#
85# SSH client local policy
86#
87
88allow ssh_t self:capability { setuid setgid dac_override dac_read_search };
89allow ssh_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
90allow ssh_t self:fd use;
91allow ssh_t self:fifo_file rw_fifo_file_perms;
92allow ssh_t self:unix_dgram_socket { create_socket_perms sendto };
93allow ssh_t self:unix_stream_socket { create_stream_socket_perms connectto };
94allow ssh_t self:shm create_shm_perms;
95allow ssh_t self:sem create_sem_perms;
96allow ssh_t self:msgq create_msgq_perms;
97allow ssh_t self:msg { send receive };
cde15072 98allow ssh_t self:tcp_socket create_stream_socket_perms;
296273a7
CP
99
100# Read the ssh key file.
101allow ssh_t sshd_key_t:file read_file_perms;
102
103# Access the ssh temporary files.
104allow ssh_t sshd_tmp_t:dir manage_dir_perms;
105allow ssh_t sshd_tmp_t:file manage_file_perms;
106files_tmp_filetrans(ssh_t, sshd_tmp_t, { file dir })
107
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 })
296273a7
CP
117
118# Allow the ssh program to communicate with ssh-agent.
119stream_connect_pattern(ssh_t, ssh_agent_tmp_t, ssh_agent_tmp_t, ssh_agent_type)
120
121allow ssh_t sshd_t:unix_stream_socket connectto;
122
123# ssh client can manage the keys and config
edc2f7de
CP
124manage_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
125read_lnk_files_pattern(ssh_t, ssh_home_t, ssh_home_t)
296273a7
CP
126
127# ssh servers can read the user keys and config
cde15072
CP
128allow ssh_server ssh_home_t:dir list_dir_perms;
129read_files_pattern(ssh_server, ssh_home_t, ssh_home_t)
130read_lnk_files_pattern(ssh_server, ssh_home_t, ssh_home_t)
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)
142
143dev_read_urand(ssh_t)
144
145fs_getattr_all_fs(ssh_t)
146fs_search_auto_mountpoints(ssh_t)
147
148# run helper programs - needed eg for x11-ssh-askpass
149corecmd_exec_shell(ssh_t)
150corecmd_exec_bin(ssh_t)
151
152domain_use_interactive_fds(ssh_t)
153
154files_list_home(ssh_t)
155files_read_usr_files(ssh_t)
156files_read_etc_runtime_files(ssh_t)
157files_read_etc_files(ssh_t)
158files_read_var_files(ssh_t)
159
160logging_send_syslog_msg(ssh_t)
161logging_read_generic_logs(ssh_t)
162
cde15072
CP
163auth_use_nsswitch(ssh_t)
164
296273a7
CP
165miscfiles_read_localization(ssh_t)
166
167seutil_read_config(ssh_t)
168
296273a7
CP
169userdom_dontaudit_list_user_home_dirs(ssh_t)
170userdom_search_user_home_dirs(ssh_t)
171# Write to the user domain tty.
172userdom_use_user_terminals(ssh_t)
173# needs to read krb tgt
174userdom_read_user_tmp_files(ssh_t)
175
176tunable_policy(`allow_ssh_keysign',`
177 domain_auto_trans(ssh_t, ssh_keysign_exec_t, ssh_keysign_t)
178 allow ssh_keysign_t ssh_t:fd use;
179 allow ssh_keysign_t ssh_t:process sigchld;
180 allow ssh_keysign_t ssh_t:fifo_file rw_file_perms;
181')
182
296273a7
CP
183tunable_policy(`use_nfs_home_dirs',`
184 fs_manage_nfs_dirs(ssh_t)
185 fs_manage_nfs_files(ssh_t)
186')
187
188tunable_policy(`use_samba_home_dirs',`
189 fs_manage_cifs_dirs(ssh_t)
190 fs_manage_cifs_files(ssh_t)
191')
192
193# for port forwarding
194tunable_policy(`user_tcp_server',`
195 corenet_tcp_bind_ssh_port(ssh_t)
cde15072 196 corenet_tcp_bind_generic_node(ssh_t)
296273a7
CP
197')
198
199optional_policy(`
200 xserver_user_x_domain_template(ssh, ssh_t, ssh_tmpfs_t)
201 xserver_domtrans_xauth(ssh_t)
202')
203
204########################################
205#
206# ssh_keygen local policy
207#
208
209# ssh_keygen_t is the type of the ssh-keygen program when run at install time
210# and by sysadm_t
211
212dontaudit ssh_keygen_t self:capability sys_tty_config;
213allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };
214
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
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 };
bbdbdb9e 284
0bfccda4
CP
285manage_dirs_pattern(sshd_t, sshd_tmp_t, sshd_tmp_t)
286manage_files_pattern(sshd_t, sshd_tmp_t, sshd_tmp_t)
287manage_sock_files_pattern(sshd_t, sshd_tmp_t, sshd_tmp_t)
6b19be33 288files_tmp_filetrans(sshd_t, sshd_tmp_t, { dir file sock_file })
44d5d93f 289
6b19be33
CP
290kernel_search_key(sshd_t)
291kernel_link_key(sshd_t)
292
296273a7
CP
293term_use_all_user_ptys(sshd_t)
294term_setattr_all_user_ptys(sshd_t)
295term_relabelto_all_user_ptys(sshd_t)
296
6b19be33
CP
297# for X forwarding
298corenet_tcp_bind_xserver_port(sshd_t)
299corenet_sendrecv_xserver_server_packets(sshd_t)
300
6b19be33
CP
301tunable_policy(`ssh_sysadm_login',`
302 # Relabel and access ptys created by sshd
303 # ioctl is necessary for logout() processing for utmp entry and for w to
304 # display the tty.
305 # some versions of sshd on the new SE Linux require setattr
6b19be33
CP
306 userdom_spec_domtrans_all_users(sshd_t)
307 userdom_signal_all_users(sshd_t)
308',`
309 userdom_spec_domtrans_unpriv_users(sshd_t)
310 userdom_signal_unpriv_users(sshd_t)
6b19be33
CP
311')
312
cde15072
CP
313optional_policy(`
314 kerberos_keytab_template(sshd, sshd_t)
315')
316
6b19be33
CP
317optional_policy(`
318 daemontools_service_domain(sshd_t, sshd_exec_t)
319')
320
321optional_policy(`
322 inetd_tcp_service_domain(sshd_t, sshd_exec_t)
323')
324
325optional_policy(`
326 rpm_use_script_fds(sshd_t)
327')
328
329optional_policy(`
296273a7 330 rssh_spec_domtrans(sshd_t)
6b19be33 331 # For reading /home/user/.ssh
296273a7 332 rssh_read_ro_content(sshd_t)
6b19be33
CP
333')
334
350b6ab7
CP
335optional_policy(`
336 unconfined_domain(sshd_t)
337 unconfined_shell_domtrans(sshd_t)
338')
339
6b19be33
CP
340ifdef(`TODO',`
341tunable_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;
375c2415 347
5540e76a 348 optional_policy(`
6b19be33 349 domain_trans(sshd_t, xauth_exec_t, userdomain)
5540e76a 350 ')
6b19be33
CP
351',`
352 optional_policy(`
353 domain_trans(sshd_t, xauth_exec_t, unpriv_userdomain)
0404a390 354 ')
6b19be33
CP
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
359 allow sshd_t userpty_type:chr_file { relabelto read write getattr ioctl setattr };
9ccd96df 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
75beb950
CP
371dontaudit ssh_keygen_t self:capability sys_tty_config;
372allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };
0404a390 373
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
75beb950 379kernel_read_kernel_sysctls(ssh_keygen_t)
0404a390 380
75beb950 381fs_search_auto_mountpoints(ssh_keygen_t)
ab940a4c 382
75beb950
CP
383dev_read_sysfs(ssh_keygen_t)
384dev_read_urand(ssh_keygen_t)
0404a390 385
75beb950 386term_dontaudit_use_console(ssh_keygen_t)
0404a390 387
75beb950 388domain_use_interactive_fds(ssh_keygen_t)
0404a390 389
75beb950 390files_read_etc_files(ssh_keygen_t)
0404a390 391
75beb950
CP
392init_use_fds(ssh_keygen_t)
393init_use_script_ptys(ssh_keygen_t)
0404a390 394
cde15072
CP
395auth_use_nsswitch(ssh_keygen_t)
396
75beb950 397logging_send_syslog_msg(ssh_keygen_t)
0404a390 398
75beb950 399userdom_dontaudit_use_unpriv_user_fds(ssh_keygen_t)
0404a390 400
75beb950
CP
401optional_policy(`
402 seutil_sigchld_newrole(ssh_keygen_t)
403')
404
405optional_policy(`
406 udev_read_db(ssh_keygen_t)
c0d1566a 407')