## <summary>CLI for running app containers</summary>

########################################
## <summary>
##	Execute rkt_exec_t in the rkt domain.
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed to transition.
## </summary>
## </param>
#
interface(`rkt_domtrans',`
	gen_require(`
		type rkt_t, rkt_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, rkt_exec_t, rkt_t)
')

######################################
## <summary>
##	Execute rkt in the caller domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`rkt_exec',`
	gen_require(`
		type rkt_exec_t;
	')

	corecmd_search_bin($1)
	can_exec($1, rkt_exec_t)
')

########################################
## <summary>
##	Search rkt lib directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`rkt_search_lib',`
	gen_require(`
		type rkt_var_lib_t;
	')

	allow $1 rkt_var_lib_t:dir search_dir_perms;
	files_search_var_lib($1)
')

########################################
## <summary>
##	Read rkt lib files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`rkt_read_lib_files',`
	gen_require(`
		type rkt_var_lib_t;
	')

	files_search_var_lib($1)
	read_files_pattern($1, rkt_var_lib_t, rkt_var_lib_t)
')

########################################
## <summary>
##	Manage rkt lib files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`rkt_manage_lib_files',`
	gen_require(`
		type rkt_var_lib_t;
	')

	files_search_var_lib($1)
	manage_files_pattern($1, rkt_var_lib_t, rkt_var_lib_t)
')

########################################
## <summary>
##	Manage rkt lib directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`rkt_manage_lib_dirs',`
	gen_require(`
		type rkt_var_lib_t;
	')

	files_search_var_lib($1)
	manage_dirs_pattern($1, rkt_var_lib_t, rkt_var_lib_t)
')

########################################
## <summary>
##	Execute rkt server in the rkt domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`rkt_systemctl',`
	gen_require(`
		type rkt_t;
		type rkt_unit_file_t;
	')

	systemd_exec_systemctl($1)
        systemd_read_fifo_file_passwd_run($1)
	allow $1 rkt_unit_file_t:file read_file_perms;
	allow $1 rkt_unit_file_t:service manage_service_perms;

	ps_process_pattern($1, rkt_t)
')


########################################
## <summary>
##	All of the rules required to administrate
##	an rkt environment
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`rkt_admin',`
	gen_require(`
		type rkt_t;
		type rkt_var_lib_t;
	type rkt_unit_file_t;
	')

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

    tunable_policy(`deny_ptrace',`',`
        allow $1 rkt_t:process ptrace;
    ')

	files_search_var_lib($1)
	admin_pattern($1, rkt_var_lib_t)

	rkt_systemctl($1)
	admin_pattern($1, rkt_unit_file_t)
	allow $1 rkt_unit_file_t:service all_service_perms;
	optional_policy(`
		systemd_passwd_agent_exec($1)
		systemd_read_fifo_file_passwd_run($1)
	')
')
