]> git.ipfire.org Git - people/stevee/selinux-policy.git/blame - refpolicy/policy/modules/services/ssh.te
initial commit
[people/stevee/selinux-policy.git] / refpolicy / policy / modules / services / ssh.te
CommitLineData
0404a390
CP
1
2policy_module(ssh,1.0)
3
4########################################
5#
6# Declarations
7#
8
45239964 9attribute ssh_server;
0404a390
CP
10
11# Type for the ssh-agent executable.
12type ssh_agent_exec_t;
13files_file_type(ssh_agent_exec_t)
14
15# ssh client executable.
16type ssh_exec_t;
17files_file_type(ssh_exec_t)
18
19type ssh_keygen_t;
20type ssh_keygen_exec_t;
21init_daemon_domain(ssh_keygen_t,ssh_keygen_exec_t)
22role system_r types ssh_keygen_t;
23
9ccd96df
CP
24sshd_program_domain(sshd)
25
0404a390
CP
26type sshd_exec_t;
27files_file_type(sshd_exec_t)
28
9ccd96df
CP
29sshd_program_domain(sshd_extern)
30
0404a390
CP
31type sshd_key_t;
32files_file_type(sshd_key_t)
33
34type sshd_tmp_t;
35files_tmp_file(sshd_tmp_t)
36
37#################################
38#
39# sshd local policy
40#
41# sshd_t is the domain for the sshd program.
42#
43
9ccd96df
CP
44# so a tunnel can point to another ssh tunnel
45allow sshd_t self:tcp_socket { acceptfrom connectto recvfrom };
0404a390
CP
46
47allow sshd_t sshd_tmp_t:dir create_dir_perms;
48allow sshd_t sshd_tmp_t:file create_file_perms;
49allow sshd_t sshd_tmp_t:sock_file create_file_perms;
50files_create_tmp_files(sshd_t, sshd_tmp_t, { dir file sock_file })
51
52# for X forwarding
53corenet_tcp_bind_xserver_port(sshd_t)
54
55auth_exec_pam(sshd_t)
56
57seutil_read_config(sshd_t)
58
9ccd96df
CP
59# Allow checking users mail at login
60mta_getattr_spool(sshd_t)
61
62optional_policy(`inetd.te',`
63 tunable_policy(`run_ssh_inetd',`
64 inetd_service_domain(sshd_t,sshd_exec_t)
65 ',`
66 init_daemon_domain(sshd_t,sshd_exec_t)
67 ')
68',`
69 # These rules should match the else block
70 # of the run_ssh_inetd tunable directly above
71 init_daemon_domain(sshd_t,sshd_exec_t)
72')
73
0404a390 74ifdef(`TODO',`
9ccd96df 75tunable_policy(`ssh_sysadm_login',`
0404a390
CP
76 userdom_spec_domtrans_all_users(sshd_t)
77 userdom_signal_all_users(sshd_t)
78
9ccd96df 79 optional_policy(`xauth.te',`
0404a390
CP
80 domain_trans(sshd_t, xauth_exec_t, userdomain)
81 ')
82 # Relabel and access ptys created by sshd
83 # ioctl is necessary for logout() processing for utmp entry and for w to
84 # display the tty.
85 # some versions of sshd on the new SE Linux require setattr
86 allow sshd_t ptyfile:chr_file { relabelto read write getattr ioctl setattr };
87 # inheriting stream sockets is needed for "ssh host command" as no pty
88 # is allocated
89 allow userdomain sshd_t:unix_stream_socket rw_stream_socket_perms;
9ccd96df 90',`
0404a390
CP
91 userdom_spec_domtrans_unpriv_users(sshd_t)
92 userdom_signal_unpriv_users(sshd_t)
93
9ccd96df 94 optional_policy(`xauth.te',`
0404a390
CP
95 domain_trans(sshd_t, xauth_exec_t, unpriv_userdomain)
96 ')
97 # Relabel and access ptys created by sshd
98 # ioctl is necessary for logout() processing for utmp entry and for w to
99 # display the tty.
100 # some versions of sshd on the new SE Linux require setattr
101 allow sshd_t userpty_type:chr_file { relabelto read write getattr ioctl setattr };
102 # inheriting stream sockets is needed for "ssh host command" as no pty
103 # is allocated
104 allow userdomain sshd_t:unix_stream_socket rw_stream_socket_perms;
9ccd96df
CP
105')
106
107# this goes to inetd
108tunable_policy(`run_ssh_inetd',`
109 corenet_tcp_bind_ssh_port(inetd_t)
110')
0404a390
CP
111
112# for when the network connection breaks after running newrole -r sysadm_r
113dontaudit sshd_t sysadm_devpts_t:chr_file setattr;
114
ab940a4c
CP
115optional_policy(`rpm.te',`
116allow sshd_t rpm_script_t:fd use;
117')
0404a390
CP
118') dnl endif TODO
119
120#################################
121#
122# sshd_extern local policy
123#
124# sshd_extern_t is the domain for ssh from outside our network
125#
0404a390 126
9ccd96df 127ifdef(`TODO',`
0404a390
CP
128domain_trans(sshd_extern_t, shell_exec_t, user_mini_domain)
129# Signal the user domains.
130allow sshd_extern_t user_mini_domain:process signal;
131
132ifdef(`xauth.te', `
133domain_trans(sshd_extern_t, xauth_exec_t, user_mini_domain)
134')
135
136# Relabel and access ptys created by sshd
137# ioctl is necessary for logout() processing for utmp entry and for w to
138# display the tty.
139# some versions of sshd on the new SE Linux require setattr
140allow sshd_extern_t user_mini_domain:chr_file { relabelto read write getattr ioctl setattr };
141
142# inheriting stream sockets is needed for "ssh host command" as no pty
143# is allocated
144allow user_mini_domain sshd_extern_t:unix_stream_socket rw_stream_socket_perms;
145
146optional_policy(`inetd.te',`
9ccd96df 147 tunable_policy(`run_ssh_inetd',`
0404a390 148 domain_trans(inetd_t, sshd_exec_t, sshd_extern_t)
9ccd96df 149 ',`
0404a390 150 domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
9ccd96df 151 ')
0404a390
CP
152',`
153 # These rules should match the else block
9ccd96df 154 # of the run_ssh_inetd tunable directly above
0404a390 155 domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
0404a390
CP
156')
157
158ifdef(`direct_sysadm_daemon', `
159# Direct execution by sysadm_r.
160domain_auto_trans(sysadm_t, sshd_exec_t, sshd_t)
161role_transition sysadm_r sshd_exec_t system_r;
162')
163
164# so a tunnel can point to another ssh tunnel...
0404a390
CP
165allow sshd_t kernel_t:tcp_socket recvfrom;
166allow sshd_t kernel_t:tcp_socket recvfrom;
167
168# for port forwarding
169allow userdomain sshd_t:tcp_socket { connectto recvfrom };
170allow sshd_t userdomain:tcp_socket { acceptfrom recvfrom };
171allow userdomain kernel_t:tcp_socket recvfrom;
172allow sshd_t kernel_t:tcp_socket recvfrom;
173') dnl endif TODO
174
175########################################
176#
177# ssh_keygen local policy
178#
179
180# ssh_keygen_t is the type of the ssh-keygen program when run at install time
181# and by sysadm_t
182
183dontaudit ssh_keygen_t self:capability sys_tty_config;
184allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };
185
186allow ssh_keygen_t self:unix_stream_socket create_stream_socket_perms;
187
188allow ssh_keygen_t sshd_key_t:file create_file_perms;
189files_create_etc_config(ssh_keygen_t,sshd_key_t,file)
190
191kernel_read_kernel_sysctl(ssh_keygen_t)
192
ab940a4c
CP
193fs_search_auto_mountpoints(ssh_keygen_t)
194
0404a390
CP
195dev_read_sysfs(ssh_keygen_t)
196dev_read_urand(ssh_keygen_t)
197
198term_dontaudit_use_console(ssh_keygen_t)
199
200domain_use_wide_inherit_fd(ssh_keygen_t)
201
202files_read_generic_etc_files(ssh_keygen_t)
203
204init_use_fd(ssh_keygen_t)
205init_use_script_pty(ssh_keygen_t)
206
207libs_use_ld_so(ssh_keygen_t)
208libs_use_shared_libs(ssh_keygen_t)
209
210logging_send_syslog_msg(ssh_keygen_t)
211
212allow ssh_keygen_t proc_t:dir r_dir_perms;
213allow ssh_keygen_t proc_t:lnk_file read;
214
215userdom_use_sysadm_tty(ssh_keygen_t)
216userdom_dontaudit_use_unpriv_user_fd(ssh_keygen_t)
217
218ifdef(`direct_sysadm_daemon',`
219 userdom_dontaudit_use_sysadm_terms(ssh_keygen_t)
220')
221
222ifdef(`targeted_policy', `
223 term_dontaudit_use_unallocated_tty(ssh_keygen_t)
224 term_dontaudit_use_generic_pty(ssh_keygen_t)
225 files_dontaudit_read_root_file(ssh_keygen_t)
226')
227
228optional_policy(`rhgb.te', `
229 rhgb_domain(ssh_keygen_t)
230')
231
232optional_policy(`selinux.te',`
233 seutil_newrole_sigchld(ssh_keygen_t)
234')
235
236optional_policy(`udev.te', `
237 udev_read_db(ssh_keygen_t)
238')