summaryrefslogtreecommitdiff
path: root/policy/modules/services/ssh.te
blob: 6296c6b479bc166209fc542db7f82ddc70c256f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

policy_module(ssh,1.3.5)

########################################
#
# Declarations
#

attribute ssh_server;

# ssh client executable.
type ssh_exec_t;
corecmd_executable_file(ssh_exec_t)

type ssh_keygen_exec_t;
corecmd_executable_file(ssh_keygen_exec_t)

type ssh_keysign_exec_t;
corecmd_executable_file(ssh_keysign_exec_t)

# real declaration moved to mls until
# range_transition works in loadable modules
gen_require(`
	type sshd_exec_t;
')
corecmd_executable_file(sshd_exec_t)

type sshd_key_t;
files_type(sshd_key_t)

ifdef(`targeted_policy',`
	unconfined_alias_domain(sshd_t)
	init_system_domain(sshd_t,sshd_exec_t)

	type sshd_var_run_t;
	files_type(sshd_var_run_t)
',`
	# Type for the ssh-agent executable.
	type ssh_agent_exec_t;
	files_type(ssh_agent_exec_t)

	type ssh_keygen_t;
	init_system_domain(ssh_keygen_t,ssh_keygen_exec_t)
	role system_r types ssh_keygen_t;

	ssh_server_template(sshd)
	ssh_server_template(sshd_extern)

	# cjp: commenting this out until typeattribute works in a conditional
#	optional_policy(`
#		tunable_policy(`run_ssh_inetd',`
#			inetd_tcp_service_domain(sshd_t,sshd_exec_t)
#		',`
#			init_daemon_domain(sshd_t,sshd_exec_t)
#		')
#	',`
		# These rules should match the else block
		# of the run_ssh_inetd tunable directly above
		init_daemon_domain(sshd_t,sshd_exec_t)
#	')

	type sshd_tmp_t;
	files_tmp_file(sshd_tmp_t)
')

#################################
#
# sshd local policy
#
# sshd_t is the domain for the sshd program.
#

ifdef(`strict_policy',`
	# so a tunnel can point to another ssh tunnel
	allow sshd_t self:tcp_socket { acceptfrom connectto recvfrom };
	allow sshd_t self:netlink_route_socket r_netlink_socket_perms;

	allow sshd_t sshd_tmp_t:dir create_dir_perms;
	allow sshd_t sshd_tmp_t:file create_file_perms;
	allow sshd_t sshd_tmp_t:sock_file create_file_perms;
	files_tmp_filetrans(sshd_t, sshd_tmp_t, { dir file sock_file })

	# for X forwarding
	corenet_tcp_bind_xserver_port(sshd_t)
	corenet_sendrecv_xserver_server_packets(sshd_t)

	mls_file_read_up(sshd_t)
	mls_file_write_down(sshd_t)
	mls_file_upgrade(sshd_t)
	mls_file_downgrade(sshd_t)
	mls_process_set_level(sshd_t)

	auth_exec_pam(sshd_t)

	seutil_read_config(sshd_t)

	tunable_policy(`ssh_sysadm_login',`
		# Relabel and access ptys created by sshd
		# ioctl is necessary for logout() processing for utmp entry and for w to
		# display the tty.
		# some versions of sshd on the new SE Linux require setattr
		term_use_all_user_ptys(sshd_t)
		term_setattr_all_user_ptys(sshd_t)
		term_relabelto_all_user_ptys(sshd_t)

		userdom_spec_domtrans_all_users(sshd_t)
		userdom_signal_all_users(sshd_t)
	',`
		userdom_spec_domtrans_unpriv_users(sshd_t)
		userdom_signal_unpriv_users(sshd_t)

		userdom_setattr_unpriv_users_ptys(sshd_t)
		userdom_relabelto_unpriv_users_ptys(sshd_t)
		userdom_use_unpriv_users_ptys(sshd_t)
	')

	optional_policy(`
		daemontools_service_domain(sshd_t, sshd_exec_t)
	')

	optional_policy(`
		rpm_use_script_fds(sshd_t)
	')

	optional_policy(`
		rssh_spec_domtrans_all_users(sshd_t)
		# For reading /home/user/.ssh
		rssh_read_all_users_ro_content(sshd_t)
	')

	ifdef(`TODO',`
	tunable_policy(`ssh_sysadm_login',`
		# Relabel and access ptys created by sshd
		# ioctl is necessary for logout() processing for utmp entry and for w to
		# display the tty.
		# some versions of sshd on the new SE Linux require setattr
		allow sshd_t ptyfile:chr_file relabelto;

		optional_policy(`
			domain_trans(sshd_t, xauth_exec_t, userdomain)
		')
	',`
		optional_policy(`
			domain_trans(sshd_t, xauth_exec_t, unpriv_userdomain)
		')
		# Relabel and access ptys created by sshd
		# ioctl is necessary for logout() processing for utmp entry and for w to
		# display the tty.
		# some versions of sshd on the new SE Linux require setattr
		allow sshd_t userpty_type:chr_file { relabelto read write getattr ioctl setattr };
	')
	') dnl endif TODO
')

#################################
#
# sshd_extern local policy
#
# sshd_extern_t is the domain for ssh from outside our network
#

ifdef(`strict_policy',`
	ifdef(`TODO',`
	domain_trans(sshd_extern_t, shell_exec_t, user_mini_domain)
	# Signal the user domains.
	allow sshd_extern_t user_mini_domain:process signal;

	ifdef(`xauth.te', `
	domain_trans(sshd_extern_t, xauth_exec_t, user_mini_domain)
	')

	# Relabel and access ptys created by sshd
	# ioctl is necessary for logout() processing for utmp entry and for w to
	# display the tty.
	# some versions of sshd on the new SE Linux require setattr
	allow sshd_extern_t user_mini_domain:chr_file { relabelto read write getattr ioctl setattr };

	# inheriting stream sockets is needed for "ssh host command" as no pty
	# is allocated
	allow user_mini_domain sshd_extern_t:unix_stream_socket rw_stream_socket_perms;

	optional_policy(`
		tunable_policy(`run_ssh_inetd',`
			domain_trans(inetd_t, sshd_exec_t, sshd_extern_t)
		',`
			domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
		')
	',`
		# These rules should match the else block
		# of the run_ssh_inetd tunable directly above
		domain_trans(initrc_t, sshd_exec_t, sshd_extern_t)
	')

	ifdef(`direct_sysadm_daemon', `
	# Direct execution by sysadm_r.
	domain_auto_trans(sysadm_t, sshd_exec_t, sshd_t)
	role_transition sysadm_r sshd_exec_t system_r;
	')

	# for port forwarding
	allow userdomain sshd_t:tcp_socket { connectto recvfrom };
	allow sshd_t userdomain:tcp_socket { acceptfrom recvfrom };
	allow userdomain kernel_t:tcp_socket recvfrom;
	allow sshd_t kernel_t:tcp_socket recvfrom;
	') dnl endif TODO
')

########################################
#
# ssh_keygen local policy
#

ifdef(`targeted_policy',`',`
	# ssh_keygen_t is the type of the ssh-keygen program when run at install time
	# and by sysadm_t

	dontaudit ssh_keygen_t self:capability sys_tty_config;
	allow ssh_keygen_t self:process { sigchld sigkill sigstop signull signal };

	allow ssh_keygen_t self:unix_stream_socket create_stream_socket_perms;

	allow ssh_keygen_t sshd_key_t:file create_file_perms;
	files_etc_filetrans(ssh_keygen_t,sshd_key_t,file)

	kernel_read_kernel_sysctls(ssh_keygen_t)

	fs_search_auto_mountpoints(ssh_keygen_t)

	dev_read_sysfs(ssh_keygen_t)
	dev_read_urand(ssh_keygen_t)

	term_dontaudit_use_console(ssh_keygen_t)

	domain_use_interactive_fds(ssh_keygen_t)

	files_read_etc_files(ssh_keygen_t)

	init_use_fds(ssh_keygen_t)
	init_use_script_ptys(ssh_keygen_t)

	libs_use_ld_so(ssh_keygen_t)
	libs_use_shared_libs(ssh_keygen_t)

	logging_send_syslog_msg(ssh_keygen_t)

	allow ssh_keygen_t proc_t:dir r_dir_perms;
	allow ssh_keygen_t proc_t:lnk_file read;

	userdom_use_sysadm_ttys(ssh_keygen_t)
	userdom_dontaudit_use_unpriv_user_fds(ssh_keygen_t)

	# cjp: with the old daemon_(base_)domain being broken up into
	# a daemon and system interface, this probably is not needed:
	ifdef(`direct_sysadm_daemon',`
		userdom_dontaudit_use_sysadm_terms(ssh_keygen_t)
	')

	ifdef(`targeted_policy', `
		term_dontaudit_use_unallocated_ttys(ssh_keygen_t)
		term_dontaudit_use_generic_ptys(ssh_keygen_t)
		files_dontaudit_read_root_files(ssh_keygen_t)
	')

	optional_policy(`
		seutil_sigchld_newrole(ssh_keygen_t)
	')

	optional_policy(`
		udev_read_db(ssh_keygen_t)
	')
')