Blob Blame History Raw
## <summary>Periodic execution of scheduled commands.</summary>

#######################################
## <summary>
##	The per user domain template for the cron module.
## </summary>
## <desc>
##	<p>
##	This template creates a derived domains which are used
##	for running programs on behalf of the user, from cron.
##	A type for the user crontab is also created.
##	</p>
##	<p>
##	This template is invoked automatically for each user, and
##	generally does not need to be invoked directly
##	by policy writers.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
## </param>
#
template(`cron_per_userdomain_template',`

	# Type of user crontabs once moved to cron spool.
	type $1_cron_spool_t, cron_spool_type;
	files_type($1_cron_spool_t)

	type $1_crond_t; # user_crond_domain;
	domain_type($1_crond_t);
	corecmd_shell_entry_type($1_crond_t)
	role $1_r types $1_crond_t;

	type $1_crontab_t;
	domain_type($1_crontab_t)
	domain_entry_file($1_crontab_t,crontab_exec_t)
	role $1_r types $1_crontab_t;

	##############################
	#
	# $1_crond_t local policy
	#

	allow $1_crond_t self:capability dac_override;
	allow $1_crond_t self:process { signal_perms setsched };
	allow $1_crond_t self:fifo_file rw_file_perms;
	allow $1_crond_t self:unix_stream_socket create_stream_socket_perms;
	allow $1_crond_t self:unix_dgram_socket create_socket_perms;

	# The entrypoint interface is not used as this is not
	# a regular entrypoint.  Since crontab files are
	# not directly executed, crond must ensure that
	# the crontab file has a type that is appropriate
	# for the domain of the user cron job.  It
	# performs an entrypoint permission check
	# for this purpose.
	allow $1_crond_t $1_cron_spool_t:file entrypoint;

	# Permit a transition from the crond_t domain to this domain.
	# The transition is requested explicitly by the modified crond 
	# via setexeccon.  There is no way to set up an automatic
	# transition, since crontabs are configuration files, not executables.
	allow crond_t $1_crond_t:process transition;
	dontaudit crond_t $1_crond_t:process { noatsecure siginh rlimitinh };
	allow crond_t $1_crond_t:fd use;
	allow $1_crond_t crond_t:fd use;
	allow $1_crond_t crond_t:fifo_file rw_file_perms;
	allow $1_crond_t crond_t:process sigchld;

	kernel_read_system_state($1_crond_t)
	kernel_read_kernel_sysctl($1_crond_t)

	# ps does not need to access /boot when run from cron
	bootloader_dontaudit_search_boot($1_crond_t)

	corenet_tcp_sendrecv_all_if($1_crond_t)
	corenet_raw_sendrecv_all_if($1_crond_t)
	corenet_udp_sendrecv_all_if($1_crond_t)
	corenet_tcp_sendrecv_all_nodes($1_crond_t)
	corenet_raw_sendrecv_all_nodes($1_crond_t)
	corenet_udp_sendrecv_all_nodes($1_crond_t)
	corenet_tcp_sendrecv_all_ports($1_crond_t)
	corenet_udp_sendrecv_all_ports($1_crond_t)
	corenet_tcp_bind_all_nodes($1_crond_t)
	corenet_udp_bind_all_nodes($1_crond_t)

	dev_read_urand($1_crond_t)

	fs_getattr_all_fs($1_crond_t)

	domain_exec_all_entry_files($1_crond_t)

	files_read_usr_files($1_crond_t)
	files_exec_etc_files($1_crond_t)
	# for nscd:
	files_dontaudit_search_pids($1_crond_t)

	corecmd_exec_bin($1_crond_t)
	corecmd_exec_sbin($1_crond_t)

	libs_use_ld_so($1_crond_t)
	libs_use_shared_libs($1_crond_t)
	libs_exec_lib_files($1_crond_t)
	libs_exec_ld_so($1_crond_t)

	files_read_etc_runtime_files($1_crond_t)

	logging_search_logs($1_crond_t)

	seutil_read_config($1_crond_t)

	miscfiles_read_localization($1_crond_t)

	tunable_policy(`fcron_crond', `
		allow crond_t $1_cron_spool_t:file create_file_perms;
	')

	optional_policy(`nis.te',`
		nis_use_ypbind($1_crond_t)
	')

	ifdef(`TODO',`
	# Access user files and dirs.
	allow $1_crond_t home_root_t:dir search;
	file_type_auto_trans($1_crond_t, $1_home_dir_t, $1_home_t)

	# Run scripts in user home directory and access shared libs.
	can_exec($1_crond_t, $1_home_t)

	file_type_auto_trans($1_crond_t, tmp_t, $1_tmp_t)

	ifdef(`mta.te', `
		domain_auto_trans($1_crond_t, sendmail_exec_t, $1_mail_t)
		allow $1_crond_t sendmail_exec_t:lnk_file r_file_perms;

		# $1_mail_t should only be reading from the cron fifo not needing to write
		dontaudit $1_mail_t crond_t:fifo_file write;
		allow mta_user_agent $1_crond_t:fd use;
	')

	allow $1_crond_t var_spool_t:dir search;
	allow $1_crond_t var_t:dir r_dir_perms;
	allow $1_crond_t var_t:file r_file_perms;

	# quiet other ps operations
	dontaudit $1_crond_t domain:dir { getattr search };
	') dnl endif TODO

	##############################
	#
	# $1_crontab_t local policy
	#

	# Transition from the user domain to the derived domain.
	domain_auto_trans($1_t, crontab_exec_t, $1_crontab_t)
	allow $1_t $1_crontab_t:fd use;
	allow $1_crontab_t $1_t:fd use;
	allow $1_crontab_t $1_t:fifo_file rw_file_perms;
	allow $1_crontab_t $1_t:process sigchld;

	# for ^Z
	allow $1_t $1_crontab_t:process signal;

	# Allow crond to read those crontabs in cron spool.
	allow crond_t $1_cron_spool_t:file r_file_perms;

	# dac_override is to create the file in the directory under /tmp
	allow $1_crontab_t self:capability { setuid setgid chown dac_override };
	allow $1_crontab_t self:process signal_perms;

	# create files in /var/spool/cron
	allow $1_crontab_t $1_cron_spool_t:file create_file_perms;
	allow $1_crontab_t cron_spool_t:dir rw_dir_perms;
	type_transition $1_crontab_t $1_cron_spool_t:file system_crond_tmp_t;

	# crontab signals crond by updating the mtime on the spooldir
	allow $1_crontab_t cron_spool_t:dir setattr;

	allow $1_crontab_t crond_log_t:file ra_file_perms;

	# for the checks used by crontab -u
	selinux_dontaudit_search_fs($1_crontab_t)

	fs_getattr_xattr_fs($1_crontab_t)

	domain_use_wide_inherit_fd($1_crontab_t)

	files_read_etc_files($1_crontab_t)
	files_dontaudit_search_pids($1_crontab_t)

	libs_use_ld_so($1_crontab_t)
	libs_use_shared_libs($1_crontab_t)

	logging_send_syslog_msg($1_crontab_t)

	miscfiles_read_localization($1_crontab_t)

	seutil_dontaudit_search_config($1_crontab_t)

	tunable_policy(`fcron_crond', `
		# fcron wants an instant update of a crontab change for the administrator
		# also crontab does a security check for crontab -u
		dontaudit $1_crontab_t crond_t:process signal;
	')

	ifdef(`TODO',`

	can_ps($1_t, $1_crontab_t)

	dontaudit $1_crontab_t proc_t:dir search;

	# Type for temporary files.
	file_type_auto_trans($1_crontab_t, tmp_t, $1_tmp_t, { dir file })

	# Run helper programs as $1_t
	domain_auto_trans($1_crontab_t, { bin_t sbin_t shell_exec_t }, $1_t)

	# Read user crontabs 
	allow $1_crontab_t { $1_home_t $1_home_dir_t }:dir r_dir_perms;  
	allow $1_crontab_t $1_home_t:file r_file_perms;  
	dontaudit $1_crontab_t $1_home_dir_t:dir write;

	# Access terminals.
	allow $1_crontab_t devpts_t:dir r_dir_perms;
	allow $1_crontab_t $1_tty_device_t:chr_file rw_file_perms;
	allow $1_crontab_t $1_devpts_t:chr_file rw_file_perms;

	# Inherit and use descriptors from gnome-pty-helper.
	ifdef(`gnome-pty-helper.te', `allow $1_crontab_t $1_gph_t:fd use;')
	') dnl endif TODO
')

#######################################
## <summary>
##	The administrative functions template for the cron module.
## </summary>
## <desc>
##	<p>
##	This template creates rules for administrating the cron service,
##	allowing the specified user to manage other user crontabs.
##	</p>
## </desc>
## <param name="userdomain_prefix">
##	The prefix of the user domain (e.g., user
##	is the prefix for user_t).
## </param>
#
template(`cron_admin_template',`
	# Allow our crontab domain to unlink a user cron spool file.
	allow $1_crontab_t cron_spool_type:file { getattr read unlink };

	logging_read_generic_logs($1_crond_t)

	# Manipulate other users crontab.
	selinux_get_fs_mount($1_crontab_t)
	selinux_validate_context($1_crontab_t)
	selinux_compute_access_vector($1_crontab_t)
	selinux_compute_create_context($1_crontab_t)
	selinux_compute_relabel_context($1_crontab_t)
	selinux_compute_user_contexts($1_crontab_t)

	tunable_policy(`fcron_crond', `
		# fcron wants an instant update of a crontab change for the administrator
		# also crontab does a security check for crontab -u
		allow $1_crontab_t self:process setfscreate;
		selinux_get_fs_mount($1_crontab_t)
	')
')

########################################
## <summary>
##	Make the specified program domain accessable
##	from the system cron jobs.
## </summary>
## <param name="domain">
##	The type of the process to transition to.
## </param>
## <param name="entrypoint">
##	The type of the file used as an entrypoint to this domain.
## </param>
#
interface(`cron_system_entry',`
	gen_require(`
		type crond_t, system_crond_t;
		class fd use;
		class fifo_file rw_file_perms;
		class process sigchld;
	')

	domain_auto_trans(system_crond_t, $2, $1)

	# cjp: perhaps these four rules from the old
	# domain_auto_trans are not needed?
	allow system_crond_t $1:fd use;
	allow $1 system_crond_t:fd use;
	allow $1 system_crond_t:fifo_file rw_file_perms;
	allow $1 system_crond_t:process sigchld;

	allow $1 crond_t:fifo_file { getattr read write ioctl };
	allow $1 crond_t:fd use;
	allow $1 crond_t:process sigchld;
')

########################################
## <summary>
##	Read a cron daemon unnamed pipe
## </summary>
## <param name="domain">
##	The type of the process to performing this action.
## </param>
#
interface(`cron_read_pipe',`
	gen_require(`
		type crond_t;
		class file r_file_perms;
	')

	allow $1 crond_t:file r_file_perms;
')


########################################
## <summary>
##	Read and write the cron daemon log files.
## </summary>
## <param name="domain">
##	The type of the process to performing this action.
## </param>
#
interface(`cron_rw_log',`
	gen_require(`
		type crond_log_t;
		class file rw_file_perms;
	')

	logging_search_logs($1)
	allow $1 crond_log_t:file rw_file_perms;
')

########################################
## <summary>
##	Search the directory containing user cron tables.
## </summary>
## <param name="domain">
##	The type of the process to performing this action.
## </param>
#
interface(`cron_search_spool',`
	gen_require(`
		type cron_spool_t;
		class dir search;
	')

	files_search_spool($1)
	allow $1 cron_spool_t:dir search;
')