policy_module(couchdb, 1.1.1)

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

type couchdb_t;
type couchdb_exec_t;
init_daemon_domain(couchdb_t, couchdb_exec_t)

type couchdb_initrc_exec_t;
init_script_file(couchdb_initrc_exec_t)

type couchdb_conf_t;
files_config_file(couchdb_conf_t)

type couchdb_log_t;
logging_log_file(couchdb_log_t)

type couchdb_tmp_t;
files_tmp_file(couchdb_tmp_t)

type couchdb_var_lib_t;
files_type(couchdb_var_lib_t)

type couchdb_var_run_t;
files_pid_file(couchdb_var_run_t)

type couchdb_unit_file_t;
systemd_unit_file(couchdb_unit_file_t)

########################################
#
# Local policy
#

allow couchdb_t self:process { execmem setsched signal signull sigkill };
allow couchdb_t self:fifo_file rw_fifo_file_perms;
allow couchdb_t self:unix_stream_socket create_stream_socket_perms;
allow couchdb_t self:unix_dgram_socket create_socket_perms;
allow couchdb_t self:tcp_socket { accept listen };

manage_files_pattern(couchdb_t, couchdb_conf_t, couchdb_conf_t)

manage_dirs_pattern(couchdb_t, couchdb_log_t, couchdb_log_t)
append_files_pattern(couchdb_t, couchdb_log_t, couchdb_log_t)
create_files_pattern(couchdb_t, couchdb_log_t, couchdb_log_t)
setattr_files_pattern(couchdb_t, couchdb_log_t, couchdb_log_t)
logging_log_filetrans(couchdb_t, couchdb_log_t, dir)

manage_dirs_pattern(couchdb_t, couchdb_tmp_t, couchdb_tmp_t)
manage_files_pattern(couchdb_t, couchdb_tmp_t, couchdb_tmp_t)
files_tmp_filetrans(couchdb_t, couchdb_tmp_t, { dir file })

manage_dirs_pattern(couchdb_t, couchdb_var_lib_t, couchdb_var_lib_t)
manage_files_pattern(couchdb_t, couchdb_var_lib_t, couchdb_var_lib_t)
files_var_lib_filetrans(couchdb_t, couchdb_var_lib_t, dir)

manage_dirs_pattern(couchdb_t, couchdb_var_run_t, couchdb_var_run_t)
manage_files_pattern(couchdb_t, couchdb_var_run_t, couchdb_var_run_t)
files_pid_filetrans(couchdb_t, couchdb_var_run_t, {file dir })

can_exec(couchdb_t, couchdb_exec_t)

kernel_read_network_state(couchdb_t)
kernel_read_system_state(couchdb_t)
kernel_read_fs_sysctls(couchdb_t)
kernel_dgram_send(couchdb_t)

corecmd_exec_bin(couchdb_t)
corecmd_exec_shell(couchdb_t)

corenet_all_recvfrom_unlabeled(couchdb_t)
corenet_all_recvfrom_netlabel(couchdb_t)
corenet_tcp_sendrecv_generic_if(couchdb_t)
corenet_tcp_sendrecv_generic_node(couchdb_t)
corenet_tcp_bind_generic_node(couchdb_t)

corenet_sendrecv_couchdb_server_packets(couchdb_t)
corenet_tcp_bind_couchdb_port(couchdb_t)
corenet_tcp_sendrecv_couchdb_port(couchdb_t)

# disksup tries to monitor the local disks
fs_getattr_all_files(couchdb_t)
fs_getattr_all_dirs(couchdb_t)
fs_getattr_all_fs(couchdb_t)
files_getattr_all_mountpoints(couchdb_t)
files_search_all_mountpoints(couchdb_t)
files_getattr_lost_found_dirs(couchdb_t)
files_dontaudit_list_var(couchdb_t)

dev_list_sysfs(couchdb_t)
dev_read_sysfs(couchdb_t)
dev_read_urand(couchdb_t)

auth_use_nsswitch(couchdb_t)

optional_policy(`
    gnome_dontaudit_search_config(couchdb_t)
')

optional_policy(`
    rpc_read_nfs_state_data(couchdb_t)
')


