policy_module(redis, 1.0.1)

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

## <desc>
## <p>
## Allow Redis to run redis-sentinal notification scripts.
## </p>
## </desc>
gen_tunable(redis_enable_notify, false)

type redis_t;
type redis_exec_t;
init_daemon_domain(redis_t, redis_exec_t)

type redis_initrc_exec_t;
init_script_file(redis_initrc_exec_t)

type redis_conf_t;
files_config_file(redis_conf_t)

type redis_log_t;
logging_log_file(redis_log_t)

type redis_var_lib_t;
files_type(redis_var_lib_t)

type redis_var_run_t;
files_pid_file(redis_var_run_t)

type redis_tmp_t;
files_tmp_file(redis_tmp_t)

type redis_unit_file_t;
systemd_unit_file(redis_unit_file_t)

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

allow redis_t self:process { setrlimit signal_perms };
allow redis_t self:fifo_file rw_fifo_file_perms;
allow redis_t self:unix_stream_socket create_stream_socket_perms;
allow redis_t self:tcp_socket create_stream_socket_perms;

manage_files_pattern(redis_t, redis_conf_t, redis_conf_t)

manage_dirs_pattern(redis_t, redis_log_t, redis_log_t)
manage_files_pattern(redis_t, redis_log_t, redis_log_t)
manage_lnk_files_pattern(redis_t, redis_log_t, redis_log_t)

manage_dirs_pattern(redis_t, redis_var_lib_t, redis_var_lib_t)
manage_files_pattern(redis_t, redis_var_lib_t, redis_var_lib_t)
manage_lnk_files_pattern(redis_t, redis_var_lib_t, redis_var_lib_t)

manage_dirs_pattern(redis_t, redis_var_run_t, redis_var_run_t)
manage_files_pattern(redis_t, redis_var_run_t, redis_var_run_t)
manage_lnk_files_pattern(redis_t, redis_var_run_t, redis_var_run_t)
manage_sock_files_pattern(redis_t, redis_var_run_t, redis_var_run_t)


manage_dirs_pattern(redis_t, redis_tmp_t, redis_tmp_t)
manage_files_pattern(redis_t, redis_tmp_t, redis_tmp_t)
files_tmp_filetrans(redis_t, redis_tmp_t, { dir file })

kernel_read_system_state(redis_t)
kernel_read_net_sysctls(redis_t)

corenet_all_recvfrom_unlabeled(redis_t)
corenet_all_recvfrom_netlabel(redis_t)
corenet_tcp_sendrecv_generic_if(redis_t)
corenet_tcp_sendrecv_generic_node(redis_t)
corenet_tcp_bind_generic_node(redis_t)
corenet_tcp_connect_redis_port(redis_t)

corenet_sendrecv_redis_server_packets(redis_t)
corenet_tcp_bind_redis_port(redis_t)
corenet_tcp_sendrecv_redis_port(redis_t)

dev_read_sysfs(redis_t)
dev_read_urand(redis_t)

logging_send_syslog_msg(redis_t)

sysnet_dns_name_resolve(redis_t)

tunable_policy(`redis_enable_notify',`
	# allow httpd to connect to mail servers
	corenet_tcp_connect_smtp_port(redis_t)
	corenet_sendrecv_smtp_client_packets(redis_t)
	corenet_tcp_connect_pop_port(redis_t)
    corenet_sendrecv_pop_client_packets(redis_t)

    corecmd_exec_bin(redis_t)
    corecmd_exec_shell(redis_t)

	fs_getattr_tmpfs(redis_t)
	fs_getattr_xattr_fs(redis_t)
')

optional_policy(`
	tunable_policy(`redis_enable_notify',`
		auth_read_passwd_file(redis_t)
	')
')

optional_policy(`
    tunable_policy(`redis_enable_notify',`
	    mta_send_mail(redis_t)
	    mta_signal_system_mail(redis_t)
    ')
')

optional_policy(`
    tunable_policy(`redis_enable_notify',`
        postfix_rw_spool_maildrop_files(redis_t)
    ')
')

optional_policy(`
    sssd_read_public_files(redis_t)
    sssd_search_lib(redis_t)
')

optional_policy(`
	tunable_policy(`redis_enable_notify',`
		systemd_userdbd_stream_connect(redis_t)
	')
')
