Blob Blame History Raw

########################################
#
# cron_per_userdomain_template(domainprefix)
#

template(`cron_per_userdomain_template',`

	# Type of user crontabs once moved to cron spool.
	type $1_cron_spool_t;
	files_file_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_generic_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;
	')

	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;
	')

	# This domain is granted permissions common to most domains.
	can_ypbind($1_crond_t)
	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
	#

	# 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;

	fs_getattr_xattr_fs($1_crontab_t)

	domain_use_wide_inherit_fd($1_crontab_t)

	files_read_generic_etc_files($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)

	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',`

	# Transition from the user domain to the derived domain.
	domain_auto_trans($1_t, crontab_exec_t, $1_crontab_t)

	can_ps($1_t, $1_crontab_t)

	dontaudit $1_crontab_t proc_t:dir search;
	dontaudit $1_crontab_t selinux_config_t:dir search;
	# for the checks used by crontab -u
	dontaudit $1_crontab_t security_t:dir search;

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

	# Use the type when creating files in /var/spool/cron.
	allow sysadm_crontab_t $1_cron_spool_t:file { getattr read };

	# Run helper programs as $1_t
	allow $1_crontab_t { bin_t sbin_t }:dir search;
	allow $1_crontab_t bin_t:lnk_file read;
	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;')

	dontaudit $1_crontab_t var_run_t:dir search;
	') dnl endif TODO
')

########################################
#
# cron_admin_template(domainprefix)
#

template(`cron_admin_template',`
	logging_read_generic_logs($1_crond_t)

	# Allow our crontab domain to unlink a user cron spool file.
	#allow $1_crontab_t user_cron_spool_t:file unlink;

	# 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)
	')
')

########################################
#
# cron_rw_log(domain)
#
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;
')