4c5ec89
4c5ec89
## <summary>policy for tomcat</summary>
4c5ec89
4c5ec89
######################################
4c5ec89
## <summary>
4c5ec89
##      Creates types and rules for a basic
4c5ec89
##      tomcat daemon domain.
4c5ec89
## </summary>
4c5ec89
## <param name="prefix">
4c5ec89
##      <summary>
4c5ec89
##      Prefix for the domain.
4c5ec89
##      </summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
template(`tomcat_domain_template',`
4c5ec89
        gen_require(`
4c5ec89
                attribute tomcat_domain;
4c5ec89
        ')
4c5ec89
4c5ec89
	type $1_t, tomcat_domain;
e1b6c60
	type $1_exec_t;
e1b6c60
	init_daemon_domain($1_t, $1_exec_t)
e1b6c60
e1b6c60
	type $1_cache_t;
023eb19
	files_type($1_cache_t)
e1b6c60
e1b6c60
	type $1_log_t;
023eb19
	logging_log_file($1_log_t)
e1b6c60
e1b6c60
	type $1_var_lib_t;
023eb19
	files_type($1_var_lib_t)
e1b6c60
e1b6c60
	type $1_var_run_t;
023eb19
	files_pid_file($1_var_run_t)
e1b6c60
e1b6c60
	type $1_tmp_t;
023eb19
	files_tmp_file($1_tmp_t)
e1b6c60
e1b6c60
	##################################
e1b6c60
	#
e1b6c60
	# Local policy
e1b6c60
	#
e1b6c60
e1b6c60
	manage_dirs_pattern($1_t, $1_cache_t, $1_cache_t)
e1b6c60
	manage_files_pattern($1_t, $1_cache_t, $1_cache_t)
e1b6c60
	manage_lnk_files_pattern($1_t, $1_cache_t, $1_cache_t)
e1b6c60
	files_var_filetrans($1_t, $1_cache_t, { dir file })
e1b6c60
e1b6c60
	manage_dirs_pattern($1_t, $1_log_t, $1_log_t)
e1b6c60
	manage_files_pattern($1_t, $1_log_t, $1_log_t)
e7d729c
	manage_lnk_files_pattern($1_t, $1_log_t, $1_log_t)
e1b6c60
	logging_log_filetrans($1_t, $1_log_t, { dir file })
e1b6c60
e1b6c60
	manage_dirs_pattern($1_t, $1_var_lib_t, $1_var_lib_t)
e1b6c60
	manage_files_pattern($1_t, $1_var_lib_t, $1_var_lib_t)
e7d729c
	manage_lnk_files_pattern($1_t, $1_var_lib_t, $1_var_lib_t)
e7d729c
	files_var_lib_filetrans($1_t, $1_var_lib_t, { dir file lnk_file })
e1b6c60
e1b6c60
	manage_dirs_pattern($1_t, $1_var_run_t, $1_var_run_t)
e1b6c60
	manage_files_pattern($1_t, $1_var_run_t, $1_var_run_t)
e7d729c
	manage_lnk_files_pattern($1_t, $1_var_run_t, $1_var_run_t)
e7d729c
	files_pid_filetrans($1_t, $1_var_run_t, { dir file lnk_file })
e1b6c60
e1b6c60
	manage_dirs_pattern($1_t, $1_tmp_t, $1_tmp_t)
e1b6c60
	manage_files_pattern($1_t, $1_tmp_t, $1_tmp_t)
e1b6c60
	manage_fifo_files_pattern($1_t, $1_tmp_t, $1_tmp_t)
e1b6c60
	files_tmp_filetrans($1_t, $1_tmp_t, { file fifo_file dir })
4c5ec89
4c5ec89
	can_exec($1_t, $1_exec_t)
4c5ec89
1bafb67
	kernel_read_system_state($1_t)
e7d729c
d8b106c
	logging_send_syslog_msg($1_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Transition to tomcat.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
## <summary>
4c5ec89
##	Domain allowed to transition.
4c5ec89
## </summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_domtrans',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_t, tomcat_exec_t;
4c5ec89
	')
4c5ec89
4c5ec89
	corecmd_search_bin($1)
4c5ec89
	domtrans_pattern($1, tomcat_exec_t, tomcat_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Search tomcat cache directories.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_search_cache',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_cache_t;
4c5ec89
	')
4c5ec89
4c5ec89
	allow $1 tomcat_cache_t:dir search_dir_perms;
4c5ec89
	files_search_var($1)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Read tomcat cache files.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_read_cache_files',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_cache_t;
4c5ec89
	')
4c5ec89
4c5ec89
	files_search_var($1)
4c5ec89
	read_files_pattern($1, tomcat_cache_t, tomcat_cache_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Create, read, write, and delete
4c5ec89
##	tomcat cache files.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_manage_cache_files',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_cache_t;
4c5ec89
	')
4c5ec89
4c5ec89
	files_search_var($1)
4c5ec89
	manage_files_pattern($1, tomcat_cache_t, tomcat_cache_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Manage tomcat cache dirs.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_manage_cache_dirs',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_cache_t;
4c5ec89
	')
4c5ec89
4c5ec89
	files_search_var($1)
4c5ec89
	manage_dirs_pattern($1, tomcat_cache_t, tomcat_cache_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Read tomcat's log files.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
## <rolecap/>
4c5ec89
#
4c5ec89
interface(`tomcat_read_log',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_log_t;
4c5ec89
	')
4c5ec89
4c5ec89
	logging_search_logs($1)
4c5ec89
	read_files_pattern($1, tomcat_log_t, tomcat_log_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Append to tomcat log files.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_append_log',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_log_t;
4c5ec89
	')
4c5ec89
4c5ec89
	logging_search_logs($1)
4c5ec89
	append_files_pattern($1, tomcat_log_t, tomcat_log_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Manage tomcat log files
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_manage_log',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_log_t;
4c5ec89
	')
4c5ec89
4c5ec89
	logging_search_logs($1)
4c5ec89
	manage_dirs_pattern($1, tomcat_log_t, tomcat_log_t)
4c5ec89
	manage_files_pattern($1, tomcat_log_t, tomcat_log_t)
4c5ec89
	manage_lnk_files_pattern($1, tomcat_log_t, tomcat_log_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Search tomcat lib directories.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_search_lib',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_var_lib_t;
4c5ec89
	')
4c5ec89
4c5ec89
	allow $1 tomcat_var_lib_t:dir search_dir_perms;
4c5ec89
	files_search_var_lib($1)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Read tomcat lib files.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_read_lib_files',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_var_lib_t;
4c5ec89
	')
4c5ec89
4c5ec89
	files_search_var_lib($1)
4c5ec89
	read_files_pattern($1, tomcat_var_lib_t, tomcat_var_lib_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Manage tomcat lib files.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_manage_lib_files',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_var_lib_t;
4c5ec89
	')
4c5ec89
4c5ec89
	files_search_var_lib($1)
4c5ec89
	manage_files_pattern($1, tomcat_var_lib_t, tomcat_var_lib_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Manage tomcat lib directories.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_manage_lib_dirs',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_var_lib_t;
4c5ec89
	')
4c5ec89
4c5ec89
	files_search_var_lib($1)
4c5ec89
	manage_dirs_pattern($1, tomcat_var_lib_t, tomcat_var_lib_t)
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Read tomcat PID files.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_read_pid_files',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_var_run_t;
4c5ec89
	')
4c5ec89
4c5ec89
	files_search_pids($1)
4c5ec89
	allow $1 tomcat_var_run_t:file read_file_perms;
4c5ec89
')
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	Execute tomcat server in the tomcat domain.
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed to transition.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
#
4c5ec89
interface(`tomcat_systemctl',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_t;
4c5ec89
		type tomcat_unit_file_t;
4c5ec89
	')
4c5ec89
4c5ec89
	systemd_exec_systemctl($1)
4c5ec89
	allow $1 tomcat_unit_file_t:file read_file_perms;
4c5ec89
	allow $1 tomcat_unit_file_t:service manage_service_perms;
4c5ec89
4c5ec89
	ps_process_pattern($1, tomcat_t)
4c5ec89
')
4c5ec89
4c5ec89
4c5ec89
########################################
4c5ec89
## <summary>
4c5ec89
##	All of the rules required to administrate
4c5ec89
##	an tomcat environment
4c5ec89
## </summary>
4c5ec89
## <param name="domain">
4c5ec89
##	<summary>
4c5ec89
##	Domain allowed access.
4c5ec89
##	</summary>
4c5ec89
## </param>
4c5ec89
## <rolecap/>
4c5ec89
#
4c5ec89
interface(`tomcat_admin',`
4c5ec89
	gen_require(`
4c5ec89
		type tomcat_t;
4c5ec89
		type tomcat_cache_t;
4c5ec89
		type tomcat_log_t;
4c5ec89
		type tomcat_var_lib_t;
4c5ec89
		type tomcat_var_run_t;
4c5ec89
	type tomcat_unit_file_t;
4c5ec89
	')
4c5ec89
4c5ec89
	allow $1 tomcat_t:process { ptrace signal_perms };
4c5ec89
	ps_process_pattern($1, tomcat_t)
4c5ec89
4c5ec89
	files_search_var($1)
4c5ec89
	admin_pattern($1, tomcat_cache_t)
4c5ec89
4c5ec89
	logging_search_logs($1)
4c5ec89
	admin_pattern($1, tomcat_log_t)
4c5ec89
4c5ec89
	files_search_var_lib($1)
4c5ec89
	admin_pattern($1, tomcat_var_lib_t)
4c5ec89
4c5ec89
	files_search_pids($1)
4c5ec89
	admin_pattern($1, tomcat_var_run_t)
4c5ec89
4c5ec89
	tomcat_systemctl($1)
4c5ec89
	admin_pattern($1, tomcat_unit_file_t)
4c5ec89
	allow $1 tomcat_unit_file_t:service all_service_perms;
4c5ec89
	optional_policy(`
4c5ec89
		systemd_passwd_agent_exec($1)
4c5ec89
		systemd_read_fifo_file_passwd_run($1)
4c5ec89
	')
4c5ec89
')