]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/policy/modules/services/ssh.te
add slocate from dan
[people/stevee/selinux-policy.git] / refpolicy / policy / modules / services / ssh.te
CommitLineData
0404a390 1
bf080a46 2policy_module(ssh,1.1.1)
0404a390
CP
3
4########################################
5#
6# Declarations
7#
8
45239964 9attribute ssh_server;
0404a390 10
0404a390
CP
11# ssh client executable.
12type ssh_exec_t;
8fd36732 13files_type(ssh_exec_t)
0404a390 14
0404a390 15type ssh_keygen_exec_t;
375c2415 16files_type(ssh_keygen_exec_t)
0404a390 17
a0824843
CP
18type ssh_keysign_exec_t;
19files_type(ssh_keysign_exec_t)
20
c3812748
CP
21# real declaration moved to mls until
22# range_transition works in loadable modules
23gen_require(`
24 type sshd_exec_t;
25')
26files_type(sshd_exec_t)
27
375c2415
CP
28type sshd_key_t;
29files_type(sshd_key_t)
9ccd96df 30
375c2415
CP
31ifdef(`targeted_policy',`
32 unconfined_alias_domain(sshd_t)
33 init_system_domain(sshd_t,sshd_exec_t)
2d13f729
CP
34
35 type sshd_var_run_t;
36 files_type(sshd_var_run_t)
b488014f
CP
37
38 # FIXME
39 typeattribute ssh_exec_t entry_type;
40 typeattribute ssh_keygen_exec_t entry_type;
41 typeattribute ssh_keysign_exec_t entry_type;
375c2415
CP
42',`
43 # Type for the ssh-agent executable.
44 type ssh_agent_exec_t;
45 files_type(ssh_agent_exec_t)
46
47 type ssh_keygen_t;
48 init_system_domain(ssh_keygen_t,ssh_keygen_exec_t)
49 role system_r types ssh_keygen_t;
50
51 ssh_server_template(sshd)
52 ssh_server_template(sshd_extern)
53
54 # cjp: commenting this out until typeattribute works in a conditional
1328802a 55# optional_policy(`inetd',`
375c2415
CP
56# tunable_policy(`run_ssh_inetd',`
57# inetd_tcp_service_domain(sshd_t,sshd_exec_t)
58# ',`
59# init_daemon_domain(sshd_t,sshd_exec_t)
60# ')
80436b9b 61# ',`
375c2415
CP
62 # These rules should match the else block
63 # of the run_ssh_inetd tunable directly above
64 init_daemon_domain(sshd_t,sshd_exec_t)
80436b9b 65# ')
0404a390 66
375c2415
CP
67 type sshd_tmp_t;
68 files_tmp_file(sshd_tmp_t)
69')
0404a390
CP
70
71#################################
72#
73# sshd local policy
74#
75# sshd_t is the domain for the sshd program.
76#
77
375c2415
CP
78ifdef(`targeted_policy',`',`
79 # so a tunnel can point to another ssh tunnel
80 allow sshd_t self:tcp_socket { acceptfrom connectto recvfrom };
0404a390 81
375c2415
CP
82 allow sshd_t sshd_tmp_t:dir create_dir_perms;
83 allow sshd_t sshd_tmp_t:file create_file_perms;
84 allow sshd_t sshd_tmp_t:sock_file create_file_perms;
9d594986 85 files_filetrans_tmp(sshd_t, sshd_tmp_t, { dir file sock_file })
0404a390 86
375c2415
CP
87 # for X forwarding
88 corenet_tcp_bind_xserver_port(sshd_t)
0404a390 89
bf080a46
CP
90 mls_file_read_up(sshd_t)
91 mls_file_write_down(sshd_t)
92 mls_file_upgrade(sshd_t)
93 mls_file_downgrade(sshd_t)
94 mls_process_set_level(sshd_t)
95
375c2415 96 auth_exec_pam(sshd_t)
e5590ea5 97
375c2415 98 seutil_read_config(sshd_t)
e5590ea5 99
375c2415
CP
100 tunable_policy(`ssh_sysadm_login',`
101 # Relabel and access ptys created by sshd
102 # ioctl is necessary for logout() processing for utmp entry and for w to
103 # display the tty.
104 # some versions of sshd on the new SE Linux require setattr
105 term_use_all_user_ptys(sshd_t)
106 term_setattr_all_user_ptys(sshd_t)
107 term_relabelto_all_user_ptys(sshd_t)
108
109 userdom_spec_domtrans_all_users(sshd_t)
110 userdom_signal_all_users(sshd_t)
111 ',`
112 userdom_spec_domtrans_unpriv_users(sshd_t)
113 userdom_signal_unpriv_users(sshd_t)
114 ')
bbdbdb9e 115
1328802a 116 optional_policy(`rpm',`
375c2415 117 rpm_use_script_fd(sshd_t)
0404a390 118 ')
375c2415
CP
119
120 ifdef(`TODO',`
121 tunable_policy(`ssh_sysadm_login',`
122 # Relabel and access ptys created by sshd
123 # ioctl is necessary for logout() processing for utmp entry and for w to
124 # display the tty.
125 # some versions of sshd on the new SE Linux require setattr
126 allow sshd_t ptyfile:chr_file relabelto;
127
1328802a 128 optional_policy(`xauth',`
375c2415
CP
129 domain_trans(sshd_t, xauth_exec_t, userdomain)
130 ')
131 ',`
1328802a 132 optional_policy(`xauth',`
375c2415
CP
133 domain_trans(sshd_t, xauth_exec_t, unpriv_userdomain)
134 ')
135 # Relabel and access ptys created by sshd
136 # ioctl is necessary for logout() processing for utmp entry and for w to
137 # display the tty.
138 # some versions of sshd on the new SE Linux require setattr
139 allow sshd_t userpty_type:chr_file { relabelto read write getattr ioctl setattr };
0404a390 140 ')
375c2415 141 ') dnl endif TODO
9ccd96df 142')
0404a390
CP
143
144#################################
145#
146# sshd_extern local policy
147#
148# sshd_extern_t is the domain for ssh from outside our network
149#
0404a390 150
375c2415
CP
151ifdef(`targeted_policy',`',`
152 ifdef(`TODO',`
153 domain_trans(sshd_extern_t, shell_exec_t, user_mini_domain)
154 # Signal the user domains.
155 allow sshd_extern_t user_mini_domain:process signal;
0404a390 156
375c2415
CP
157 ifdef(`xauth.te', `
158 domain_trans(sshd_extern_t, xauth_exec_t, user_mini_domain)
159 ')
0404a390 160
375c2415
CP
161 # Relabel and access ptys created by sshd
162 # ioctl is necessary for logout() processing for utmp entry and for w to
163 # display the tty.
164 # some versions of sshd on the new SE Linux require setattr
165 allow sshd_extern_t user_mini_domain:chr_file { relabelto read write getattr ioctl setattr };
166
167 # inheriting stream sockets is needed for "ssh host command" as no pty
168 # is allocated
169 allow user_mini_domain sshd_extern_t:unix_stream_socket rw_stream_socket_perms;
170
1328802a 171 optional_policy(`inetd',`
375c2415
CP
172 tunable_policy(`run_ssh_inetd',`
173 domain_trans(inetd_t, sshd_exec_t, sshd_extern_t)
174 ',`
175 domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
176 ')
9ccd96df 177 ',`
375c2415
CP
178 # These rules should match the else block
179 # of the run_ssh_inetd tunable directly above
0404a390 180 domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
9ccd96df 181 ')
0404a390 182
375c2415
CP
183 ifdef(`direct_sysadm_daemon', `
184 # Direct execution by sysadm_r.
185 domain_auto_trans(sysadm_t, sshd_exec_t, sshd_t)
186 role_transition sysadm_r sshd_exec_t system_r;
187 ')
0404a390 188
375c2415
CP
189 # for port forwarding
190 allow userdomain sshd_t:tcp_socket { connectto recvfrom };
191 allow sshd_t userdomain:tcp_socket { acceptfrom recvfrom };
192 allow userdomain kernel_t:tcp_socket recvfrom;
193 allow sshd_t kernel_t:tcp_socket recvfrom;
194 ') dnl endif TODO
195')
0404a390
CP
196
197########################################
198#
199# ssh_keygen local policy
200#
201
375c2415
CP
202ifdef(`targeted_policy',`',`
203 # ssh_keygen_t is the type of the ssh-keygen program when run at install time
204 # and by sysadm_t
0404a390 205
375c2415
CP
206 dontaudit ssh_keygen_t self:capability sys_tty_config;
207 allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };
0404a390 208
375c2415 209 allow ssh_keygen_t self:unix_stream_socket create_stream_socket_perms;
0404a390 210
375c2415 211 allow ssh_keygen_t sshd_key_t:file create_file_perms;
9d594986 212 files_filetrans_etc(ssh_keygen_t,sshd_key_t,file)
0404a390 213
375c2415 214 kernel_read_kernel_sysctl(ssh_keygen_t)
0404a390 215
375c2415 216 fs_search_auto_mountpoints(ssh_keygen_t)
ab940a4c 217
375c2415
CP
218 dev_read_sysfs(ssh_keygen_t)
219 dev_read_urand(ssh_keygen_t)
0404a390 220
375c2415 221 term_dontaudit_use_console(ssh_keygen_t)
0404a390 222
375c2415 223 domain_use_wide_inherit_fd(ssh_keygen_t)
0404a390 224
375c2415 225 files_read_etc_files(ssh_keygen_t)
0404a390 226
375c2415
CP
227 init_use_fd(ssh_keygen_t)
228 init_use_script_pty(ssh_keygen_t)
0404a390 229
375c2415
CP
230 libs_use_ld_so(ssh_keygen_t)
231 libs_use_shared_libs(ssh_keygen_t)
0404a390 232
375c2415 233 logging_send_syslog_msg(ssh_keygen_t)
0404a390 234
375c2415
CP
235 allow ssh_keygen_t proc_t:dir r_dir_perms;
236 allow ssh_keygen_t proc_t:lnk_file read;
0404a390 237
375c2415
CP
238 userdom_use_sysadm_tty(ssh_keygen_t)
239 userdom_dontaudit_use_unpriv_user_fd(ssh_keygen_t)
0404a390 240
375c2415
CP
241 # cjp: with the old daemon_(base_)domain being broken up into
242 # a daemon and system interface, this probably is not needed:
243 ifdef(`direct_sysadm_daemon',`
244 userdom_dontaudit_use_sysadm_terms(ssh_keygen_t)
245 ')
0404a390 246
375c2415
CP
247 ifdef(`targeted_policy', `
248 term_dontaudit_use_unallocated_tty(ssh_keygen_t)
249 term_dontaudit_use_generic_pty(ssh_keygen_t)
250 files_dontaudit_read_root_file(ssh_keygen_t)
251 ')
0404a390 252
1328802a 253 optional_policy(`selinuxutil',`
375c2415
CP
254 seutil_sigchld_newrole(ssh_keygen_t)
255 ')
0404a390 256
1328802a 257 optional_policy(`udev',`
375c2415
CP
258 udev_read_db(ssh_keygen_t)
259 ')
c0d1566a 260')