aboutsummaryrefslogtreecommitdiff
blob: c40c6b91f48a584c14d07d0787c5d3a3263793f0 (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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
## <summary>PostgreSQL relational database</summary>

#######################################
## <summary>
##	Role access for SE-PostgreSQL.
## </summary>
## <param name="role_prefix">
##	<summary>
##	The prefix of the user role (e.g., user
##	is the prefix for user_r).
##	</summary>
## </param>
## <param name="user_domain">
##	<summary>
##	User domain for the role.
##	</summary>
## </param>
## <param name="user_exec_domain">
##	<summary>
##	User exec domain for execute and transition access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access
##	</summary>
## </param>
#
template(`postgresql_role',`
	gen_require(`
		class db_database all_db_database_perms;
		class db_schema all_db_schema_perms;
		class db_table all_db_table_perms;
		class db_sequence all_db_sequence_perms;
		class db_view all_db_view_perms;
		class db_procedure all_db_procedure_perms;
		class db_language all_db_language_perms;
		class db_column all_db_column_perms;
		class db_tuple all_db_tuple_perms;
		class db_blob all_db_blob_perms;

		attribute sepgsql_client_type, sepgsql_database_type;
		attribute sepgsql_schema_type, sepgsql_sysobj_table_type;

		type sepgsql_trusted_proc_exec_t, sepgsql_trusted_proc_t;
		type sepgsql_ranged_proc_exec_t, sepgsql_ranged_proc_t;
		type user_sepgsql_blob_t, user_sepgsql_proc_exec_t;
		type user_sepgsql_schema_t, user_sepgsql_seq_t;
		type user_sepgsql_sysobj_t, user_sepgsql_table_t;
		type user_sepgsql_view_t;
		type sepgsql_temp_object_t;
	')

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

	typeattribute $2 sepgsql_client_type;
	role $4 types sepgsql_trusted_proc_t;
	role $4 types sepgsql_ranged_proc_t;

	##############################
	#
	# Client local policy
	#

	tunable_policy(`sepgsql_enable_users_ddl',`
		allow $2 user_sepgsql_schema_t:db_schema { create drop setattr };
		allow $2 user_sepgsql_table_t:db_table { create drop setattr };
		allow $2 user_sepgsql_table_t:db_column { create drop setattr };
		allow $2 user_sepgsql_sysobj_t:db_tuple { update insert delete };
		allow $2 user_sepgsql_seq_t:db_sequence { create drop setattr set_value };
		allow $2 user_sepgsql_view_t:db_view { create drop setattr };
		allow $2 user_sepgsql_proc_exec_t:db_procedure { create drop setattr };
	')

	allow $2 user_sepgsql_schema_t:db_schema { getattr search add_name remove_name };
	type_transition $2 sepgsql_database_type:db_schema user_sepgsql_schema_t;
	type_transition $2 sepgsql_database_type:db_schema sepgsql_temp_object_t "pg_temp";

	allow $2 user_sepgsql_table_t:db_table	{ getattr select update insert delete lock };
	allow $2 user_sepgsql_table_t:db_column { getattr select update insert };
	allow $2 user_sepgsql_table_t:db_tuple	{ select update insert delete };
	type_transition $2 sepgsql_schema_type:db_table user_sepgsql_table_t;

	allow $2 user_sepgsql_sysobj_t:db_tuple	{ use select };
	type_transition $2 sepgsql_sysobj_table_type:db_tuple user_sepgsql_sysobj_t;

	allow $2 user_sepgsql_seq_t:db_sequence { getattr get_value next_value };
	type_transition $2 sepgsql_schema_type:db_sequence user_sepgsql_seq_t;

	allow $2 user_sepgsql_view_t:db_view { getattr expand };
	type_transition $2 sepgsql_schema_type:db_view user_sepgsql_view_t;

	allow $2 user_sepgsql_proc_exec_t:db_procedure { getattr execute };
	type_transition $2 sepgsql_schema_type:db_procedure user_sepgsql_proc_exec_t;

	allow $2 user_sepgsql_blob_t:db_blob { create drop getattr setattr read write import export };
	type_transition $2 sepgsql_database_type:db_blob user_sepgsql_blob_t;

	allow $2 sepgsql_ranged_proc_t:process transition;
	type_transition $2 sepgsql_ranged_proc_exec_t:process sepgsql_ranged_proc_t;
	allow sepgsql_ranged_proc_t $2:process dyntransition;

	allow $2 sepgsql_trusted_proc_t:process transition;
	type_transition $2 sepgsql_trusted_proc_exec_t:process sepgsql_trusted_proc_t;

	optional_policy(`
		systemd_user_app_status($1, sepgsql_ranged_proc_t)
		systemd_user_app_status($1, sepgsql_trusted_proc_t)
	')
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL loadable shared library module
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a database object type.
##	</summary>
## </param>
#
interface(`postgresql_loadable_module',`
	gen_require(`
		attribute sepgsql_module_type;
	')

	typeattribute $1 sepgsql_module_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL database object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a database object type.
##	</summary>
## </param>
#
interface(`postgresql_database_object',`
	gen_require(`
		attribute sepgsql_database_type;
	')

	typeattribute $1 sepgsql_database_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL schema object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a schema object type.
##	</summary>
## </param>
#
interface(`postgresql_schema_object',`
	gen_require(`
		attribute sepgsql_schema_type;
	')

	typeattribute $1 sepgsql_schema_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL table/column/tuple object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a table/column/tuple object type.
##	</summary>
## </param>
#
interface(`postgresql_table_object',`
	gen_require(`
		attribute sepgsql_table_type;
	')

	typeattribute $1 sepgsql_table_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL system table/column/tuple object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a table/column/tuple object type.
##	</summary>
## </param>
#
interface(`postgresql_system_table_object',`
	gen_require(`
		attribute sepgsql_table_type, sepgsql_sysobj_table_type;
	')

	typeattribute $1 sepgsql_table_type;
	typeattribute $1 sepgsql_sysobj_table_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL sequence type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a sequence type.
##	</summary>
## </param>
#
interface(`postgresql_sequence_object',`
	gen_require(`
		attribute sepgsql_sequence_type;
	')

	typeattribute $1 sepgsql_sequence_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL view object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a view object type.
##	</summary>
## </param>
#
interface(`postgresql_view_object',`
	gen_require(`
		attribute sepgsql_view_type;
	')

	typeattribute $1 sepgsql_view_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL procedure object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a procedure object type.
##	</summary>
## </param>
#
interface(`postgresql_procedure_object',`
	gen_require(`
		attribute sepgsql_procedure_type;
	')

	typeattribute $1 sepgsql_procedure_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL trusted procedure object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a trusted procedure object type.
##	</summary>
## </param>
#
interface(`postgresql_trusted_procedure_object',`
	gen_require(`
		attribute sepgsql_procedure_type;
		attribute sepgsql_trusted_procedure_type;
	')

	typeattribute $1 sepgsql_procedure_type;
	typeattribute $1 sepgsql_trusted_procedure_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL procedural language object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a procedural language object type.
##	</summary>
## </param>
#
interface(`postgresql_language_object',`
	gen_require(`
		attribute sepgsql_language_type;
	')

	typeattribute $1 sepgsql_language_type;
')

########################################
## <summary>
##	Marks as a SE-PostgreSQL binary large object type
## </summary>
## <param name="type">
##	<summary>
##	Type marked as a database binary large object type.
##	</summary>
## </param>
#
interface(`postgresql_blob_object',`
	gen_require(`
		attribute sepgsql_blob_type;
	')

	typeattribute $1 sepgsql_blob_type;
')

########################################
## <summary>
##	Allow the specified domain to search postgresql's database directory.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`postgresql_search_db',`
	gen_require(`
		type postgresql_db_t;
	')

	allow $1 postgresql_db_t:dir search;
')

########################################
## <summary>
##	Allow the specified domain to manage postgresql's database.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
interface(`postgresql_manage_db',`
	gen_require(`
		type postgresql_db_t;
	')

	allow $1 postgresql_db_t:dir rw_dir_perms;
	allow $1 postgresql_db_t:file rw_file_perms;
	allow $1 postgresql_db_t:lnk_file read_lnk_file_perms;
')

#######################################
## <summary>
##	Execute postgresql in the calling domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access
##	</summary>
## </param>
#
interface(`postgresql_exec',`
	gen_require(`
		type postgresql_exec_t;
	')

	can_exec($1, postgresql_exec_t)
')

########################################
## <summary>
##	Execute postgresql in the postgresql domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`postgresql_domtrans',`
	gen_require(`
		type postgresql_t, postgresql_exec_t;
	')

	domtrans_pattern($1, postgresql_exec_t, postgresql_t)
')

######################################
## <summary>
##	Allow domain to signal postgresql
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`postgresql_signal',`
	gen_require(`
		type postgresql_t;
	')
	allow $1 postgresql_t:process signal;
')

########################################
## <summary>
##	Allow the specified domain to read postgresql's etc.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`postgresql_read_config',`
	gen_require(`
		type postgresql_etc_t;
	')

	files_search_etc($1)
	allow $1 postgresql_etc_t:dir list_dir_perms;
	allow $1 postgresql_etc_t:file read_file_perms;
	allow $1 postgresql_etc_t:lnk_file read_lnk_file_perms;
')

########################################
## <summary>
##	Allow the specified domain to connect to postgresql with a tcp socket.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`postgresql_tcp_connect',`
	gen_require(`
		type postgresql_t;
	')

	corenet_tcp_recvfrom_labeled($1, postgresql_t)
	corenet_tcp_connect_postgresql_port($1)
	corenet_sendrecv_postgresql_client_packets($1)
')

########################################
## <summary>
##	Allow the specified domain to connect to postgresql with a unix socket.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`postgresql_stream_connect',`
	gen_require(`
		type postgresql_t, postgresql_runtime_t, postgresql_tmp_t;
	')

	stream_connect_pattern($1, { postgresql_runtime_t postgresql_tmp_t }, { postgresql_runtime_t postgresql_tmp_t }, postgresql_t)

	files_search_runtime($1)
	files_search_tmp($1)
')

########################################
## <summary>
##	Allow the specified domain unprivileged accesses to unifined database objects
##	managed by SE-PostgreSQL,
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`postgresql_unpriv_client',`
	gen_require(`
		class db_database all_db_database_perms;
		class db_schema all_db_schema_perms;
		class db_table all_db_table_perms;
		class db_sequence all_db_sequence_perms;
		class db_view all_db_view_perms;
		class db_procedure all_db_procedure_perms;
		class db_language all_db_language_perms;
		class db_column all_db_column_perms;
		class db_tuple all_db_tuple_perms;
		class db_blob all_db_blob_perms;

		attribute sepgsql_client_type;
		attribute sepgsql_database_type, sepgsql_schema_type;
		attribute sepgsql_sysobj_table_type;

		type sepgsql_ranged_proc_t, sepgsql_ranged_proc_exec_t;
		type sepgsql_temp_object_t;
		type sepgsql_trusted_proc_t, sepgsql_trusted_proc_exec_t;
		type unpriv_sepgsql_blob_t, unpriv_sepgsql_proc_exec_t;
		type unpriv_sepgsql_schema_t, unpriv_sepgsql_seq_t;
		type unpriv_sepgsql_sysobj_t, unpriv_sepgsql_table_t;
		type unpriv_sepgsql_view_t;
	')

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

	typeattribute $1 sepgsql_client_type;

	########################################
	#
	# Client local policy
	#

	type_transition $1 sepgsql_ranged_proc_exec_t:process sepgsql_ranged_proc_t;
	allow $1 sepgsql_ranged_proc_t:process transition;
	allow sepgsql_ranged_proc_t $1:process dyntransition;

	type_transition $1 sepgsql_trusted_proc_exec_t:process sepgsql_trusted_proc_t;
	allow $1 sepgsql_trusted_proc_t:process transition;

	allow $1 unpriv_sepgsql_blob_t:db_blob { create drop getattr setattr read write import export };
	type_transition $1 sepgsql_database_type:db_blob unpriv_sepgsql_blob_t;

	allow $1 unpriv_sepgsql_proc_exec_t:db_procedure { getattr execute };
	type_transition $1 sepgsql_schema_type:db_procedure unpriv_sepgsql_proc_exec_t;

	allow $1 unpriv_sepgsql_schema_t:db_schema { getattr add_name remove_name };
	type_transition $1 sepgsql_database_type:db_schema unpriv_sepgsql_schema_t;
	type_transition $1 sepgsql_database_type:db_schema sepgsql_temp_object_t "pg_temp";

	allow $1 unpriv_sepgsql_table_t:db_table { getattr select update insert delete lock };
	allow $1 unpriv_sepgsql_table_t:db_column { getattr select update insert };
	allow $1 unpriv_sepgsql_table_t:db_tuple { select update insert delete };
	type_transition $1 sepgsql_schema_type:db_table unpriv_sepgsql_table_t;

	allow $1 unpriv_sepgsql_seq_t:db_sequence { getattr get_value next_value set_value };
	type_transition $1 sepgsql_schema_type:db_sequence unpriv_sepgsql_seq_t;

	allow $1 unpriv_sepgsql_sysobj_t:db_tuple { use select };
	type_transition $1 sepgsql_sysobj_table_type:db_tuple unpriv_sepgsql_sysobj_t;

	allow $1 unpriv_sepgsql_view_t:db_view { getattr expand };
	type_transition $1 sepgsql_schema_type:db_view unpriv_sepgsql_view_t;


	tunable_policy(`sepgsql_enable_users_ddl',`
		allow $1 unpriv_sepgsql_schema_t:db_schema { create drop setattr };
		allow $1 unpriv_sepgsql_table_t:db_table { create drop setattr };
		allow $1 unpriv_sepgsql_table_t:db_column { create drop setattr };
		allow $1 unpriv_sepgsql_sysobj_t:db_tuple { update insert delete };
		allow $1 unpriv_sepgsql_seq_t:db_sequence { create drop setattr };
		allow $1 unpriv_sepgsql_view_t:db_view { create drop setattr };
		allow $1 unpriv_sepgsql_proc_exec_t:db_procedure { create drop setattr };
	')
')

########################################
## <summary>
##	Allow the specified domain unconfined accesses to any database objects
##	managed by SE-PostgreSQL,
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`postgresql_unconfined',`
	gen_require(`
		attribute sepgsql_unconfined_type;
	')

	typeattribute $1 sepgsql_unconfined_type;
')

########################################
## <summary>
##	All of the rules required to administrate an postgresql environment
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	The role to be allowed to manage the postgresql domain.
##	</summary>
## </param>
## <rolecap/>
#
interface(`postgresql_admin',`
	gen_require(`
		attribute sepgsql_admin_type;

		type postgresql_t, postgresql_runtime_t;
		type postgresql_tmp_t, postgresql_db_t;
		type postgresql_etc_t, postgresql_log_t;
		type postgresql_initrc_exec_t, postgresql_unit_t;
	')

	typeattribute $1 sepgsql_admin_type;

	allow $1 postgresql_t:process { ptrace signal_perms };
	ps_process_pattern($1, postgresql_t)

	init_startstop_service($1, $2, postgresql_t, postgresql_initrc_exec_t, postgresql_unit_t)

	admin_pattern($1, postgresql_runtime_t)

	admin_pattern($1, postgresql_db_t)

	admin_pattern($1, postgresql_etc_t)

	admin_pattern($1, postgresql_log_t)

	admin_pattern($1, postgresql_tmp_t)

	postgresql_tcp_connect($1)
	postgresql_stream_connect($1)
')