policy_module(stapserver, 1.1.1)

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

type stapserver_t;
type stapserver_exec_t;
init_daemon_domain(stapserver_t, stapserver_exec_t)

type stapserver_var_lib_t;
files_type(stapserver_var_lib_t)

type stapserver_log_t;
logging_log_file(stapserver_log_t)

type stapserver_var_run_t;
files_pid_file(stapserver_var_run_t)

type stapserver_tmp_t;
files_tmp_file(stapserver_tmp_t)

type stapserver_tmpfs_t;
userdom_user_tmpfs_file(stapserver_tmpfs_t)

########################################
#
# stapserver local policy
#

#runuser
allow stapserver_t self:capability { setuid setgid };
allow stapserver_t self:process setsched;

allow stapserver_t self:capability { dac_read_search  kill sys_ptrace};
allow stapserver_t self:process { setrlimit signal };

allow stapserver_t self:fifo_file rw_fifo_file_perms;
allow stapserver_t self:key write;
allow stapserver_t self:unix_stream_socket create_stream_socket_perms;
allow stapserver_t self:tcp_socket { accept listen };

manage_dirs_pattern(stapserver_t, stapserver_var_lib_t, stapserver_var_lib_t)
manage_files_pattern(stapserver_t, stapserver_var_lib_t, stapserver_var_lib_t)
files_var_lib_filetrans(stapserver_t, stapserver_var_lib_t, dir)
allow stapserver_t stapserver_var_lib_t:file map;

manage_dirs_pattern(stapserver_t, stapserver_log_t, stapserver_log_t)
manage_files_pattern(stapserver_t, stapserver_log_t, stapserver_log_t)
logging_log_filetrans(stapserver_t, stapserver_log_t, dir )

manage_dirs_pattern(stapserver_t, stapserver_tmp_t, stapserver_tmp_t)
manage_files_pattern(stapserver_t, stapserver_tmp_t, stapserver_tmp_t)
manage_lnk_files_pattern(stapserver_t, stapserver_tmp_t, stapserver_tmp_t)
files_tmp_filetrans(stapserver_t, stapserver_tmp_t, { file dir })
allow stapserver_t stapserver_tmp_t:file { execute map };

manage_dirs_pattern(stapserver_t, stapserver_var_run_t, stapserver_var_run_t)
manage_files_pattern(stapserver_t, stapserver_var_run_t, stapserver_var_run_t)
files_pid_filetrans(stapserver_t, stapserver_var_run_t, dir )

manage_files_pattern(stapserver_t, stapserver_tmpfs_t, stapserver_tmpfs_t)
manage_dirs_pattern(stapserver_t, stapserver_tmpfs_t, stapserver_tmpfs_t)
fs_tmpfs_filetrans(stapserver_t, stapserver_tmpfs_t, { file dir })

kernel_read_system_state(stapserver_t)
kernel_read_kernel_sysctls(stapserver_t)
kernel_read_fs_sysctls(stapserver_t)
files_list_kernel_modules(stapserver_t)

corecmd_exec_bin(stapserver_t)
corecmd_exec_shell(stapserver_t)

domain_read_all_domains_state(stapserver_t)
domain_use_interactive_fds(stapserver_t)

dev_read_sysfs(stapserver_t)
dev_read_rand(stapserver_t)
dev_read_urand(stapserver_t)

files_list_tmp(stapserver_t)
files_search_kernel_modules(stapserver_t)

fs_search_cgroup_dirs(stapserver_t)
fs_getattr_all_fs(stapserver_t)

auth_use_nsswitch(stapserver_t)

init_read_utmp(stapserver_t)

logging_send_audit_msgs(stapserver_t)
logging_send_syslog_msg(stapserver_t)

#lspci
miscfiles_read_hwdata(stapserver_t)

systemd_dbus_chat_logind(stapserver_t)

userdom_use_user_terminals(stapserver_t)

optional_policy(`
    avahi_dbus_chat(stapserver_t)
')

optional_policy(`
	consoletype_exec(stapserver_t)
')

optional_policy(`
	dbus_system_bus_client(stapserver_t)
')

optional_policy(`
	hostname_exec(stapserver_t)
')

optional_policy(`
	plymouthd_exec_plymouth(stapserver_t)
')

optional_policy(`
	rpm_exec(stapserver_t)
')

optional_policy(`
	rpc_search_nfs_state_data(stapserver_t)
')
