2005-09-19 21:17:45 +00:00
|
|
|
|
2008-06-24 12:57:06 +00:00
|
|
|
policy_module(postgresql, 1.5.3)
|
2008-06-10 15:33:18 +00:00
|
|
|
|
|
|
|
gen_require(`
|
|
|
|
class db_database all_db_database_perms;
|
|
|
|
class db_table all_db_table_perms;
|
|
|
|
class db_procedure all_db_procedure_perms;
|
|
|
|
class db_column all_db_column_perms;
|
|
|
|
class db_tuple all_db_tuple_perms;
|
|
|
|
class db_blob all_db_blob_perms;
|
|
|
|
')
|
2005-09-19 21:17:45 +00:00
|
|
|
|
|
|
|
#################################
|
|
|
|
#
|
|
|
|
# Declarations
|
|
|
|
#
|
2008-06-10 15:33:18 +00:00
|
|
|
|
|
|
|
## <desc>
|
|
|
|
## <p>
|
|
|
|
## Allow unprived users to execute DDL statement
|
|
|
|
## </p>
|
|
|
|
## </desc>
|
|
|
|
gen_tunable(sepgsql_enable_users_ddl, true)
|
|
|
|
|
2005-09-19 21:17:45 +00:00
|
|
|
type postgresql_t;
|
|
|
|
type postgresql_exec_t;
|
|
|
|
init_daemon_domain(postgresql_t,postgresql_exec_t)
|
|
|
|
|
|
|
|
type postgresql_db_t;
|
|
|
|
files_type(postgresql_db_t)
|
|
|
|
|
2005-10-24 18:40:24 +00:00
|
|
|
type postgresql_etc_t;
|
|
|
|
files_config_file(postgresql_etc_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
|
|
|
type postgresql_lock_t;
|
|
|
|
files_lock_file(postgresql_lock_t)
|
|
|
|
|
|
|
|
type postgresql_log_t;
|
|
|
|
logging_log_file(postgresql_log_t)
|
|
|
|
|
|
|
|
type postgresql_tmp_t;
|
|
|
|
files_tmp_file(postgresql_tmp_t)
|
|
|
|
|
|
|
|
type postgresql_var_run_t;
|
|
|
|
files_pid_file(postgresql_var_run_t)
|
|
|
|
|
2008-06-10 15:33:18 +00:00
|
|
|
# database clients attribute
|
|
|
|
attribute sepgsql_client_type;
|
|
|
|
attribute sepgsql_unconfined_type;
|
|
|
|
|
|
|
|
# database objects attribute
|
|
|
|
attribute sepgsql_database_type;
|
|
|
|
attribute sepgsql_table_type;
|
|
|
|
attribute sepgsql_sysobj_table_type;
|
|
|
|
attribute sepgsql_procedure_type;
|
|
|
|
attribute sepgsql_blob_type;
|
|
|
|
attribute sepgsql_module_type;
|
|
|
|
|
|
|
|
# database object types
|
|
|
|
type sepgsql_blob_t;
|
|
|
|
postgresql_blob_object(sepgsql_blob_t)
|
|
|
|
|
|
|
|
type sepgsql_db_t;
|
|
|
|
postgresql_database_object(sepgsql_db_t)
|
|
|
|
|
|
|
|
type sepgsql_fixed_table_t;
|
|
|
|
postgresql_table_object(sepgsql_fixed_table_t)
|
|
|
|
|
|
|
|
type sepgsql_proc_t;
|
|
|
|
postgresql_procedure_object(sepgsql_proc_t)
|
|
|
|
|
|
|
|
type sepgsql_ro_blob_t;
|
|
|
|
postgresql_blob_object(sepgsql_ro_blob_t)
|
|
|
|
|
|
|
|
type sepgsql_ro_table_t;
|
|
|
|
postgresql_table_object(sepgsql_ro_table_t)
|
|
|
|
|
|
|
|
type sepgsql_secret_blob_t;
|
|
|
|
postgresql_blob_object(sepgsql_secret_blob_t)
|
|
|
|
|
|
|
|
type sepgsql_secret_table_t;
|
|
|
|
postgresql_table_object(sepgsql_secret_table_t)
|
|
|
|
|
|
|
|
type sepgsql_sysobj_t;
|
|
|
|
postgresql_system_table_object(sepgsql_sysobj_t)
|
|
|
|
|
|
|
|
type sepgsql_table_t;
|
|
|
|
postgresql_table_object(sepgsql_table_t)
|
|
|
|
|
2008-06-24 12:57:06 +00:00
|
|
|
type sepgsql_trusted_proc_exec_t;
|
|
|
|
postgresql_procedure_object(sepgsql_trusted_proc_exec_t)
|
2008-06-10 15:33:18 +00:00
|
|
|
|
|
|
|
# Trusted Procedure Domain
|
2008-06-24 12:57:06 +00:00
|
|
|
type sepgsql_trusted_proc_t;
|
|
|
|
domain_type(sepgsql_trusted_proc_t)
|
|
|
|
postgresql_unconfined(sepgsql_trusted_proc_t)
|
|
|
|
role system_r types sepgsql_trusted_proc_t;
|
2008-06-10 15:33:18 +00:00
|
|
|
|
2005-09-19 21:17:45 +00:00
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# postgresql Local policy
|
|
|
|
#
|
|
|
|
allow postgresql_t self:capability { kill dac_override dac_read_search chown fowner fsetid setuid setgid sys_nice sys_tty_config sys_admin };
|
2006-05-17 14:50:31 +00:00
|
|
|
dontaudit postgresql_t self:capability { sys_tty_config sys_admin };
|
2005-10-24 17:28:17 +00:00
|
|
|
allow postgresql_t self:process signal_perms;
|
2005-09-19 21:17:45 +00:00
|
|
|
allow postgresql_t self:fifo_file { getattr read write ioctl };
|
|
|
|
allow postgresql_t self:file { getattr read };
|
|
|
|
allow postgresql_t self:sem create_sem_perms;
|
|
|
|
allow postgresql_t self:shm create_shm_perms;
|
|
|
|
allow postgresql_t self:tcp_socket create_stream_socket_perms;
|
|
|
|
allow postgresql_t self:udp_socket create_stream_socket_perms;
|
|
|
|
allow postgresql_t self:unix_dgram_socket create_socket_perms;
|
|
|
|
allow postgresql_t self:unix_stream_socket create_stream_socket_perms;
|
2008-06-10 15:33:18 +00:00
|
|
|
allow postgresql_t self:netlink_selinux_socket create_socket_perms;
|
|
|
|
|
|
|
|
allow postgresql_t sepgsql_database_type:db_database *;
|
|
|
|
type_transition postgresql_t postgresql_t:db_database sepgsql_db_t;
|
|
|
|
|
|
|
|
allow postgresql_t sepgsql_module_type:db_database install_module;
|
|
|
|
# Database/Loadable module
|
|
|
|
allow sepgsql_database_type sepgsql_module_type:db_database load_module;
|
|
|
|
|
|
|
|
allow postgresql_t sepgsql_table_type:{ db_table db_column db_tuple } *;
|
|
|
|
type_transition postgresql_t sepgsql_database_type:db_table sepgsql_sysobj_t;
|
|
|
|
|
|
|
|
allow postgresql_t sepgsql_procedure_type:db_procedure *;
|
|
|
|
type_transition postgresql_t sepgsql_database_type:db_procedure sepgsql_proc_t;
|
|
|
|
|
|
|
|
allow postgresql_t sepgsql_blob_type:db_blob *;
|
|
|
|
type_transition postgresql_t sepgsql_database_type:db_blob sepgsql_blob_t;
|
2005-09-19 21:17:45 +00:00
|
|
|
|
2006-12-12 20:08:08 +00:00
|
|
|
manage_dirs_pattern(postgresql_t,postgresql_db_t,postgresql_db_t)
|
|
|
|
manage_files_pattern(postgresql_t,postgresql_db_t,postgresql_db_t)
|
|
|
|
manage_lnk_files_pattern(postgresql_t,postgresql_db_t,postgresql_db_t)
|
|
|
|
manage_fifo_files_pattern(postgresql_t,postgresql_db_t,postgresql_db_t)
|
|
|
|
manage_sock_files_pattern(postgresql_t,postgresql_db_t,postgresql_db_t)
|
2006-02-21 18:40:44 +00:00
|
|
|
files_var_lib_filetrans(postgresql_t, postgresql_db_t, { dir file lnk_file sock_file fifo_file })
|
2005-09-19 21:17:45 +00:00
|
|
|
|
2006-12-12 20:08:08 +00:00
|
|
|
allow postgresql_t postgresql_etc_t:dir list_dir_perms;
|
|
|
|
read_files_pattern(postgresql_t,postgresql_etc_t,postgresql_etc_t)
|
|
|
|
read_lnk_files_pattern(postgresql_t,postgresql_etc_t,postgresql_etc_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
|
|
|
allow postgresql_t postgresql_exec_t:lnk_file { getattr read };
|
|
|
|
can_exec(postgresql_t, postgresql_exec_t )
|
|
|
|
|
2006-12-12 20:08:08 +00:00
|
|
|
allow postgresql_t postgresql_lock_t:file manage_file_perms;
|
2006-03-02 23:41:11 +00:00
|
|
|
files_lock_filetrans(postgresql_t,postgresql_lock_t,file)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
2006-12-12 20:08:08 +00:00
|
|
|
manage_files_pattern(postgresql_t,postgresql_log_t,postgresql_log_t)
|
2006-02-21 18:40:44 +00:00
|
|
|
logging_log_filetrans(postgresql_t,postgresql_log_t,{ file dir })
|
2005-09-19 21:17:45 +00:00
|
|
|
|
2006-12-12 20:08:08 +00:00
|
|
|
manage_dirs_pattern(postgresql_t,postgresql_tmp_t,postgresql_tmp_t)
|
|
|
|
manage_files_pattern(postgresql_t,postgresql_tmp_t,postgresql_tmp_t)
|
|
|
|
manage_lnk_files_pattern(postgresql_t,postgresql_tmp_t,postgresql_tmp_t)
|
|
|
|
manage_fifo_files_pattern(postgresql_t,postgresql_tmp_t,postgresql_tmp_t)
|
|
|
|
manage_sock_files_pattern(postgresql_t,postgresql_tmp_t,postgresql_tmp_t)
|
2006-02-21 18:40:44 +00:00
|
|
|
files_tmp_filetrans(postgresql_t, postgresql_tmp_t, { dir file sock_file })
|
|
|
|
fs_tmpfs_filetrans(postgresql_t, postgresql_tmp_t, { dir file lnk_file sock_file fifo_file })
|
2005-09-19 21:17:45 +00:00
|
|
|
|
2006-12-12 20:08:08 +00:00
|
|
|
manage_files_pattern(postgresql_t,postgresql_var_run_t,postgresql_var_run_t)
|
|
|
|
manage_sock_files_pattern(postgresql_t,postgresql_var_run_t,postgresql_var_run_t)
|
2006-03-02 23:41:11 +00:00
|
|
|
files_pid_filetrans(postgresql_t,postgresql_var_run_t,file)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
2006-01-31 16:49:43 +00:00
|
|
|
kernel_read_kernel_sysctls(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
kernel_read_system_state(postgresql_t)
|
|
|
|
kernel_list_proc(postgresql_t)
|
2006-01-31 16:49:43 +00:00
|
|
|
kernel_read_all_sysctls(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
kernel_read_proc_symlinks(postgresql_t)
|
|
|
|
|
2007-06-27 15:23:21 +00:00
|
|
|
corenet_all_recvfrom_unlabeled(postgresql_t)
|
|
|
|
corenet_all_recvfrom_netlabel(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
corenet_tcp_sendrecv_all_if(postgresql_t)
|
|
|
|
corenet_udp_sendrecv_all_if(postgresql_t)
|
|
|
|
corenet_tcp_sendrecv_all_nodes(postgresql_t)
|
|
|
|
corenet_udp_sendrecv_all_nodes(postgresql_t)
|
|
|
|
corenet_tcp_sendrecv_all_ports(postgresql_t)
|
|
|
|
corenet_udp_sendrecv_all_ports(postgresql_t)
|
|
|
|
corenet_tcp_bind_all_nodes(postgresql_t)
|
|
|
|
corenet_tcp_bind_postgresql_port(postgresql_t)
|
|
|
|
corenet_tcp_connect_auth_port(postgresql_t)
|
2006-05-30 19:46:34 +00:00
|
|
|
corenet_sendrecv_postgresql_server_packets(postgresql_t)
|
|
|
|
corenet_sendrecv_auth_client_packets(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
|
|
|
dev_read_sysfs(postgresql_t)
|
|
|
|
dev_read_urand(postgresql_t)
|
|
|
|
|
|
|
|
fs_getattr_all_fs(postgresql_t)
|
|
|
|
fs_search_auto_mountpoints(postgresql_t)
|
|
|
|
|
2008-06-10 15:33:18 +00:00
|
|
|
selinux_get_enforce_mode(postgresql_t)
|
|
|
|
selinux_validate_context(postgresql_t)
|
|
|
|
selinux_compute_access_vector(postgresql_t)
|
|
|
|
selinux_compute_create_context(postgresql_t)
|
|
|
|
selinux_compute_relabel_context(postgresql_t)
|
|
|
|
|
2005-09-19 21:17:45 +00:00
|
|
|
term_use_controlling_term(postgresql_t)
|
|
|
|
|
|
|
|
corecmd_exec_bin(postgresql_t)
|
|
|
|
corecmd_exec_shell(postgresql_t)
|
|
|
|
|
2006-02-02 21:08:12 +00:00
|
|
|
domain_dontaudit_list_all_domains_state(postgresql_t)
|
2006-02-20 21:33:25 +00:00
|
|
|
domain_use_interactive_fds(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
|
|
|
files_dontaudit_search_home(postgresql_t)
|
|
|
|
files_manage_etc_files(postgresql_t)
|
|
|
|
files_search_etc(postgresql_t)
|
|
|
|
files_read_etc_runtime_files(postgresql_t)
|
|
|
|
files_read_usr_files(postgresql_t)
|
|
|
|
|
2007-12-06 16:04:14 +00:00
|
|
|
auth_use_nsswitch(postgresql_t)
|
|
|
|
|
2006-01-18 18:08:39 +00:00
|
|
|
init_read_utmp(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
|
|
|
libs_use_ld_so(postgresql_t)
|
|
|
|
libs_use_shared_libs(postgresql_t)
|
|
|
|
|
|
|
|
logging_send_syslog_msg(postgresql_t)
|
|
|
|
|
|
|
|
miscfiles_read_localization(postgresql_t)
|
|
|
|
|
2008-06-10 15:33:18 +00:00
|
|
|
seutil_libselinux_linked(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
2006-02-20 21:33:25 +00:00
|
|
|
userdom_dontaudit_use_unpriv_user_fds(postgresql_t)
|
2005-09-19 21:17:45 +00:00
|
|
|
|
|
|
|
mta_getattr_spool(postgresql_t)
|
|
|
|
|
2008-04-29 13:58:34 +00:00
|
|
|
sysadm_dontaudit_search_home_dirs(postgresql_t)
|
|
|
|
sysadm_dontaudit_use_ttys(postgresql_t)
|
|
|
|
|
2005-09-19 21:17:45 +00:00
|
|
|
tunable_policy(`allow_execmem',`
|
|
|
|
allow postgresql_t self:process execmem;
|
|
|
|
')
|
|
|
|
|
2006-03-24 16:13:54 +00:00
|
|
|
optional_policy(`
|
2005-09-19 21:17:45 +00:00
|
|
|
consoletype_exec(postgresql_t)
|
|
|
|
')
|
|
|
|
|
2006-03-24 16:13:54 +00:00
|
|
|
optional_policy(`
|
2005-09-19 21:17:45 +00:00
|
|
|
cron_search_spool(postgresql_t)
|
|
|
|
cron_system_entry(postgresql_t,postgresql_exec_t)
|
|
|
|
')
|
|
|
|
|
2006-03-24 16:13:54 +00:00
|
|
|
optional_policy(`
|
2005-09-19 21:17:45 +00:00
|
|
|
hostname_exec(postgresql_t)
|
|
|
|
')
|
|
|
|
|
2007-11-26 16:44:57 +00:00
|
|
|
optional_policy(`
|
|
|
|
ipsec_match_default_spd(postgresql_t)
|
|
|
|
')
|
|
|
|
|
2006-03-24 16:13:54 +00:00
|
|
|
optional_policy(`
|
2005-09-19 21:17:45 +00:00
|
|
|
kerberos_use(postgresql_t)
|
|
|
|
')
|
|
|
|
|
2006-03-24 16:13:54 +00:00
|
|
|
optional_policy(`
|
2005-09-19 21:17:45 +00:00
|
|
|
seutil_sigchld_newrole(postgresql_t)
|
|
|
|
')
|
|
|
|
|
2006-03-24 16:13:54 +00:00
|
|
|
optional_policy(`
|
2005-09-19 21:17:45 +00:00
|
|
|
udev_read_db(postgresql_t)
|
|
|
|
')
|
2008-06-10 15:33:18 +00:00
|
|
|
|
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Rules common to all clients
|
|
|
|
#
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_db_t:db_database { getattr access get_param set_param };
|
|
|
|
type_transition sepgsql_client_type sepgsql_client_type:db_database sepgsql_db_t;
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_fixed_table_t:db_table { getattr use select insert };
|
|
|
|
allow sepgsql_client_type sepgsql_fixed_table_t:db_column { getattr use select insert };
|
|
|
|
allow sepgsql_client_type sepgsql_fixed_table_t:db_tuple { use select insert };
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_table_t:db_table { getattr use select update insert delete };
|
|
|
|
allow sepgsql_client_type sepgsql_table_t:db_column { getattr use select update insert };
|
|
|
|
allow sepgsql_client_type sepgsql_table_t:db_tuple { use select update insert delete };
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_ro_table_t:db_table { getattr use select };
|
|
|
|
allow sepgsql_client_type sepgsql_ro_table_t:db_column { getattr use select };
|
|
|
|
allow sepgsql_client_type sepgsql_ro_table_t:db_tuple { use select };
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_secret_table_t:db_table getattr;
|
|
|
|
allow sepgsql_client_type sepgsql_secret_table_t:db_column getattr;
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_sysobj_t:db_table { getattr use select };
|
|
|
|
allow sepgsql_client_type sepgsql_sysobj_t:db_column { getattr use select };
|
|
|
|
allow sepgsql_client_type sepgsql_sysobj_t:db_tuple { use select };
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_proc_t:db_procedure { getattr execute };
|
|
|
|
allow sepgsql_client_type sepgsql_trusted_proc_t:db_procedure { getattr execute entrypoint };
|
|
|
|
|
|
|
|
allow sepgsql_client_type sepgsql_blob_t:db_blob { create drop getattr setattr read write };
|
|
|
|
allow sepgsql_client_type sepgsql_ro_blob_t:db_blob { getattr read };
|
|
|
|
allow sepgsql_client_type sepgsql_secret_blob_t:db_blob getattr;
|
|
|
|
|
|
|
|
# The purpose of the dontaudit rule in row-level access control is to prevent a flood of logs.
|
|
|
|
# If a client tries to SELECT a table including violated tuples, these are filtered from
|
|
|
|
# the result set as if not exist, but its access denied longs can be recorded within log files.
|
|
|
|
# In generally, the number of tuples are much larger than the number of columns, tables and so on.
|
|
|
|
# So, it makes a flood of logs when many tuples are violated.
|
|
|
|
#
|
|
|
|
# The default policy does not prevent anything for sepgsql_client_type sepgsql_unconfined_type,
|
|
|
|
# so we don't need "dontaudit" rules in Type-Enforcement. However, MLS/MCS can prevent them
|
|
|
|
# to access classified tuples and can make a audit record.
|
|
|
|
#
|
|
|
|
# Therefore, the following rule is applied for any domains which can connect SE-PostgreSQL.
|
|
|
|
dontaudit { postgresql_t sepgsql_client_type sepgsql_unconfined_type } { sepgsql_table_type -sepgsql_sysobj_table_type }:db_tuple { use select update insert delete };
|
|
|
|
|
|
|
|
tunable_policy(`sepgsql_enable_users_ddl',`
|
|
|
|
allow sepgsql_client_type sepgsql_table_t:db_table { create drop setattr };
|
|
|
|
allow sepgsql_client_type sepgsql_table_t:db_column { create drop setattr };
|
|
|
|
allow sepgsql_client_type sepgsql_sysobj_t:db_tuple { update insert delete };
|
|
|
|
')
|
|
|
|
|
|
|
|
########################################
|
|
|
|
#
|
|
|
|
# Unconfined access to this module
|
|
|
|
#
|
|
|
|
|
|
|
|
allow sepgsql_unconfined_type sepgsql_database_type:db_database *;
|
|
|
|
type_transition sepgsql_unconfined_type sepgsql_unconfined_type:db_database sepgsql_db_t;
|
|
|
|
|
|
|
|
type_transition sepgsql_unconfined_type sepgsql_database_type:db_table sepgsql_table_t;
|
|
|
|
type_transition sepgsql_unconfined_type sepgsql_database_type:db_procedure sepgsql_proc_t;
|
|
|
|
type_transition sepgsql_unconfined_type sepgsql_database_type:db_blob sepgsql_blob_t;
|
|
|
|
|
|
|
|
allow sepgsql_unconfined_type sepgsql_table_type:{ db_table db_column db_tuple } *;
|
|
|
|
|
|
|
|
# unconfined domain is not allowed to invoke user defined procedure directly.
|
|
|
|
# They have to confirm and relabel it at first.
|
|
|
|
allow sepgsql_unconfined_type { sepgsql_proc_t sepgsql_trusted_proc_t }:db_procedure *;
|
|
|
|
allow sepgsql_unconfined_type sepgsql_procedure_type:db_procedure { create drop getattr setattr relabelfrom relabelto };
|
|
|
|
|
|
|
|
allow sepgsql_unconfined_type sepgsql_blob_type:db_blob *;
|
|
|
|
|
|
|
|
allow sepgsql_unconfined_type sepgsql_module_type:db_database install_module;
|
|
|
|
|
|
|
|
kernel_relabelfrom_unlabeled_database(sepgsql_unconfined_type)
|