aboutsummaryrefslogtreecommitdiff
blob: ca82fb38acfcc62442b2c15cf462a78235043af1 (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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
policy_module(ipsec, 1.21.0)

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

## <desc>
## <p>
## Allow racoon to read shadow
## </p>
## </desc>
gen_tunable(racoon_read_shadow, false)

type ipsec_t;
type ipsec_exec_t;
init_daemon_domain(ipsec_t, ipsec_exec_t)
role system_r types ipsec_t;

# type for ipsec configuration file(s) - not for keys
type ipsec_conf_file_t;
files_type(ipsec_conf_file_t)

type ipsec_initrc_exec_t;
init_script_file(ipsec_initrc_exec_t)

# type for file(s) containing ipsec keys - RSA or preshared
type ipsec_key_file_t;
files_type(ipsec_key_file_t)

type ipsec_log_t;
logging_log_file(ipsec_log_t)

# Default type for IPSEC SPD entries
type ipsec_spd_t;
corenet_spd_type(ipsec_spd_t)

type ipsec_tmp_t;
files_tmp_file(ipsec_tmp_t)

type ipsec_unit_t;
init_unit_file(ipsec_unit_t)

# type for runtime files, including pluto.ctl
type ipsec_var_run_t;
files_pid_file(ipsec_var_run_t)

type ipsec_mgmt_t;
type ipsec_mgmt_exec_t;
init_system_domain(ipsec_mgmt_t, ipsec_mgmt_exec_t)
corecmd_shell_entry_type(ipsec_mgmt_t)
role system_r types ipsec_mgmt_t;

type ipsec_mgmt_lock_t;
files_lock_file(ipsec_mgmt_lock_t)

type ipsec_mgmt_var_run_t;
files_pid_file(ipsec_mgmt_var_run_t)

type ipsec_supervisor_t;
type ipsec_supervisor_exec_t;
init_daemon_domain(ipsec_supervisor_t, ipsec_supervisor_exec_t)
role system_r types ipsec_supervisor_t;

type racoon_t;
type racoon_exec_t;
init_daemon_domain(racoon_t, racoon_exec_t)
role system_r types racoon_t;

type racoon_tmp_t;
files_tmp_file(racoon_tmp_t)

type setkey_t;
type setkey_exec_t;
init_system_domain(setkey_t, setkey_exec_t)
role system_r types setkey_t;

########################################
#
# ipsec Local policy
#

allow ipsec_t self:capability { chown dac_override dac_read_search net_admin setgid setpcap setuid sys_nice };
dontaudit ipsec_t self:capability { sys_ptrace sys_tty_config };
allow ipsec_t self:process { getcap setcap getsched signal setsched };
allow ipsec_t self:tcp_socket create_stream_socket_perms;
allow ipsec_t self:udp_socket create_socket_perms;
allow ipsec_t self:key_socket create_socket_perms;
allow ipsec_t self:fifo_file rw_fifo_file_perms;
allow ipsec_t self:netlink_xfrm_socket create_netlink_socket_perms;
allow ipsec_t self:netlink_route_socket rw_netlink_socket_perms;

allow ipsec_t ipsec_initrc_exec_t:file read_file_perms;

allow ipsec_t ipsec_conf_file_t:dir list_dir_perms;
read_files_pattern(ipsec_t, ipsec_conf_file_t, ipsec_conf_file_t)
read_lnk_files_pattern(ipsec_t, ipsec_conf_file_t, ipsec_conf_file_t)

allow ipsec_t ipsec_key_file_t:dir list_dir_perms;
manage_files_pattern(ipsec_t, ipsec_key_file_t, ipsec_key_file_t)
read_lnk_files_pattern(ipsec_t, ipsec_key_file_t, ipsec_key_file_t)

manage_dirs_pattern(ipsec_t, ipsec_tmp_t, ipsec_tmp_t)
manage_files_pattern(ipsec_t, ipsec_tmp_t, ipsec_tmp_t)
files_tmp_filetrans(ipsec_t, ipsec_tmp_t, { dir file })

manage_dirs_pattern(ipsec_t, ipsec_var_run_t, ipsec_var_run_t)
manage_files_pattern(ipsec_t, ipsec_var_run_t, ipsec_var_run_t)
manage_sock_files_pattern(ipsec_t, ipsec_var_run_t, ipsec_var_run_t)
files_pid_filetrans(ipsec_t, ipsec_var_run_t, { dir file sock_file })

can_exec(ipsec_t, ipsec_mgmt_exec_t)

# pluto runs an updown script (by calling popen()!) as this is by default
# a shell script, we need to find a way to make things work without
# letting all sorts of stuff possibly be run...
# so try flipping back into the ipsec_mgmt_t domain
corecmd_shell_domtrans(ipsec_t, ipsec_mgmt_t)
allow ipsec_mgmt_t ipsec_t:fd use;
allow ipsec_mgmt_t ipsec_t:fifo_file rw_fifo_file_perms;
allow ipsec_mgmt_t ipsec_t:unix_stream_socket { read write };
allow ipsec_mgmt_t ipsec_t:process { rlimitinh sigchld };

kernel_read_kernel_sysctls(ipsec_t)
kernel_rw_net_sysctls(ipsec_t)
kernel_list_proc(ipsec_t)
kernel_read_proc_symlinks(ipsec_t)
# allow pluto to access /proc/net/ipsec_eroute;
kernel_read_system_state(ipsec_t)
kernel_read_network_state(ipsec_t)
kernel_read_software_raid_state(ipsec_t)
kernel_request_load_module(ipsec_t)
kernel_getattr_core_if(ipsec_t)
kernel_getattr_message_if(ipsec_t)

corecmd_exec_shell(ipsec_t)
corecmd_exec_bin(ipsec_t)

# Pluto needs network access
corenet_all_recvfrom_unlabeled(ipsec_t)
corenet_tcp_sendrecv_all_if(ipsec_t)
corenet_raw_sendrecv_all_if(ipsec_t)
corenet_tcp_sendrecv_all_nodes(ipsec_t)
corenet_raw_sendrecv_all_nodes(ipsec_t)
corenet_tcp_sendrecv_all_ports(ipsec_t)
corenet_tcp_bind_all_nodes(ipsec_t)
corenet_udp_bind_all_nodes(ipsec_t)
corenet_tcp_bind_reserved_port(ipsec_t)
corenet_tcp_bind_isakmp_port(ipsec_t)
corenet_udp_bind_isakmp_port(ipsec_t)
corenet_udp_bind_ipsecnat_port(ipsec_t)
corenet_sendrecv_generic_server_packets(ipsec_t)
corenet_sendrecv_isakmp_server_packets(ipsec_t)
# allow pluto to build Security Association Database
corenet_setcontext_all_spds(ipsec_t)

dev_read_sysfs(ipsec_t)
dev_read_rand(ipsec_t)
dev_read_urand(ipsec_t)

domain_use_interactive_fds(ipsec_t)
# allow pluto to set contexts on ipsec policy and SAs
domain_ipsec_setcontext_all_domains(ipsec_t)

files_list_tmp(ipsec_t)
files_read_etc_files(ipsec_t)
files_read_usr_files(ipsec_t)
files_dontaudit_search_home(ipsec_t)

fs_getattr_all_fs(ipsec_t)
fs_search_auto_mountpoints(ipsec_t)

term_use_console(ipsec_t)
term_dontaudit_use_all_ttys(ipsec_t)

auth_use_nsswitch(ipsec_t)

init_use_fds(ipsec_t)
init_use_script_ptys(ipsec_t)

logging_send_syslog_msg(ipsec_t)

miscfiles_read_localization(ipsec_t)

sysnet_domtrans_ifconfig(ipsec_t)

userdom_dontaudit_use_unpriv_user_fds(ipsec_t)
userdom_dontaudit_search_user_home_dirs(ipsec_t)

optional_policy(`
	seutil_sigchld_newrole(ipsec_t)
')

optional_policy(`
	udev_read_db(ipsec_t)
')

########################################
#
# ipsec_mgmt Local policy
#

allow ipsec_mgmt_t self:capability { dac_override dac_read_search net_admin setpcap sys_nice };
dontaudit ipsec_mgmt_t self:capability { sys_ptrace sys_tty_config };
allow ipsec_mgmt_t self:process { getsched ptrace setrlimit setsched signal };
allow ipsec_mgmt_t self:unix_stream_socket create_stream_socket_perms;
allow ipsec_mgmt_t self:tcp_socket create_stream_socket_perms;
allow ipsec_mgmt_t self:udp_socket create_socket_perms;
allow ipsec_mgmt_t self:key_socket create_socket_perms;
allow ipsec_mgmt_t self:fifo_file rw_fifo_file_perms;

domtrans_pattern(ipsec_mgmt_t, ipsec_exec_t, ipsec_t)

# _realsetup needs to be able to cat /var/run/pluto.pid,
# run ps on that pid, and delete the file
read_files_pattern(ipsec_mgmt_t, ipsec_t, ipsec_t)
read_lnk_files_pattern(ipsec_mgmt_t, ipsec_t, ipsec_t)

allow ipsec_mgmt_t ipsec_conf_file_t:file read_file_perms;

manage_files_pattern(ipsec_mgmt_t, ipsec_key_file_t, ipsec_key_file_t)
manage_lnk_files_pattern(ipsec_mgmt_t, ipsec_key_file_t, ipsec_key_file_t)

allow ipsec_mgmt_t ipsec_mgmt_lock_t:file manage_file_perms;
files_lock_filetrans(ipsec_mgmt_t, ipsec_mgmt_lock_t, file)

manage_files_pattern(ipsec_mgmt_t, ipsec_log_t, ipsec_log_t)
logging_log_filetrans(ipsec_mgmt_t, ipsec_log_t, file)

manage_dirs_pattern(ipsec_mgmt_t, ipsec_tmp_t, ipsec_tmp_t)
manage_files_pattern(ipsec_mgmt_t, ipsec_tmp_t, ipsec_tmp_t)
files_tmp_filetrans(ipsec_mgmt_t, ipsec_tmp_t, { dir file })

allow ipsec_mgmt_t ipsec_mgmt_var_run_t:file manage_file_perms;
manage_files_pattern(ipsec_mgmt_t, ipsec_var_run_t, ipsec_var_run_t)
manage_lnk_files_pattern(ipsec_mgmt_t, ipsec_var_run_t, ipsec_var_run_t)
files_pid_filetrans(ipsec_mgmt_t, ipsec_mgmt_var_run_t, file)

allow ipsec_mgmt_t ipsec_var_run_t:sock_file manage_sock_file_perms;
files_pid_filetrans(ipsec_mgmt_t, ipsec_var_run_t, sock_file)

# logger, running in ipsec_mgmt_t needs to use sockets
allow ipsec_mgmt_t self:unix_dgram_socket { create connect write };
allow ipsec_mgmt_t ipsec_t:unix_dgram_socket { create connect write };

# whack needs to connect to pluto
stream_connect_pattern(ipsec_mgmt_t, ipsec_var_run_t, ipsec_var_run_t, ipsec_t)

can_exec(ipsec_mgmt_t, ipsec_mgmt_exec_t)
allow ipsec_mgmt_t ipsec_mgmt_exec_t:lnk_file read;

domtrans_pattern(ipsec_mgmt_t, ipsec_supervisor_exec_t, ipsec_supervisor_t)
allow ipsec_mgmt_t ipsec_supervisor_t:process { signal signull };

kernel_rw_net_sysctls(ipsec_mgmt_t)
# allow pluto to access /proc/net/ipsec_eroute;
kernel_read_system_state(ipsec_mgmt_t)
kernel_read_network_state(ipsec_mgmt_t)
kernel_read_software_raid_state(ipsec_mgmt_t)
kernel_read_kernel_sysctls(ipsec_mgmt_t)
kernel_getattr_core_if(ipsec_mgmt_t)
kernel_getattr_message_if(ipsec_mgmt_t)

files_read_kernel_symbol_table(ipsec_mgmt_t)
files_getattr_kernel_modules(ipsec_mgmt_t)

# the default updown script wants to run route
# the ipsec wrapper wants to run /usr/bin/logger (should we put
# it in its own domain?)
corecmd_exec_bin(ipsec_mgmt_t)
corecmd_exec_shell(ipsec_mgmt_t)

dev_read_rand(ipsec_mgmt_t)
dev_read_urand(ipsec_mgmt_t)

domain_use_interactive_fds(ipsec_mgmt_t)
# denials when ps tries to search /proc. Do not audit these denials.
domain_dontaudit_read_all_domains_state(ipsec_mgmt_t)
# suppress audit messages about unnecessary socket access
# cjp: this seems excessive
domain_dontaudit_rw_all_udp_sockets(ipsec_mgmt_t)
domain_dontaudit_rw_all_key_sockets(ipsec_mgmt_t)

files_read_etc_files(ipsec_mgmt_t)
files_exec_etc_files(ipsec_mgmt_t)
files_read_etc_runtime_files(ipsec_mgmt_t)
files_read_usr_files(ipsec_mgmt_t)
files_dontaudit_getattr_default_dirs(ipsec_mgmt_t)
files_dontaudit_getattr_default_files(ipsec_mgmt_t)
files_list_tmp(ipsec_mgmt_t)

fs_getattr_xattr_fs(ipsec_mgmt_t)
fs_list_tmpfs(ipsec_mgmt_t)

term_use_console(ipsec_mgmt_t)
term_dontaudit_getattr_unallocated_ttys(ipsec_mgmt_t)

auth_dontaudit_read_login_records(ipsec_mgmt_t)

init_read_utmp(ipsec_mgmt_t)
init_use_script_ptys(ipsec_mgmt_t)
init_exec_script_files(ipsec_mgmt_t)
init_use_fds(ipsec_mgmt_t)
init_labeled_script_domtrans(ipsec_mgmt_t, ipsec_initrc_exec_t)

logging_send_syslog_msg(ipsec_mgmt_t)

miscfiles_read_localization(ipsec_mgmt_t)

seutil_dontaudit_search_config(ipsec_mgmt_t)

sysnet_manage_config(ipsec_mgmt_t)
sysnet_domtrans_ifconfig(ipsec_mgmt_t)
sysnet_etc_filetrans_config(ipsec_mgmt_t)

userdom_use_user_terminals(ipsec_mgmt_t)

optional_policy(`
	consoletype_exec(ipsec_mgmt_t)
')

optional_policy(`
	hostname_exec(ipsec_mgmt_t)
')

optional_policy(`
	dbus_system_bus_client(ipsec_mgmt_t)
	dbus_connect_system_bus(ipsec_mgmt_t)

	optional_policy(`
		networkmanager_dbus_chat(ipsec_mgmt_t)
	')
')

optional_policy(`
	iptables_domtrans(ipsec_mgmt_t)
')

optional_policy(`
	modutils_domtrans(ipsec_mgmt_t)
')

optional_policy(`
	nscd_use(ipsec_mgmt_t)
')

########################################
#
# Racoon local policy
#

allow racoon_t self:capability { net_admin net_bind_service };
allow racoon_t self:netlink_route_socket create_netlink_socket_perms;
allow racoon_t self:unix_dgram_socket { connect create ioctl write };
allow racoon_t self:netlink_selinux_socket { bind create read };
allow racoon_t self:udp_socket create_socket_perms;
allow racoon_t self:key_socket create_socket_perms;
allow racoon_t self:fifo_file rw_fifo_file_perms;

manage_dirs_pattern(racoon_t, racoon_tmp_t, racoon_tmp_t)
manage_files_pattern(racoon_t, racoon_tmp_t, racoon_tmp_t)
files_tmp_filetrans(racoon_t, racoon_tmp_t, { dir file })

can_exec(racoon_t, racoon_exec_t)

can_exec(racoon_t, setkey_exec_t)

# manage pid file
manage_files_pattern(racoon_t, ipsec_var_run_t, ipsec_var_run_t)
manage_sock_files_pattern(racoon_t, ipsec_var_run_t, ipsec_var_run_t)
files_pid_filetrans(racoon_t, ipsec_var_run_t, file)

allow racoon_t ipsec_conf_file_t:dir list_dir_perms;
read_files_pattern(racoon_t, ipsec_conf_file_t, ipsec_conf_file_t)
read_lnk_files_pattern(racoon_t, ipsec_conf_file_t, ipsec_conf_file_t)

allow racoon_t ipsec_key_file_t:dir list_dir_perms;
read_files_pattern(racoon_t, ipsec_key_file_t, ipsec_key_file_t)
read_lnk_files_pattern(racoon_t, ipsec_key_file_t, ipsec_key_file_t)

kernel_read_system_state(racoon_t)
kernel_read_network_state(racoon_t)
kernel_request_load_module(racoon_t)

corecmd_exec_shell(racoon_t)
corecmd_exec_bin(racoon_t)

corenet_all_recvfrom_unlabeled(racoon_t)
corenet_tcp_sendrecv_all_if(racoon_t)
corenet_udp_sendrecv_all_if(racoon_t)
corenet_tcp_sendrecv_all_nodes(racoon_t)
corenet_udp_sendrecv_all_nodes(racoon_t)
corenet_tcp_bind_all_nodes(racoon_t)
corenet_udp_bind_all_nodes(racoon_t)
corenet_udp_bind_isakmp_port(racoon_t)
corenet_udp_bind_ipsecnat_port(racoon_t)

dev_read_urand(racoon_t)

# allow racoon to set contexts on ipsec policy and SAs
domain_ipsec_setcontext_all_domains(racoon_t)

files_read_etc_files(racoon_t)

fs_dontaudit_getattr_xattr_fs(racoon_t)

# allow racoon to use avc_has_perm to check context on proposed SA
selinux_compute_access_vector(racoon_t)

auth_use_nsswitch(racoon_t)

ipsec_setcontext_default_spd(racoon_t)

locallogin_use_fds(racoon_t)

logging_send_syslog_msg(racoon_t)
logging_send_audit_msgs(racoon_t)

miscfiles_read_localization(racoon_t)

sysnet_exec_ifconfig(racoon_t)

auth_can_read_shadow_passwords(racoon_t)
tunable_policy(`racoon_read_shadow',`
	auth_tunable_read_shadow(racoon_t)
')

########################################
#
# Setkey local policy
#

allow setkey_t self:capability net_admin;
allow setkey_t self:key_socket create_socket_perms;
allow setkey_t self:netlink_route_socket create_netlink_socket_perms;

allow setkey_t ipsec_conf_file_t:dir list_dir_perms;
read_files_pattern(setkey_t, ipsec_conf_file_t, ipsec_conf_file_t)
read_lnk_files_pattern(setkey_t, ipsec_conf_file_t, ipsec_conf_file_t)

kernel_request_load_module(setkey_t)

# allow setkey utility to set contexts on SA's and policy
domain_ipsec_setcontext_all_domains(setkey_t)

files_read_etc_files(setkey_t)

init_dontaudit_use_fds(setkey_t)
init_read_script_tmp_files(setkey_t)

# allow setkey to set the context for ipsec SAs and policy.
corenet_setcontext_all_spds(setkey_t)

locallogin_use_fds(setkey_t)

miscfiles_read_localization(setkey_t)

seutil_read_config(setkey_t)

userdom_use_user_terminals(setkey_t)

########################################
#
# ipsec_supervisor policy
#

allow ipsec_supervisor_t self:capability { dac_override dac_read_search kill net_admin };
allow ipsec_supervisor_t self:process { signal signull };
allow ipsec_supervisor_t self:fifo_file rw_fifo_file_perms;
allow ipsec_supervisor_t self:netlink_route_socket rw_netlink_socket_perms;
allow ipsec_supervisor_t self:netlink_xfrm_socket create_netlink_socket_perms;

allow ipsec_supervisor_t ipsec_conf_file_t:dir list_dir_perms;
read_files_pattern(ipsec_supervisor_t, ipsec_conf_file_t, ipsec_conf_file_t)

manage_files_pattern(ipsec_supervisor_t, ipsec_key_file_t, ipsec_key_file_t)

allow ipsec_supervisor_t ipsec_t:unix_stream_socket { connectto };
allow ipsec_supervisor_t ipsec_t:process { signal signull };

allow ipsec_supervisor_t ipsec_var_run_t:sock_file { rw_sock_file_perms unlink };
manage_dirs_pattern(ipsec_supervisor_t, ipsec_var_run_t, ipsec_var_run_t)
manage_files_pattern(ipsec_supervisor_t, ipsec_var_run_t, ipsec_var_run_t)
files_pid_filetrans(ipsec_supervisor_t, ipsec_var_run_t, { dir file sock_file })

domtrans_pattern(ipsec_supervisor_t, ipsec_exec_t, ipsec_t)

kernel_read_network_state(ipsec_supervisor_t)
kernel_read_system_state(ipsec_supervisor_t)
kernel_rw_net_sysctls(ipsec_supervisor_t)

corecmd_exec_bin(ipsec_supervisor_t)
corecmd_exec_shell(ipsec_supervisor_t)

dev_read_rand(ipsec_supervisor_t)
dev_read_urand(ipsec_supervisor_t)

files_read_etc_files(ipsec_supervisor_t)

logging_send_syslog_msg(ipsec_supervisor_t)

miscfiles_read_localization(ipsec_supervisor_t)

optional_policy(`
	modutils_domtrans(ipsec_supervisor_t)
')

ifdef(`distro_gentoo',`
	################################################
	#
	# racoon policy
	#

	allow racoon_t self:unix_stream_socket create_stream_socket_perms;

	selinux_getattr_fs(racoon_t)

	###############################################
	#
	# setkey policy
	#

	domain_use_interactive_fds(setkey_t)

	########################################
	#
	# ipsec_mgmt Local policy
	#

	optional_policy(`
		resolvconf_client_domain(ipsec_mgmt_t)
	')
')