policy_module(condor, 1.0.1)

########################################
#
# Declarations
#

## <desc>
##	<p>
##	Determine whether Condor can connect
##	to the network using TCP.
##	</p>
## </desc>
gen_tunable(condor_tcp_network_connect, false)

attribute condor_domain;

type condor_master_t, condor_domain;
type condor_master_exec_t;
init_daemon_domain(condor_master_t, condor_master_exec_t)

type condor_master_tmp_t;
files_tmp_file(condor_master_tmp_t)

type condor_initrc_exec_t;
init_script_file(condor_initrc_exec_t)

type condor_schedd_tmp_t;
files_tmp_file(condor_schedd_tmp_t)

type condor_startd_tmp_t;
files_tmp_file(condor_startd_tmp_t)

type condor_startd_tmpfs_t;
files_tmpfs_file(condor_startd_tmpfs_t)

type condor_conf_t alias condor_etc_rw_t;
files_config_file(condor_conf_t)

type condor_log_t;
logging_log_file(condor_log_t)

type condor_var_lib_t;
files_type(condor_var_lib_t)

type condor_var_lock_t;
files_lock_file(condor_var_lock_t)

type condor_var_run_t;
files_pid_file(condor_var_run_t)

type condor_unit_file_t;
systemd_unit_file(condor_unit_file_t)

condor_domain_template(collector)
condor_domain_template(negotiator)
condor_domain_template(procd)
condor_domain_template(schedd)
condor_domain_template(startd)

#####################################
#
# Global local policy
#

allow condor_domain self:capability { dac_read_search  };
allow condor_domain self:capability2 block_suspend;

allow condor_domain self:process signal_perms;
allow condor_domain self:fifo_file rw_fifo_file_perms;
allow condor_domain self:tcp_socket create_stream_socket_perms;
allow condor_domain self:udp_socket create_socket_perms;
allow condor_domain self:unix_stream_socket create_stream_socket_perms;
allow condor_domain self:netlink_route_socket r_netlink_socket_perms;

allow condor_domain condor_etc_rw_t:dir list_dir_perms;
rw_files_pattern(condor_domain, condor_etc_rw_t, condor_etc_rw_t)

rw_files_pattern(condor_domain, condor_conf_t, condor_conf_t)

manage_dirs_pattern(condor_domain, condor_log_t, condor_log_t)
manage_files_pattern(condor_domain, condor_log_t, condor_log_t)
logging_log_filetrans(condor_domain, condor_log_t, { dir file })

manage_dirs_pattern(condor_domain, condor_var_lib_t, condor_var_lib_t)
manage_files_pattern(condor_domain, condor_var_lib_t, condor_var_lib_t)
files_var_lib_filetrans(condor_domain, condor_var_lib_t, { dir file })

manage_dirs_pattern(condor_domain, condor_var_lock_t, condor_var_lock_t)
manage_files_pattern(condor_domain, condor_var_lock_t, condor_var_lock_t)
files_lock_filetrans(condor_domain, condor_var_lock_t, { dir file })

manage_dirs_pattern(condor_domain, condor_var_run_t, condor_var_run_t)
manage_files_pattern(condor_domain, condor_var_run_t, condor_var_run_t)
manage_fifo_files_pattern(condor_domain, condor_var_run_t, condor_var_run_t)
files_pid_filetrans(condor_domain, condor_var_run_t, { dir file fifo_file })

allow condor_domain condor_master_t:process signull;
allow condor_domain condor_master_t:tcp_socket getattr;
allow condor_domain condor_master_t:udp_socket { read write };

kernel_read_network_state(condor_domain)
kernel_rw_kernel_sysctl(condor_domain)
kernel_search_network_sysctl(condor_domain)
kernel_read_vm_sysctls(condor_domain)

corecmd_exec_bin(condor_domain)
corecmd_exec_shell(condor_domain)

corenet_tcp_sendrecv_generic_if(condor_domain)
corenet_tcp_sendrecv_generic_node(condor_domain)

corenet_sendrecv_condor_client_packets(condor_domain)
corenet_tcp_connect_condor_port(condor_domain)
corenet_tcp_sendrecv_condor_port(condor_domain)

domain_use_interactive_fds(condor_domain)

dev_read_rand(condor_domain)
dev_read_sysfs(condor_domain)
dev_read_urand(condor_domain)

auth_read_passwd(condor_domain)

sysnet_dns_name_resolve(condor_domain)

sysnet_dns_name_resolve(condor_domain)

tunable_policy(`condor_tcp_network_connect',`
	corenet_sendrecv_all_client_packets(condor_domain)
	corenet_tcp_connect_all_ports(condor_domain)
	corenet_tcp_sendrecv_all_ports(condor_domain)
')

optional_policy(`
	rhcs_stream_connect_cluster(condor_domain)
')

#####################################
#
# Master local policy
#

allow condor_master_t self:capability { chown setuid setgid sys_ptrace net_admin };

allow condor_master_t condor_domain:process { sigkill signal };

manage_dirs_pattern(condor_master_t, condor_master_tmp_t, condor_master_tmp_t)
manage_files_pattern(condor_master_t, condor_master_tmp_t, condor_master_tmp_t)
files_tmp_filetrans(condor_master_t, condor_master_tmp_t, { file dir })

can_exec(condor_master_t, condor_master_exec_t)

kernel_read_system_state(condor_master_t)
kernel_read_fs_sysctls(condor_master_t)
kernel_rw_net_sysctls(condor_master_t)

corenet_udp_sendrecv_generic_if(condor_master_t)
corenet_udp_sendrecv_generic_node(condor_master_t)
corenet_tcp_bind_generic_node(condor_master_t)
corenet_udp_bind_generic_node(condor_master_t)

corenet_sendrecv_condor_server_packets(condor_master_t)
corenet_tcp_bind_condor_port(condor_master_t)
corenet_tcp_sendrecv_condor_port(condor_master_t)
corenet_udp_bind_condor_port(condor_master_t)
corenet_udp_sendrecv_condor_port(condor_master_t)

corenet_sendrecv_amqp_client_packets(condor_master_t)
corenet_tcp_connect_amqp_port(condor_master_t)
corenet_tcp_sendrecv_amqp_port(condor_master_t)

domain_read_all_domains_state(condor_master_t)

auth_use_nsswitch(condor_master_t)

logging_send_syslog_msg(condor_master_t)

optional_policy(`
	mta_send_mail(condor_master_t)
	mta_read_config(condor_master_t)
')

######################################
#
# Collector local policy
#

allow condor_collector_t self:capability { setuid setgid };

allow condor_collector_t condor_master_t:tcp_socket rw_stream_socket_perms;
allow condor_collector_t condor_master_t:udp_socket rw_socket_perms;

kernel_read_network_state(condor_collector_t)

corenet_tcp_bind_http_port(condor_collector_t)

#####################################
#
# Negotiator local policy
#

allow condor_negotiator_t self:capability { setuid setgid };
allow condor_negotiator_t condor_master_t:tcp_socket rw_stream_socket_perms;
allow condor_negotiator_t condor_master_t:udp_socket getattr;

corenet_tcp_connect_all_ephemeral_ports(condor_negotiator_t)

######################################
#
# Procd local policy
#

allow condor_procd_t self:capability { fowner chown kill dac_read_search  sys_ptrace };
allow condor_procd_t self:cap_userns { sys_ptrace };

allow condor_procd_t condor_domain:process sigkill;

domain_read_all_domains_state(condor_procd_t)

#######################################
#
# Schedd local policy
#

allow condor_schedd_t self:capability { setuid chown setgid dac_read_search  };

allow condor_schedd_t condor_master_t:tcp_socket rw_stream_socket_perms;
allow condor_schedd_t condor_master_t:udp_socket getattr;

allow condor_schedd_t condor_var_lock_t:dir manage_file_perms;

allow condor_schedd_t condor_master_tmp_t:dir getattr;  

domtrans_pattern(condor_schedd_t, condor_procd_exec_t, condor_procd_t)
domtrans_pattern(condor_schedd_t, condor_startd_exec_t, condor_startd_t)

manage_dirs_pattern(condor_schedd_t, condor_schedd_tmp_t, condor_schedd_tmp_t)
manage_files_pattern(condor_schedd_t, condor_schedd_tmp_t, condor_schedd_tmp_t)
relabel_files_pattern(condor_schedd_t, condor_schedd_tmp_t, condor_schedd_tmp_t)
files_tmp_filetrans(condor_schedd_t, condor_schedd_tmp_t, { file dir })

corenet_tcp_connect_all_ephemeral_ports(condor_schedd_t)

optional_policy(`
	mta_send_mail(condor_schedd_t)
	mta_read_config(condor_schedd_t)
')

#####################################
#
# Startd local policy
#

allow condor_startd_t self:capability { setuid net_admin setgid dac_read_search  };
allow condor_startd_t self:process execmem;

manage_dirs_pattern(condor_startd_t, condor_startd_tmp_t, condor_startd_tmp_t)
manage_files_pattern(condor_startd_t, condor_startd_tmp_t, condor_startd_tmp_t)
relabel_files_pattern(condor_startd_t, condor_startd_tmp_t, condor_startd_tmp_t)
files_tmp_filetrans(condor_startd_t, condor_startd_tmp_t, { file dir })

manage_dirs_pattern(condor_startd_t, condor_startd_tmpfs_t, condor_startd_tmpfs_t)
manage_files_pattern(condor_startd_t, condor_startd_tmpfs_t, condor_startd_tmpfs_t)
fs_tmpfs_filetrans(condor_startd_t, condor_startd_tmpfs_t, { dir file })

can_exec(condor_startd_t, condor_startd_exec_t)

domain_read_all_domains_state(condor_startd_t)

mcs_process_set_categories(condor_startd_t)

init_domtrans_script(condor_startd_t)
init_initrc_domain(condor_startd_t)

libs_exec_lib_files(condor_startd_t)

optional_policy(`
	ssh_basic_client_template(condor_startd, condor_startd_t, system_r)
	ssh_domtrans(condor_startd_t)

	manage_files_pattern(condor_startd_ssh_t, condor_var_lib_t, condor_var_lib_t)
	manage_dirs_pattern(condor_startd_ssh_t, condor_var_lib_t, condor_var_lib_t)

	optional_policy(`
		kerberos_use(condor_startd_ssh_t)
	')
')

optional_policy(`
    unconfined_domain(condor_startd_t)
')
