Chris PeBenito 17de1b
## <summary>PostgreSQL relational database</summary>
Chris PeBenito 17de1b
Chris PeBenito e8cb08
#######################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##      The userdomain template for the SE-PostgreSQL.
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <desc>
Chris PeBenito e8cb08
##      This template creates a delivered types which are used
Chris PeBenito e8cb08
##	for given userdomains.
Chris PeBenito e8cb08
## </desc>
Chris PeBenito e8cb08
## <param name="userdomain_prefix">
Chris PeBenito e8cb08
##      <summary>
Chris PeBenito e8cb08
##      The prefix of the user domain (e.g., user
Chris PeBenito e8cb08
##      is the prefix for user_t).
Chris PeBenito e8cb08
##      </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
## <param name="user_domain">
Chris PeBenito e8cb08
## 	<summary>
Chris PeBenito e8cb08
##      The type of the user domain.
Chris PeBenito e8cb08
##      </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
## <param name="user_role">
Chris PeBenito e8cb08
##      <summary>
Chris PeBenito e8cb08
##      The role associated with the user domain.
Chris PeBenito e8cb08
##      </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
template(`postgresql_userdom_template',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		class db_database all_db_database_perms;
Chris PeBenito e8cb08
		class db_table all_db_table_perms;
Chris PeBenito e8cb08
		class db_procedure all_db_procedure_perms;
Chris PeBenito e8cb08
		class db_column all_db_column_perms;
Chris PeBenito e8cb08
		class db_tuple all_db_tuple_perms;
Chris PeBenito e8cb08
		class db_blob all_db_blob_perms;
Chris PeBenito e8cb08
Chris PeBenito e8cb08
		attribute sepgsql_client_type, sepgsql_database_type;
Chris PeBenito e8cb08
		attribute sepgsql_sysobj_table_type;
Chris PeBenito e8cb08
Chris PeBenito 7f4005
		type sepgsql_trusted_proc_exec_t, sepgsql_trusted_proc_t;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	########################################
Chris PeBenito e8cb08
	#
Chris PeBenito e8cb08
	# Declarations
Chris PeBenito e8cb08
	#
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $2 sepgsql_client_type;
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	type $1_sepgsql_blob_t;
Chris PeBenito e8cb08
	postgresql_blob_object($1_sepgsql_blob_t)
Chris PeBenito e8cb08
Chris PeBenito 7f4005
	type $1_sepgsql_proc_exec_t;
Chris PeBenito 7f4005
	postgresql_procedure_object($1_sepgsql_proc_exec_t)
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	type $1_sepgsql_sysobj_t;
Chris PeBenito e8cb08
	postgresql_system_table_object($1_sepgsql_sysobj_t)
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	type $1_sepgsql_table_t;
Chris PeBenito e8cb08
	postgresql_table_object($1_sepgsql_table_t)
Chris PeBenito e8cb08
Chris PeBenito 7f4005
	role $3 types sepgsql_trusted_proc_t;
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	##############################
Chris PeBenito e8cb08
	#
Chris PeBenito e8cb08
	# Client local policy
Chris PeBenito e8cb08
	#
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	tunable_policy(`sepgsql_enable_users_ddl',`
Chris PeBenito 0bfccd
		allow $2 $1_sepgsql_table_t:db_table { create drop };
Chris PeBenito e8cb08
		type_transition $2 sepgsql_database_type:db_table $1_sepgsql_table_t;
Chris PeBenito e8cb08
Chris PeBenito 0bfccd
		allow $2 $1_sepgsql_table_t:db_column { create drop };
Chris PeBenito e8cb08
Chris PeBenito 0bfccd
		allow $2 $1_sepgsql_sysobj_t:db_tuple { update insert delete };
Chris PeBenito e8cb08
		type_transition $2 sepgsql_sysobj_table_type:db_tuple $1_sepgsql_sysobj_t;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito 0bfccd
	allow $2 $1_sepgsql_table_t:db_table { getattr setattr use select update insert delete };
Chris PeBenito 0bfccd
	allow $2 $1_sepgsql_table_t:db_column { getattr setattr use select update insert };
Chris PeBenito 0bfccd
	allow $2 $1_sepgsql_table_t:db_tuple { use select update insert delete };
Chris PeBenito 0bfccd
	allow $2 $1_sepgsql_sysobj_t:db_tuple { use select };
Chris PeBenito e8cb08
Chris PeBenito 0bfccd
	allow $2 $1_sepgsql_proc_exec_t:db_procedure { create drop getattr setattr execute };
Chris PeBenito 7f4005
	type_transition $2 sepgsql_database_type:db_procedure $1_sepgsql_proc_exec_t;
Chris PeBenito e8cb08
Chris PeBenito 0bfccd
	allow $2 $1_sepgsql_blob_t:db_blob { create drop getattr setattr read write };
Chris PeBenito e8cb08
	type_transition $2 sepgsql_database_type:db_blob $1_sepgsql_blob_t;
Chris PeBenito e8cb08
Chris PeBenito 7f4005
	allow $2 sepgsql_trusted_proc_t:process transition;
Chris PeBenito 7f4005
	type_transition $2 sepgsql_trusted_proc_exec_t:process sepgsql_trusted_proc_t;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##     Marks as a SE-PostgreSQL loadable shared library module
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="type">
Chris PeBenito e8cb08
##     <summary>
Chris PeBenito e8cb08
##     Type marked as a database object type.
Chris PeBenito e8cb08
##     </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_loadable_module',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		attribute sepgsql_module_type;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_module_type;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##     Marks as a SE-PostgreSQL database object type
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="type">
Chris PeBenito e8cb08
##     <summary>
Chris PeBenito e8cb08
##     Type marked as a database object type.
Chris PeBenito e8cb08
##     </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_database_object',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		attribute sepgsql_database_type;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_database_type;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##     Marks as a SE-PostgreSQL table/column/tuple object type
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="type">
Chris PeBenito e8cb08
##     <summary>
Chris PeBenito e8cb08
##     Type marked as a table/column/tuple object type.
Chris PeBenito e8cb08
##     </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_table_object',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		attribute sepgsql_table_type;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_table_type;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##     Marks as a SE-PostgreSQL system table/column/tuple object type
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="type">
Chris PeBenito e8cb08
##     <summary>
Chris PeBenito e8cb08
##     Type marked as a table/column/tuple object type.
Chris PeBenito e8cb08
##     </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_system_table_object',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito 0bfccd
		attribute sepgsql_table_type, sepgsql_sysobj_table_type;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_table_type;
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_sysobj_table_type;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##     Marks as a SE-PostgreSQL procedure object type
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="type">
Chris PeBenito e8cb08
##     <summary>
Chris PeBenito e8cb08
##     Type marked as a database object type.
Chris PeBenito e8cb08
##     </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_procedure_object',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		attribute sepgsql_procedure_type;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_procedure_type;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##     Marks as a SE-PostgreSQL binary large object type
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="type">
Chris PeBenito e8cb08
##     <summary>
Chris PeBenito e8cb08
##     Type marked as a database binary large object type.
Chris PeBenito e8cb08
##     </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_blob_object',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		attribute sepgsql_blob_type;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_blob_type;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito 17de1b
########################################
Chris PeBenito 17de1b
## <summary>
Chris PeBenito 17de1b
##	Allow the specified domain to search postgresql's database directory.
Chris PeBenito 17de1b
## </summary>
Chris PeBenito 17de1b
## <param name="domain">
Chris PeBenito 17de1b
##	<summary>
Chris PeBenito 17de1b
##	Domain allowed access.
Chris PeBenito 17de1b
##	</summary>
Chris PeBenito 17de1b
## </param>
Chris PeBenito 17de1b
#
Chris PeBenito 17de1b
interface(`postgresql_search_db',`
Chris PeBenito 17de1b
	gen_require(`
Chris PeBenito 17de1b
		type postgresql_db_t;
Chris PeBenito 17de1b
	')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
	allow $1 postgresql_db_t:dir search;
Chris PeBenito 17de1b
')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
########################################
Chris PeBenito 17de1b
## <summary>
Chris PeBenito 17de1b
##	Allow the specified domain to manage postgresql's database.
Chris PeBenito 17de1b
## </summary>
Chris PeBenito 17de1b
## <param name="domain">
Chris PeBenito 17de1b
##	<summary>
Chris PeBenito 17de1b
##	Domain allowed access.
Chris PeBenito 17de1b
##	</summary>
Chris PeBenito 17de1b
## </param>
Chris PeBenito 17de1b
interface(`postgresql_manage_db',`
Chris PeBenito 17de1b
	gen_require(`
Chris PeBenito 17de1b
		type postgresql_db_t;
Chris PeBenito 17de1b
	')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
	allow $1 postgresql_db_t:dir rw_dir_perms;
Chris PeBenito 17de1b
	allow $1 postgresql_db_t:file rw_file_perms;
Chris PeBenito 17de1b
	allow $1 postgresql_db_t:lnk_file { getattr read };
Chris PeBenito 17de1b
')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
########################################
Chris PeBenito 17de1b
## <summary>
Chris PeBenito 17de1b
##	Execute postgresql in the postgresql domain.
Chris PeBenito 17de1b
## </summary>
Chris PeBenito 17de1b
## <param name="domain">
Chris PeBenito 17de1b
##	<summary>
Chris PeBenito 17de1b
##	The type of the process performing this action.
Chris PeBenito 17de1b
##	</summary>
Chris PeBenito 17de1b
## </param>
Chris PeBenito 17de1b
#
Chris PeBenito 17de1b
interface(`postgresql_domtrans',`
Chris PeBenito 17de1b
	gen_require(`
Chris PeBenito 17de1b
		type postgresql_t, postgresql_exec_t;
Chris PeBenito 17de1b
	')
Chris PeBenito 17de1b
Chris PeBenito 0bfccd
	domtrans_pattern($1, postgresql_exec_t, postgresql_t)
Chris PeBenito 17de1b
')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
########################################
Chris PeBenito 17de1b
## <summary>
Chris PeBenito 17de1b
##	Allow the specified domain to read postgresql's etc.
Chris PeBenito 17de1b
## </summary>
Chris PeBenito 17de1b
## <param name="domain">
Chris PeBenito 17de1b
##	<summary>
Chris PeBenito 17de1b
##	Domain allowed access.
Chris PeBenito 17de1b
##	</summary>
Chris PeBenito 17de1b
## </param>
Chris PeBenito bbcd3c
## <rolecap/>
Chris PeBenito 17de1b
#
Chris PeBenito 17de1b
interface(`postgresql_read_config',`
Chris PeBenito 17de1b
	gen_require(`
Chris PeBenito 17de1b
		type postgresql_etc_t;
Chris PeBenito 17de1b
	')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
	files_search_etc($1)
Chris PeBenito 17de1b
	allow $1 postgresql_etc_t:dir { getattr read search };
Chris PeBenito 17de1b
	allow $1 postgresql_etc_t:file { read getattr };
Chris PeBenito 17de1b
	allow $1 postgresql_etc_t:lnk_file { getattr read };
Chris PeBenito 17de1b
')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
########################################
Chris PeBenito 17de1b
## <summary>
Chris PeBenito 0b6aca
##	Allow the specified domain to connect to postgresql with a tcp socket.
Chris PeBenito 17de1b
## </summary>
Chris PeBenito 17de1b
## <param name="domain">
Chris PeBenito 17de1b
##	<summary>
Chris PeBenito 17de1b
##	Domain allowed access.
Chris PeBenito 17de1b
##	</summary>
Chris PeBenito 17de1b
## </param>
Chris PeBenito 17de1b
#
Chris PeBenito 17de1b
interface(`postgresql_tcp_connect',`
Chris PeBenito 0b6aca
	gen_require(`
Chris PeBenito 0b6aca
		type postgresql_t;
Chris PeBenito 0b6aca
	')
Chris PeBenito 0b6aca
Chris PeBenito 0bfccd
	corenet_tcp_recvfrom_labeled($1, postgresql_t)
Chris PeBenito 0b6aca
	corenet_tcp_sendrecv_postgresql_port($1)
Chris PeBenito 0b6aca
	corenet_tcp_connect_postgresql_port($1)
Chris PeBenito 0b6aca
	corenet_sendrecv_postgresql_client_packets($1)
Chris PeBenito 17de1b
')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
########################################
Chris PeBenito 17de1b
## <summary>
Chris PeBenito 17de1b
##	Allow the specified domain to connect to postgresql with a unix socket.
Chris PeBenito 17de1b
## </summary>
Chris PeBenito 17de1b
## <param name="domain">
Chris PeBenito 17de1b
##	<summary>
Chris PeBenito 17de1b
##	Domain allowed access.
Chris PeBenito 17de1b
##	</summary>
Chris PeBenito 17de1b
## </param>
Chris PeBenito bbcd3c
## <rolecap/>
Chris PeBenito 17de1b
#
Chris PeBenito 17de1b
interface(`postgresql_stream_connect',`
Chris PeBenito 17de1b
	gen_require(`
Chris PeBenito 17de1b
		type postgresql_t, postgresql_var_run_t, postgresql_tmp_t;
Chris PeBenito 17de1b
	')
Chris PeBenito 17de1b
Chris PeBenito 17de1b
	files_search_pids($1)
Chris PeBenito 17de1b
	allow $1 postgresql_t:unix_stream_socket connectto;
Chris PeBenito 17de1b
	allow $1 postgresql_var_run_t:sock_file write;
Chris PeBenito 17de1b
        # Some versions of postgresql put the sock file in /tmp
Chris PeBenito 17de1b
	allow $1 postgresql_tmp_t:sock_file write;
Chris PeBenito 17de1b
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##      Allow the specified domain unprivileged accesses to unifined database objects
Chris PeBenito e8cb08
##	managed by SE-PostgreSQL,
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="domain">
Chris PeBenito e8cb08
##      <summary>
Chris PeBenito e8cb08
##      Domain allowed access.
Chris PeBenito e8cb08
##      </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_unpriv_client',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		class db_table all_db_table_perms;
Chris PeBenito e8cb08
		class db_procedure all_db_procedure_perms;
Chris PeBenito e8cb08
		class db_blob all_db_blob_perms;
Chris PeBenito e8cb08
Chris PeBenito e8cb08
		attribute sepgsql_client_type;
Chris PeBenito e8cb08
Chris PeBenito 8e7d43
		type sepgsql_db_t, sepgsql_table_t, sepgsql_proc_t, sepgsql_blob_t;
Chris PeBenito 7f4005
		type sepgsql_trusted_proc_t, sepgsql_trusted_proc_exec_t;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_client_type;
Chris PeBenito e8cb08
Chris PeBenito 8e7d43
	type_transition $1 sepgsql_db_t:db_table sepgsql_table_t;
Chris PeBenito 8e7d43
	type_transition $1 sepgsql_db_t:db_procedure sepgsql_proc_t;
Chris PeBenito 8e7d43
	type_transition $1 sepgsql_db_t:db_blob sepgsql_blob_t;
Chris PeBenito e8cb08
Chris PeBenito 7f4005
	type_transition $1 sepgsql_trusted_proc_exec_t:process sepgsql_trusted_proc_t;
Chris PeBenito 7f4005
	allow $1 sepgsql_trusted_proc_t:process transition;
Chris PeBenito e8cb08
')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
########################################
Chris PeBenito e8cb08
## <summary>
Chris PeBenito e8cb08
##      Allow the specified domain unconfined accesses to any database objects
Chris PeBenito e8cb08
##	managed by SE-PostgreSQL,
Chris PeBenito e8cb08
## </summary>
Chris PeBenito e8cb08
## <param name="domain">
Chris PeBenito e8cb08
##      <summary>
Chris PeBenito e8cb08
##      Domain allowed access.
Chris PeBenito e8cb08
##      </summary>
Chris PeBenito e8cb08
## </param>
Chris PeBenito e8cb08
#
Chris PeBenito e8cb08
interface(`postgresql_unconfined',`
Chris PeBenito e8cb08
	gen_require(`
Chris PeBenito e8cb08
		attribute sepgsql_unconfined_type;
Chris PeBenito e8cb08
	')
Chris PeBenito e8cb08
Chris PeBenito e8cb08
	typeattribute $1 sepgsql_unconfined_type;
Chris PeBenito e8cb08
')