
## <summary>policy for icinga</summary>

########################################
## <summary>
##	Transition to icinga.
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed to transition.
## </summary>
## </param>
#
interface(`icinga_domtrans',`
	gen_require(`
		type icinga_t, icinga_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, icinga_exec_t, icinga_t)
')

########################################
## <summary>
##	Execute icinga server in the icinga domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_initrc_domtrans',`
	gen_require(`
		type icinga_initrc_exec_t;
	')

	init_labeled_script_domtrans($1, icinga_initrc_exec_t)
')

########################################
## <summary>
##	For domains icinga should transition to (e.g. Plugins).
## </summary>
## <param name="executable">
## <summary>
##	Context of the executable.
## </summary>
## </param>
## <param name="domain">
## <summary>
##	Domain icinga should transition to. 
## </summary>
## </param>
#
interface(`icinga_execstrans',`
	gen_require(`
		type icinga_t, icinga_tmp_t;
	')

	domtrans_pattern(icinga_t, $1, $2)
	dontaudit $2 icinga_tmp_t:file { read write }; # leaked filedescriptor
')

########################################
## <summary>
##	Read icinga's log files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`icinga_read_log',`
	gen_require(`
		type icinga_log_t;
	')

	logging_search_logs($1)
	read_files_pattern($1, icinga_log_t, icinga_log_t)
')

########################################
## <summary>
##	Append to icinga log files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_append_log',`
	gen_require(`
		type icinga_log_t;
	')

	logging_search_logs($1)
	append_files_pattern($1, icinga_log_t, icinga_log_t)
')

########################################
## <summary>
##	Manage icinga log files
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_manage_log',`
	gen_require(`
		type icinga_log_t;
	')

	logging_search_logs($1)
	manage_dirs_pattern($1, icinga_log_t, icinga_log_t)
	manage_files_pattern($1, icinga_log_t, icinga_log_t)
	manage_lnk_files_pattern($1, icinga_log_t, icinga_log_t)
')
########################################
## <summary>
##	Read icinga PID files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_read_pid_files',`
	gen_require(`
		type icinga_var_run_t;
	')

	files_search_pids($1)
	allow $1 icinga_var_run_t:file read_file_perms;
')


########################################
## <summary>
##	Search icinga spool directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_search_spool',`
	gen_require(`
		type icinga_spool_t;
	')

	allow $1 icinga_spool_t:dir search_dir_perms;
	files_search_spool($1)
')

########################################
## <summary>
##	Read icinga spool files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_read_spool_files',`
	gen_require(`
		type icinga_spool_t;
	')

	files_search_spool($1)
	read_files_pattern($1, icinga_spool_t, icinga_spool_t)
')

########################################
## <summary>
##	Manage icinga spool files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_manage_spool_files',`
	gen_require(`
		type icinga_spool_t;
	')

	files_search_spool($1)
	manage_files_pattern($1, icinga_spool_t, icinga_spool_t)
')

########################################
## <summary>
##	Manage icinga spool dirs.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`icinga_manage_spool_dirs',`
	gen_require(`
		type icinga_spool_t;
	')

	files_search_spool($1)
	manage_dirs_pattern($1, icinga_spool_t, icinga_spool_t)
')


########################################
## <summary>
##	Send icinga commands through pipe.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to send commands.
##	</summary>
## </param>
#
interface(`icinga_send_commands',`
	gen_require(`
		type icinga_spool_t;
	')

	files_search_spool($1)
	read_files_pattern($1, icinga_spool_t, icinga_spool_t)
	read_files_pattern($1, icinga_command_t, icinga_command_t)
	write_fifo_files_pattern($1, icinga_command_t, icinga_command_t)
')

########################################
## <summary>
##	All of the rules required to administrate
##	an icinga environment
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`icinga_admin',`
	gen_require(`
		type icinga_t;
		type icinga_initrc_exec_t;
		type icinga_log_t;
		type icinga_var_run_t;
		type icinga_spool_t;
	')

	allow $1 icinga_t:process { ptrace signal_perms };
	ps_process_pattern($1, icinga_t)

	icinga_initrc_domtrans($1)
	domain_system_change_exemption($1)
	role_transition $2 icinga_initrc_exec_t system_r;
	allow $2 system_r;

	logging_search_logs($1)
	admin_pattern($1, icinga_log_t)

	files_search_pids($1)
	admin_pattern($1, icinga_var_run_t)

	files_search_spool($1)
	admin_pattern($1, icinga_spool_t)
	optional_policy(`
		systemd_passwd_agent_exec($1)
		systemd_read_fifo_file_passwd_run($1)
	')
')

## <summary>policy for ido2db</summary>

########################################
## <summary>
##	Transition to ido2db.
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed to transition.
## </summary>
## </param>
#
interface(`ido2db_domtrans',`
	gen_require(`
		type ido2db_t, ido2db_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, ido2db_exec_t, ido2db_t)
')

########################################
## <summary>
##	Execute ido2db server in the ido2db domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ido2db_initrc_domtrans',`
	gen_require(`
		type ido2db_initrc_exec_t;
	')

	init_labeled_script_domtrans($1, ido2db_initrc_exec_t)
')

########################################
## <summary>
##	Connect to ido2db using a unix domain stream socket
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed access.
## </summary>
## </param>
#
interface(`ido2db_stream_connect',`
	gen_require(`
		type ido2db_t;
	')

	stream_connect_pattern($1, icinga_spool_t, icinga_spool_t, ido2db_t)
')

########################################
## <summary>
##	All of the rules required to administrate
##	an ido2db environment
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`ido2db_admin',`
	gen_require(`
		type ido2db_t;
		type ido2db_initrc_exec_t;
	')

	allow $1 ido2db_t:process { ptrace signal_perms };
	ps_process_pattern($1, ido2db_t)

	ido2db_initrc_domtrans($1)
	domain_system_change_exemption($1)
	role_transition $2 ido2db_initrc_exec_t system_r;
	allow $2 system_r;
	optional_policy(`
		systemd_passwd_agent_exec($1)
		systemd_read_fifo_file_passwd_run($1)
	')
')
