Chris PeBenito ab58ad
#DESC Postgresql - Database server
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Author:  Russell Coker <russell@coker.com.au>
Chris PeBenito ab58ad
# X-Debian-Packages: postgresql
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
Chris PeBenito ab58ad
#################################
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Rules for the postgresql_t domain.
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# postgresql_exec_t is the type of the postgresql executable.
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
daemon_domain(postgresql)
Chris PeBenito ab58ad
allow initrc_t postgresql_exec_t:lnk_file read;
Chris PeBenito ab58ad
allow postgresql_t usr_t:file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t postgresql_var_run_t:sock_file create_file_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`distro_debian', `
Chris PeBenito ab58ad
can_exec(postgresql_t, initrc_exec_t)
Chris PeBenito ab58ad
# gross hack
Chris PeBenito ab58ad
domain_auto_trans(dpkg_t, postgresql_exec_t, postgresql_t)
Chris PeBenito ab58ad
can_exec(postgresql_t, dpkg_exec_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
dontaudit postgresql_t sysadm_home_dir_t:dir search;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# quiet ps and killall
Chris PeBenito ab58ad
dontaudit postgresql_t domain:dir { getattr search };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# for currect directory of scripts
Chris PeBenito ab58ad
allow postgresql_t { var_spool_t cron_spool_t }:dir search;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# capability kill is for shutdown script
Chris PeBenito ab58ad
allow postgresql_t self:capability { kill dac_override dac_read_search chown fowner fsetid setuid setgid sys_nice sys_tty_config };
Chris PeBenito ab58ad
dontaudit postgresql_t self:capability sys_admin;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
etcdir_domain(postgresql)
Chris PeBenito ab58ad
type postgresql_db_t, file_type, sysadmfile;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
logdir_domain(postgresql)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`crond.te', `
Chris PeBenito ab58ad
# allow crond to find /usr/lib/postgresql/bin/do.maintenance
Chris PeBenito ab58ad
allow crond_t postgresql_db_t:dir search;
Chris PeBenito ab58ad
system_crond_entry(postgresql_exec_t, postgresql_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
tmp_domain(postgresql, `', `{ dir file sock_file }')
Chris PeBenito ab58ad
file_type_auto_trans(postgresql_t, tmpfs_t, postgresql_tmp_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Use the network.
Chris PeBenito ab58ad
can_network(postgresql_t)
Chris PeBenito ab58ad
can_ypbind(postgresql_t)
Chris PeBenito ab58ad
allow postgresql_t self:fifo_file { getattr read write ioctl };
Chris PeBenito ab58ad
allow postgresql_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito ab58ad
can_unix_connect(postgresql_t, self)
Chris PeBenito ab58ad
allow postgresql_t self:unix_dgram_socket create_socket_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t self:shm create_shm_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`targeted_policy', `', `
Chris PeBenito ab58ad
bool allow_user_postgresql_connect false;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
if (allow_user_postgresql_connect) {
Chris PeBenito ab58ad
# allow any user domain to connect to the database server
Chris PeBenito ab58ad
can_tcp_connect(userdomain, postgresql_t)
Chris PeBenito ab58ad
allow userdomain postgresql_t:unix_stream_socket connectto;
Chris PeBenito ab58ad
allow userdomain postgresql_var_run_t:sock_file write;
Chris PeBenito ab58ad
allow userdomain postgresql_tmp_t:sock_file write;
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
ifdef(`consoletype.te', `
Chris PeBenito ab58ad
can_exec(postgresql_t, consoletype_exec_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`hostname.te', `
Chris PeBenito ab58ad
can_exec(postgresql_t, hostname_exec_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t postgresql_port_t:tcp_socket name_bind;
Chris PeBenito ab58ad
allow postgresql_t auth_port_t:tcp_socket name_connect;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t { proc_t self }:file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Allow access to the postgresql databases
Chris PeBenito ab58ad
create_dir_file(postgresql_t, postgresql_db_t)
Chris PeBenito ab58ad
file_type_auto_trans(postgresql_t, var_lib_t, postgresql_db_t)
Chris PeBenito ab58ad
allow postgresql_t var_lib_t:dir { getattr search };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# because postgresql start scripts are broken and put the pid file in the DB
Chris PeBenito ab58ad
# directory
Chris PeBenito ab58ad
rw_dir_file(initrc_t, postgresql_db_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# read config files
Chris PeBenito ab58ad
allow postgresql_t { etc_t etc_runtime_t }:{ file lnk_file } { read getattr };
Chris PeBenito ab58ad
r_dir_file(initrc_t, postgresql_etc_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t etc_t:dir rw_dir_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
read_sysctl(postgresql_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t devtty_t:chr_file { read write };
Chris PeBenito ab58ad
allow postgresql_t devpts_t:dir search;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t { bin_t sbin_t }:dir search;
Chris PeBenito ab58ad
allow postgresql_t { bin_t sbin_t }:lnk_file { getattr read };
Chris PeBenito ab58ad
allow postgresql_t postgresql_exec_t:lnk_file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t self:sem create_sem_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow postgresql_t initrc_var_run_t:file { getattr read lock };
Chris PeBenito ab58ad
dontaudit postgresql_t selinux_config_t:dir search;
Chris PeBenito ab58ad
allow postgresql_t mail_spool_t:dir search;
Chris PeBenito ab58ad
lock_domain(postgresql)
Chris PeBenito ab58ad
can_exec(postgresql_t, { shell_exec_t bin_t postgresql_exec_t ls_exec_t } )
Chris PeBenito ab58ad
ifdef(`apache.te', `
Chris PeBenito ab58ad
# 
Chris PeBenito ab58ad
# Allow httpd to work with postgresql
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
allow httpd_t postgresql_tmp_t:sock_file rw_file_perms;
Chris PeBenito ab58ad
can_unix_connect(httpd_t, postgresql_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`distro_gentoo', `
Chris PeBenito ab58ad
# "su - postgres ..." is called from initrc_t
Chris PeBenito ab58ad
allow initrc_su_t postgresql_db_t:dir search;
Chris PeBenito ab58ad
allow postgresql_t initrc_su_t:process sigchld;
Chris PeBenito ab58ad
dontaudit initrc_su_t sysadm_devpts_t:chr_file rw_file_perms;
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
dontaudit postgresql_t home_root_t:dir search;
Chris PeBenito ab58ad
can_kerberos(postgresql_t)
Chris PeBenito ab58ad
allow postgresql_t urandom_device_t:chr_file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
if (allow_execmem) {
Chris PeBenito ab58ad
allow postgresql_t self:process execmem;
Chris PeBenito ab58ad
}