]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/policy/modules/services/ssh.te
fix most templated interface calls outside of templates
[people/stevee/selinux-policy.git] / refpolicy / policy / modules / services / ssh.te
CommitLineData
0404a390 1
d3d27022 2policy_module(ssh,1.2.0)
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)
f6abfdb8
CP
114
115 userdom_setattr_unpriv_user_pty(sshd_t)
116 userdom_relabelto_unpriv_user_pty(sshd_t)
1815bad1 117 userdom_use_unpriv_users_ptys(sshd_t)
375c2415 118 ')
bbdbdb9e 119
44d5d93f
CP
120 optional_policy(`daemontools',`
121 daemontools_service_domain(sshd_t, sshd_exec_t)
122 ')
123
1328802a 124 optional_policy(`rpm',`
375c2415 125 rpm_use_script_fd(sshd_t)
0404a390 126 ')
375c2415
CP
127
128 ifdef(`TODO',`
129 tunable_policy(`ssh_sysadm_login',`
130 # Relabel and access ptys created by sshd
131 # ioctl is necessary for logout() processing for utmp entry and for w to
132 # display the tty.
133 # some versions of sshd on the new SE Linux require setattr
134 allow sshd_t ptyfile:chr_file relabelto;
135
1328802a 136 optional_policy(`xauth',`
375c2415
CP
137 domain_trans(sshd_t, xauth_exec_t, userdomain)
138 ')
139 ',`
1328802a 140 optional_policy(`xauth',`
375c2415
CP
141 domain_trans(sshd_t, xauth_exec_t, unpriv_userdomain)
142 ')
143 # Relabel and access ptys created by sshd
144 # ioctl is necessary for logout() processing for utmp entry and for w to
145 # display the tty.
146 # some versions of sshd on the new SE Linux require setattr
147 allow sshd_t userpty_type:chr_file { relabelto read write getattr ioctl setattr };
0404a390 148 ')
375c2415 149 ') dnl endif TODO
9ccd96df 150')
0404a390
CP
151
152#################################
153#
154# sshd_extern local policy
155#
156# sshd_extern_t is the domain for ssh from outside our network
157#
0404a390 158
375c2415
CP
159ifdef(`targeted_policy',`',`
160 ifdef(`TODO',`
161 domain_trans(sshd_extern_t, shell_exec_t, user_mini_domain)
162 # Signal the user domains.
163 allow sshd_extern_t user_mini_domain:process signal;
0404a390 164
375c2415
CP
165 ifdef(`xauth.te', `
166 domain_trans(sshd_extern_t, xauth_exec_t, user_mini_domain)
167 ')
0404a390 168
375c2415
CP
169 # Relabel and access ptys created by sshd
170 # ioctl is necessary for logout() processing for utmp entry and for w to
171 # display the tty.
172 # some versions of sshd on the new SE Linux require setattr
173 allow sshd_extern_t user_mini_domain:chr_file { relabelto read write getattr ioctl setattr };
174
175 # inheriting stream sockets is needed for "ssh host command" as no pty
176 # is allocated
177 allow user_mini_domain sshd_extern_t:unix_stream_socket rw_stream_socket_perms;
178
1328802a 179 optional_policy(`inetd',`
375c2415
CP
180 tunable_policy(`run_ssh_inetd',`
181 domain_trans(inetd_t, sshd_exec_t, sshd_extern_t)
182 ',`
183 domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
184 ')
9ccd96df 185 ',`
375c2415
CP
186 # These rules should match the else block
187 # of the run_ssh_inetd tunable directly above
0404a390 188 domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
9ccd96df 189 ')
0404a390 190
375c2415
CP
191 ifdef(`direct_sysadm_daemon', `
192 # Direct execution by sysadm_r.
193 domain_auto_trans(sysadm_t, sshd_exec_t, sshd_t)
194 role_transition sysadm_r sshd_exec_t system_r;
195 ')
0404a390 196
375c2415
CP
197 # for port forwarding
198 allow userdomain sshd_t:tcp_socket { connectto recvfrom };
199 allow sshd_t userdomain:tcp_socket { acceptfrom recvfrom };
200 allow userdomain kernel_t:tcp_socket recvfrom;
201 allow sshd_t kernel_t:tcp_socket recvfrom;
202 ') dnl endif TODO
203')
0404a390
CP
204
205########################################
206#
207# ssh_keygen local policy
208#
209
375c2415
CP
210ifdef(`targeted_policy',`',`
211 # ssh_keygen_t is the type of the ssh-keygen program when run at install time
212 # and by sysadm_t
0404a390 213
375c2415
CP
214 dontaudit ssh_keygen_t self:capability sys_tty_config;
215 allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };
0404a390 216
375c2415 217 allow ssh_keygen_t self:unix_stream_socket create_stream_socket_perms;
0404a390 218
375c2415 219 allow ssh_keygen_t sshd_key_t:file create_file_perms;
9d594986 220 files_filetrans_etc(ssh_keygen_t,sshd_key_t,file)
0404a390 221
445522dc 222 kernel_read_kernel_sysctls(ssh_keygen_t)
0404a390 223
375c2415 224 fs_search_auto_mountpoints(ssh_keygen_t)
ab940a4c 225
375c2415
CP
226 dev_read_sysfs(ssh_keygen_t)
227 dev_read_urand(ssh_keygen_t)
0404a390 228
375c2415 229 term_dontaudit_use_console(ssh_keygen_t)
0404a390 230
375c2415 231 domain_use_wide_inherit_fd(ssh_keygen_t)
0404a390 232
375c2415 233 files_read_etc_files(ssh_keygen_t)
0404a390 234
375c2415 235 init_use_fd(ssh_keygen_t)
1815bad1 236 init_use_script_ptys(ssh_keygen_t)
0404a390 237
375c2415
CP
238 libs_use_ld_so(ssh_keygen_t)
239 libs_use_shared_libs(ssh_keygen_t)
0404a390 240
375c2415 241 logging_send_syslog_msg(ssh_keygen_t)
0404a390 242
375c2415
CP
243 allow ssh_keygen_t proc_t:dir r_dir_perms;
244 allow ssh_keygen_t proc_t:lnk_file read;
0404a390 245
1815bad1 246 userdom_use_sysadm_ttys(ssh_keygen_t)
375c2415 247 userdom_dontaudit_use_unpriv_user_fd(ssh_keygen_t)
0404a390 248
375c2415
CP
249 # cjp: with the old daemon_(base_)domain being broken up into
250 # a daemon and system interface, this probably is not needed:
251 ifdef(`direct_sysadm_daemon',`
252 userdom_dontaudit_use_sysadm_terms(ssh_keygen_t)
253 ')
0404a390 254
375c2415 255 ifdef(`targeted_policy', `
1815bad1
CP
256 term_dontaudit_use_unallocated_ttys(ssh_keygen_t)
257 term_dontaudit_use_generic_ptys(ssh_keygen_t)
9e04f5c5 258 files_dontaudit_read_root_files(ssh_keygen_t)
375c2415 259 ')
0404a390 260
1328802a 261 optional_policy(`selinuxutil',`
375c2415
CP
262 seutil_sigchld_newrole(ssh_keygen_t)
263 ')
0404a390 264
1328802a 265 optional_policy(`udev',`
375c2415
CP
266 udev_read_db(ssh_keygen_t)
267 ')
c0d1566a 268')