Chris PeBenito 62a7b0
## <summary>Secure shell client and server policy.</summary>
Chris PeBenito 62a7b0
Chris PeBenito e88003
#######################################
Chris PeBenito e88003
## <summary>
Chris PeBenito e88003
##	The per user domain template for the ssh module.
Chris PeBenito e88003
## </summary>
Chris PeBenito e88003
## <desc>
Chris PeBenito e88003
##	

Chris PeBenito e88003
##	This template creates a derived domains which are used
Chris PeBenito e88003
##	for ssh client sessions and user ssh agents.  A derived
Chris PeBenito e88003
##	type is also created to protect the user ssh keys.
Chris PeBenito e88003
##	

Chris PeBenito e88003
##	

Chris PeBenito e88003
##	This template is invoked automatically for each user, and
Chris PeBenito e88003
##	generally does not need to be invoked directly
Chris PeBenito e88003
##	by policy writers.
Chris PeBenito e88003
##	

Chris PeBenito e88003
## </desc>
Chris PeBenito e88003
## <param name="userdomain_prefix">
Chris PeBenito e88003
##	The prefix of the user domain (e.g., user
Chris PeBenito e88003
##	is the prefix for user_t).
Chris PeBenito e88003
## </param>
Chris PeBenito 451c1e
## <param name="user_domain">
Chris PeBenito 451c1e
##	The type of the user domain.
Chris PeBenito 451c1e
## </param>
Chris PeBenito 451c1e
## <param name="user_role">
Chris PeBenito 451c1e
##	The role associated with the user domain.
Chris PeBenito 451c1e
## </param>
Chris PeBenito e88003
#
Chris PeBenito 199895
template(`ssh_per_userdomain_template',`
Chris PeBenito 12ae75
	gen_require(`
Chris PeBenito 0efe52
		attribute ssh_server;
Chris PeBenito 12ae75
		type ssh_exec_t, ssh_agent_exec_t;
Chris PeBenito 0efe52
		type sshd_key_t, ssh_keysign_exec_t;
Chris PeBenito 0efe52
		type sshd_tmp_t, sshd_t;
Chris PeBenito 12ae75
	')
Chris PeBenito 12ae75
Chris PeBenito 9ccd96
	##############################
Chris PeBenito 9ccd96
	#
Chris PeBenito 9ccd96
	# Declarations
Chris PeBenito 9ccd96
	#
Chris PeBenito 0404a3
Chris PeBenito 6820a3
	type $1_home_ssh_t;
Chris PeBenito 6820a3
	userdom_home_file($1,$1_home_ssh_t)
Chris PeBenito 451c1e
	role $3 types $1_ssh_t;
Chris PeBenito 0404a3
Chris PeBenito 493d6c
	type $1_ssh_t;
Chris PeBenito 9ccd96
	domain_type($1_ssh_t)
Chris PeBenito 4483ee
	domain_entry_file($1_ssh_t,ssh_exec_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	type $1_ssh_agent_t;
Chris PeBenito 9ccd96
	domain_type($1_ssh_agent_t)
Chris PeBenito 4483ee
	domain_entry_file($1_ssh_agent_t,ssh_agent_exec_t)
Chris PeBenito 451c1e
	role $3 types $1_ssh_agent_t;
Chris PeBenito 9ccd96
Chris PeBenito 4483ee
	type $1_ssh_keysign_t; #, nscd_client_domain;
Chris PeBenito 4483ee
	domain_type($1_ssh_keysign_t)
Chris PeBenito 4483ee
	domain_entry_file($1_ssh_keysign_t,ssh_keysign_exec_t)
Chris PeBenito 4483ee
	role $3 types $1_ssh_keysign_t;
Chris PeBenito 4483ee
Chris PeBenito 9ccd96
	##############################
Chris PeBenito 9ccd96
	#
Chris PeBenito 9ccd96
	# $1_ssh_t local policy
Chris PeBenito 9ccd96
	#
Chris PeBenito 9ccd96
	allow $1_ssh_t self:capability { setuid setgid dac_override dac_read_search };
Chris PeBenito 9d3bdc
	allow $1_ssh_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
Chris PeBenito 9ccd96
	allow $1_ssh_t self:fd use;
Chris PeBenito 9ccd96
	allow $1_ssh_t self:fifo_file { read getattr lock ioctl write append };
Chris PeBenito 9ccd96
	allow $1_ssh_t self:unix_dgram_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown };
Chris PeBenito 9ccd96
	allow $1_ssh_t self:unix_stream_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown listen accept };
Chris PeBenito 9ccd96
	allow $1_ssh_t self:unix_dgram_socket sendto;
Chris PeBenito 9ccd96
	allow $1_ssh_t self:unix_stream_socket connectto;
Chris PeBenito 9ccd96
	allow $1_ssh_t self:shm { associate getattr setattr create destroy read write lock unix_read unix_write };
Chris PeBenito 9ccd96
	allow $1_ssh_t self:sem { associate getattr setattr create destroy read write unix_read unix_write };
Chris PeBenito 9ccd96
	allow $1_ssh_t self:msgq { associate getattr setattr create destroy read write enqueue unix_read unix_write };
Chris PeBenito 9ccd96
	allow $1_ssh_t self:msg { send receive };
Chris PeBenito d3b892
	allow $1_ssh_t self:tcp_socket { create connect ioctl read getattr write setattr append bind getopt setopt shutdown };
Chris PeBenito 9ccd96
Chris PeBenito 0404a3
	# Transition from the user domain to the derived domain.
Chris PeBenito 451c1e
	domain_auto_trans($2, ssh_exec_t, $1_ssh_t)
Chris PeBenito 451c1e
	allow $2 $1_ssh_t:fd use;
Chris PeBenito 451c1e
	allow $1_ssh_t $2:fd use;
Chris PeBenito 451c1e
	allow $1_ssh_t $2:fifo_file rw_file_perms;
Chris PeBenito 451c1e
	allow $1_ssh_t $2:process sigchld;
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	# Read the ssh key file.
Chris PeBenito 9ccd96
	allow $1_ssh_t sshd_key_t:file r_file_perms;
Chris PeBenito 9ccd96
Chris PeBenito aad5b9
	# Access the ssh temporary files.
Chris PeBenito aad5b9
	allow $1_ssh_t sshd_tmp_t:dir create_dir_perms;
Chris PeBenito aad5b9
	allow $1_ssh_t sshd_tmp_t:file create_file_perms;
Chris PeBenito aad5b9
	files_create_tmp_files($1_ssh_t, sshd_tmp_t, { file dir })
Chris PeBenito aad5b9
Chris PeBenito aad5b9
	# for rsync
Chris PeBenito 451c1e
	allow $1_ssh_t $2:unix_stream_socket rw_socket_perms;
Chris PeBenito 451c1e
	allow $1_ssh_t $2:unix_stream_socket connectto;
Chris PeBenito aad5b9
Chris PeBenito aad5b9
	# user can manage the keys and config
Chris PeBenito 451c1e
	allow $2 $1_home_ssh_t:dir rw_dir_perms;
Chris PeBenito 451c1e
	allow $2 $1_home_ssh_t:file create_file_perms;
Chris PeBenito 451c1e
	allow $2 $1_home_ssh_t:lnk_file create_lnk_perms;
Chris PeBenito 451c1e
	allow $2 $1_home_ssh_t:sock_file create_file_perms;
Chris PeBenito aad5b9
Chris PeBenito e5590e
	# inheriting stream sockets is needed for "ssh host command" as no pty
Chris PeBenito e5590e
	# is allocated
Chris PeBenito e5590e
	# cjp: should probably fix target to be an attribute for ssh servers
Chris PeBenito e5590e
	# or "regular" (not special like sshd_extern_t) servers
Chris PeBenito 451c1e
	allow $2 sshd_t:unix_stream_socket rw_stream_socket_perms;
Chris PeBenito e5590e
Chris PeBenito aad5b9
	# ssh client can manage the keys and config
Chris PeBenito aad5b9
	allow $1_ssh_t $1_home_ssh_t:file create_file_perms;
Chris PeBenito aad5b9
	allow $1_ssh_t $1_home_ssh_t:lnk_file { getattr read };
Chris PeBenito aad5b9
Chris PeBenito aad5b9
	# ssh servers can read the user keys and config
Chris PeBenito aad5b9
	allow ssh_server $1_home_ssh_t:dir r_dir_perms;
Chris PeBenito aad5b9
	allow ssh_server $1_home_ssh_t:lnk_file r_file_perms;
Chris PeBenito aad5b9
	allow ssh_server $1_home_ssh_t:file r_file_perms;
Chris PeBenito aad5b9
Chris PeBenito 9ccd96
	kernel_read_kernel_sysctl($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito d3b892
	corenet_tcp_sendrecv_all_if($1_ssh_t)
Chris PeBenito d3b892
	corenet_raw_sendrecv_all_if($1_ssh_t)
Chris PeBenito d3b892
	corenet_tcp_sendrecv_all_nodes($1_ssh_t)
Chris PeBenito d3b892
	corenet_raw_sendrecv_all_nodes($1_ssh_t)
Chris PeBenito d3b892
	corenet_tcp_sendrecv_all_ports($1_ssh_t)
Chris PeBenito bd7037
	corenet_non_ipsec_sendrecv($1_ssh_t)
Chris PeBenito d3b892
	corenet_tcp_bind_all_nodes($1_ssh_t)
Chris PeBenito cff75c
	corenet_tcp_connect_ssh_port($1_ssh_t)
Chris PeBenito d3b892
Chris PeBenito 9ccd96
	dev_read_urand($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	fs_getattr_all_fs($1_ssh_t)
Chris PeBenito ab940a
	fs_search_auto_mountpoints($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# run helper programs - needed eg for x11-ssh-askpass
Chris PeBenito 9ccd96
	corecmd_exec_shell($1_ssh_t)
Chris PeBenito 9ccd96
	corecmd_exec_bin($1_ssh_t)
Chris PeBenito df00b2
	corecmd_list_sbin($1_ssh_t)
Chris PeBenito df00b2
	corecmd_read_sbin_symlink($1_ssh_t)
Chris PeBenito df00b2
	# cjp: these are probably not needed:
Chris PeBenito df00b2
	corecmd_read_sbin_file($1_ssh_t)
Chris PeBenito df00b2
	corecmd_read_sbin_pipe($1_ssh_t)
Chris PeBenito df00b2
	corecmd_read_sbin_socket($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	domain_use_wide_inherit_fd($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	files_list_home($1_ssh_t)
Chris PeBenito 9ccd96
	files_read_usr_files($1_ssh_t)
Chris PeBenito 9ccd96
	files_read_etc_runtime_files($1_ssh_t)
Chris PeBenito 8fd367
	files_read_etc_files($1_ssh_t)
Chris PeBenito cff75c
	files_read_var_files($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 0404a3
	libs_use_ld_so($1_ssh_t)
Chris PeBenito 0404a3
	libs_use_shared_libs($1_ssh_t)
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	logging_send_syslog_msg($1_ssh_t)
Chris PeBenito 9ccd96
	logging_read_generic_logs($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	miscfiles_read_localization($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	seutil_read_config($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito d3b892
	sysnet_read_config($1_ssh_t)
Chris PeBenito 98a8ea
	sysnet_dns_name_resolve($1_ssh_t)
Chris PeBenito d3b892
Chris PeBenito aad5b9
	userdom_use_unpriv_users_fd($1_ssh_t)
Chris PeBenito de7649
	# Write to the user domain tty.
Chris PeBenito de7649
	userdom_use_user_terminals($1,$1_ssh_t)
Chris PeBenito aad5b9
Chris PeBenito df00b2
	tunable_policy(`read_default_t',`
Chris PeBenito df00b2
		files_list_default($1_ssh_t)
Chris PeBenito df00b2
		files_read_default_files($1_ssh_t)
Chris PeBenito df00b2
		files_read_default_symlinks($1_ssh_t)
Chris PeBenito df00b2
		files_read_default_sockets($1_ssh_t)
Chris PeBenito df00b2
		files_read_default_pipes($1_ssh_t)
Chris PeBenito df00b2
	')
Chris PeBenito df00b2
Chris PeBenito 0404a3
	tunable_policy(`use_nfs_home_dirs',`
Chris PeBenito 0404a3
		fs_manage_nfs_dirs($1_ssh_t)
Chris PeBenito 0404a3
		fs_manage_nfs_files($1_ssh_t)
Chris PeBenito 0404a3
	')
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	tunable_policy(`use_samba_home_dirs',`
Chris PeBenito 0404a3
		fs_manage_cifs_dirs($1_ssh_t)
Chris PeBenito 0404a3
		fs_manage_cifs_files($1_ssh_t)
Chris PeBenito 0404a3
	')
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	# for port forwarding
Chris PeBenito 9ccd96
	tunable_policy(`user_tcp_server',`
Chris PeBenito 9ccd96
		corenet_tcp_bind_ssh_port($1_ssh_t)
Chris PeBenito 9ccd96
	')
Chris PeBenito 0404a3
Chris PeBenito 132880
	optional_policy(`kerberos',`
Chris PeBenito a7a979
		kerberos_use($1_ssh_t)
Chris PeBenito a7a979
	')
Chris PeBenito a7a979
Chris PeBenito 132880
	optional_policy(`nis',`
Chris PeBenito ab940a
		nis_use_ypbind($1_ssh_t)
Chris PeBenito ab940a
	')
Chris PeBenito 0404a3
Chris PeBenito 132880
	optional_policy(`nscd',`
Chris PeBenito 493d6c
		nscd_use_socket($1_ssh_t)
Chris PeBenito 493d6c
	')
Chris PeBenito 493d6c
Chris PeBenito ab940a
	ifdef(`TODO',`
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# Read /var/run, /var/log.
Chris PeBenito 0404a3
	allow $1_ssh_t var_run_t:dir r_dir_perms;
Chris PeBenito 0404a3
	allow $1_ssh_t var_run_t:{ file lnk_file } r_file_perms;
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	allow $1_ssh_t $1_tmp_t:dir r_dir_perms;
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# Access the users .ssh directory.
Chris PeBenito 0404a3
	file_type_auto_trans({ sysadm_ssh_t $1_ssh_t }, $1_home_dir_t, $1_home_ssh_t, dir)
Chris PeBenito 0404a3
	file_type_auto_trans($1_ssh_t, $1_home_dir_t, $1_home_ssh_t, sock_file)
Chris PeBenito aad5b9
	allow sysadm_ssh_t $1_home_ssh_t:file create_file_perms;
Chris PeBenito aad5b9
	allow sysadm_ssh_t $1_home_ssh_t:lnk_file { getattr read };
Chris PeBenito 0404a3
	dontaudit $1_ssh_t $1_home_t:dir { getattr search };
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# for /bin/sh used to execute xauth
Chris PeBenito 0404a3
	dontaudit $1_ssh_t proc_t:{ lnk_file file } { getattr read };
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# Inherit and use descriptors from gnome-pty-helper.
Chris PeBenito 0404a3
	ifdef(`gnome-pty-helper.te', `allow $1_ssh_t $1_gph_t:fd use;')
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# allow ps to show ssh
Chris PeBenito 0404a3
	can_ps($1_t, $1_ssh_t)
Chris PeBenito 0404a3
Chris PeBenito cff75c
	# Connect to X server
Chris PeBenito cff75c
	x_client_domain($1_ssh, $1)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	#allow ssh to access keys stored on removable media
Chris PeBenito 0404a3
	# Should we have a boolean around this?
Chris PeBenito 80436b
	files_search_mnt($1_ssh_t)
Chris PeBenito 0404a3
	r_dir_file($1_ssh_t, removable_t) 
Chris PeBenito 0404a3
Chris PeBenito cff75c
	if (allow_ssh_keysign) {
Chris PeBenito cff75c
	domain_auto_trans($1_ssh_t, ssh_keysign_exec_t, $1_ssh_keysign_t)
Chris PeBenito cff75c
	allow $1_ssh_keysign_t sshd_key_t:file { getattr read };
Chris PeBenito cff75c
	allow $1_ssh_keysign_t self:capability { setgid setuid };
Chris PeBenito cff75c
	allow $1_ssh_keysign_t urandom_device_t:chr_file r_file_perms;
Chris PeBenito cff75c
	uses_shlib($1_ssh_keysign_t)
Chris PeBenito cff75c
	dontaudit $1_ssh_keysign_t selinux_config_t:dir search;
Chris PeBenito cff75c
	dontaudit $1_ssh_keysign_t proc_t:dir search;
Chris PeBenito cff75c
	dontaudit $1_ssh_keysign_t proc_t:{ lnk_file file } { getattr read };
Chris PeBenito cff75c
	allow $1_ssh_keysign_t usr_t:dir search;
Chris PeBenito cff75c
	allow $1_ssh_keysign_t etc_t:file { getattr read };
Chris PeBenito cff75c
	allow $1_ssh_keysign_t self:dir search;
Chris PeBenito cff75c
	allow $1_ssh_keysign_t self:file { getattr read };
Chris PeBenito cff75c
	allow $1_ssh_keysign_t self:unix_stream_socket create_socket_perms;
Chris PeBenito cff75c
	}
Chris PeBenito cff75c
Chris PeBenito 0404a3
	') dnl endif TODO
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	##############################
Chris PeBenito 9ccd96
	#
Chris PeBenito 9ccd96
	# $1_ssh_agent_t local policy
Chris PeBenito 9ccd96
	#
Chris PeBenito df00b2
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t self:process setrlimit;
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t self:capability setgid;
Chris PeBenito 9ccd96
Chris PeBenito 451c1e
	allow $1_ssh_agent_t { $1_ssh_agent_t $2 }:process signull;
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	allow $1_ssh_t $1_ssh_agent_t:unix_stream_socket connectto;
Chris PeBenito 9ccd96
Chris PeBenito 451c1e
	# for ssh-add
Chris PeBenito 451c1e
	allow $2 $1_ssh_agent_t:unix_stream_socket connectto;
Chris PeBenito 451c1e
Chris PeBenito 451c1e
	# Allow the user shell to signal the ssh program.
Chris PeBenito 451c1e
	allow $2 $1_ssh_agent_t:process signal;
Chris PeBenito 451c1e
Chris PeBenito df00b2
	# for the transition back to normal privs upon exec
Chris PeBenito 451c1e
	allow $1_ssh_agent_t $2:fd use;
Chris PeBenito 451c1e
	allow $2 $1_ssh_agent_t:fd use;
Chris PeBenito 451c1e
	allow $2 $1_ssh_agent_t:fifo_file rw_file_perms;
Chris PeBenito 451c1e
	allow $2 $1_ssh_agent_t:process sigchld;
Chris PeBenito df00b2
Chris PeBenito df00b2
	# Allow the ssh program to communicate with ssh-agent.
Chris PeBenito df00b2
	allow $1_ssh_t sshd_t:unix_stream_socket connectto;
Chris PeBenito df00b2
Chris PeBenito 451c1e
	domain_auto_trans($2, ssh_agent_exec_t, $1_ssh_agent_t)
Chris PeBenito 451c1e
	allow $2 $1_ssh_agent_t:fd use;
Chris PeBenito 451c1e
	allow $1_ssh_agent_t $2:fd use;
Chris PeBenito 451c1e
	allow $1_ssh_agent_t $2:fifo_file rw_file_perms;
Chris PeBenito 451c1e
	allow $1_ssh_agent_t $2:process sigchld;
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	kernel_read_kernel_sysctl($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	dev_read_urand($1_ssh_agent_t)
Chris PeBenito 9ccd96
	dev_read_rand($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito ab940a
	fs_search_auto_mountpoints($1_ssh_agent_t)
Chris PeBenito ab940a
Chris PeBenito df00b2
	# transition back to normal privs upon exec
Chris PeBenito df00b2
	corecmd_shell_domtrans($1_ssh_agent_t,$1_t)
Chris PeBenito df00b2
	corecmd_bin_domtrans($1_ssh_agent_t, $1_t)
Chris PeBenito df00b2
Chris PeBenito 9ccd96
	domain_use_wide_inherit_fd($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito 8fd367
	files_read_etc_files($1_ssh_agent_t)
Chris PeBenito 9ccd96
	files_read_etc_runtime_files($1_ssh_agent_t)
Chris PeBenito 7057c1
	files_search_home($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	libs_read_lib($1_ssh_agent_t)
Chris PeBenito 9ccd96
	libs_use_ld_so($1_ssh_agent_t)
Chris PeBenito 9ccd96
	libs_use_shared_libs($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	logging_send_syslog_msg($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	miscfiles_read_localization($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito cff75c
	seutil_dontaudit_read_config($1_ssh_agent_t)
Chris PeBenito df00b2
Chris PeBenito 451c1e
	# Write to the user domain tty.
Chris PeBenito 451c1e
	userdom_use_user_terminals($1,$1_ssh_agent_t)
Chris PeBenito 451c1e
Chris PeBenito df00b2
	tunable_policy(`use_nfs_home_dirs',`
Chris PeBenito 9ccd96
		fs_manage_nfs_files($1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito df00b2
		# transition back to normal privs upon exec
Chris PeBenito df00b2
		fs_nfs_domtrans($1_ssh_agent_t, $1_t)
Chris PeBenito df00b2
	')
Chris PeBenito df00b2
Chris PeBenito df00b2
	tunable_policy(`use_samba_home_dirs',`
Chris PeBenito 9ccd96
		fs_manage_cifs_files($1_ssh_agent_t)
Chris PeBenito df00b2
Chris PeBenito df00b2
		# transition back to normal privs upon exec
Chris PeBenito df00b2
		fs_cifs_domtrans($1_ssh_agent_t, $1_t)
Chris PeBenito df00b2
	')
Chris PeBenito 9ccd96
Chris PeBenito 132880
	optional_policy(`nis',`
Chris PeBenito ab940a
		nis_use_ypbind($1_ssh_agent_t)
Chris PeBenito ab940a
	')
Chris PeBenito ab940a
Chris PeBenito 132880
#	optional_policy(`xdm',`
Chris PeBenito 12ae75
#		# KDM:
Chris PeBenito 12ae75
#		xdm_sigchld($1_ssh_agent_t)
Chris PeBenito 12ae75
#	')
Chris PeBenito df00b2
Chris PeBenito 9ccd96
	ifdef(`TODO',`
Chris PeBenito cff75c
	ifdef(`xdm.te',`
Chris PeBenito cff75c
	can_pipe_xdm($1_ssh_agent_t)
Chris PeBenito cff75c
	')
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# allow ps to show ssh
Chris PeBenito 9ccd96
	can_ps($1_t, $1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	dontaudit $1_ssh_agent_t proc_t:{ lnk_file file } { getattr read };
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# Access the ssh temporary files. Should we have an own type here
Chris PeBenito 9ccd96
	# to which only ssh, ssh-agent and ssh-add have access?
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t $1_tmp_t:dir r_dir_perms;
Chris PeBenito 9ccd96
	file_type_auto_trans($1_ssh_agent_t, tmp_t, $1_tmp_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# transition back to normal privs upon exec
Chris PeBenito df00b2
	domain_auto_trans($1_ssh_agent_t, $1_home_t, $1_t)
Chris PeBenito 7057c1
	allow $1_ssh_agent_t $1_home_dir_t:dir search;
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	allow $1_ssh_t $1_tmp_t:sock_file write;
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	#
Chris PeBenito 9ccd96
	# Allow command to ssh-agent > ~/.ssh_agent
Chris PeBenito 9ccd96
	#
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t $1_home_t:file rw_file_perms;
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t $1_tmp_t:file rw_file_perms;
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# Allow the ssh program to communicate with ssh-agent.
Chris PeBenito 9ccd96
	allow $1_ssh_t $1_tmp_t:sock_file write;
Chris PeBenito 451c1e
	allow $1_ssh_t $2:unix_stream_socket connectto;
Chris PeBenito 9ccd96
	') dnl endif TODO
Chris PeBenito 4483ee
Chris PeBenito 4483ee
	##############################
Chris PeBenito 4483ee
	#
Chris PeBenito 4483ee
	# $1_ssh_keysign_t local policy
Chris PeBenito 4483ee
	#
Chris PeBenito 4483ee
Chris PeBenito 132880
	optional_policy(`nscd',`
Chris PeBenito 4483ee
		nscd_use_socket($1_ssh_keysign_t)
Chris PeBenito 4483ee
	')
Chris PeBenito 0404a3
')
Chris PeBenito 0404a3
Chris PeBenito e88003
#######################################
Chris PeBenito e88003
## <summary>
Chris PeBenito e88003
##	The template to define a ssh server.
Chris PeBenito e88003
## </summary>
Chris PeBenito e88003
## <desc>
Chris PeBenito e88003
##	

Chris PeBenito e88003
##	This template creates a domains to be used for
Chris PeBenito e88003
##	creating a ssh server.  This is typically done
Chris PeBenito e88003
##	to have multiple ssh servers of different sensitivities,
Chris PeBenito e88003
##	such as for an internal network-facing ssh server, and
Chris PeBenito e88003
##	a external network-facing ssh server.
Chris PeBenito e88003
##	

Chris PeBenito e88003
## </desc>
Chris PeBenito e88003
## <param name="userdomain_prefix">
Chris PeBenito 8fd367
##	The prefix of the server domain (e.g., sshd
Chris PeBenito 8fd367
##	is the prefix for sshd_t).
Chris PeBenito e88003
## </param>
Chris PeBenito 0404a3
#
Chris PeBenito 8fd367
template(`ssh_server_template', `
Chris PeBenito f0574f
	type $1_t, ssh_server;
Chris PeBenito f0574f
Chris PeBenito 2e863f
	domain_type($1_t)
Chris PeBenito 0404a3
	role system_r types $1_t;
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	type $1_devpts_t;
Chris PeBenito 0404a3
	term_login_pty($1_devpts_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	type $1_var_run_t;
Chris PeBenito 0404a3
	files_pid_file($1_var_run_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	allow $1_t self:capability { kill sys_chroot sys_resource chown dac_override fowner fsetid setgid setuid sys_tty_config };
Chris PeBenito 0404a3
	allow $1_t self:fifo_file rw_file_perms;
Chris PeBenito 0404a3
	allow $1_t self:process { signal setsched setrlimit setexec };
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	allow $1_t self:tcp_socket { listen accept create connect ioctl read getattr write setattr append bind getopt setopt shutdown };
Chris PeBenito 0404a3
	allow $1_t self:udp_socket { connect create ioctl read getattr write setattr append bind getopt setopt shutdown };
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	allow $1_t $1_devpts_t:chr_file { rw_file_perms setattr getattr relabelfrom };
Chris PeBenito 0404a3
	term_create_pty($1_t,$1_devpts_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	allow $1_t $1_var_run_t:file create_file_perms;
Chris PeBenito 0404a3
	files_create_pid($1_t,$1_var_run_t,file)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	can_exec($1_t, sshd_exec_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# Access key files
Chris PeBenito 0404a3
	allow $1_t sshd_key_t:file { getattr read };
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	kernel_read_kernel_sysctl($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	corenet_tcp_sendrecv_all_if($1_t)
Chris PeBenito 0404a3
	corenet_udp_sendrecv_all_if($1_t)
Chris PeBenito 0404a3
	corenet_raw_sendrecv_all_if($1_t)
Chris PeBenito 0404a3
	corenet_tcp_sendrecv_all_nodes($1_t)
Chris PeBenito 0404a3
	corenet_udp_sendrecv_all_nodes($1_t)
Chris PeBenito 0404a3
	corenet_raw_sendrecv_all_nodes($1_t)
Chris PeBenito 0404a3
	corenet_udp_sendrecv_all_ports($1_t)
Chris PeBenito 0404a3
	corenet_tcp_sendrecv_all_ports($1_t)
Chris PeBenito bd7037
	corenet_non_ipsec_sendrecv($1_t)
Chris PeBenito 0404a3
	corenet_tcp_bind_all_nodes($1_t)
Chris PeBenito 0404a3
	corenet_udp_bind_all_nodes($1_t)
Chris PeBenito 0907bd
	corenet_tcp_connect_all_ports($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	dev_read_urand($1_t)
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	fs_dontaudit_getattr_all_fs($1_t)
Chris PeBenito 9ccd96
Chris PeBenito 0404a3
	selinux_get_fs_mount($1_t)
Chris PeBenito 0404a3
	selinux_validate_context($1_t)
Chris PeBenito 0404a3
	selinux_compute_access_vector($1_t)
Chris PeBenito 0404a3
	selinux_compute_create_context($1_t)
Chris PeBenito 0404a3
	selinux_compute_relabel_context($1_t)
Chris PeBenito 0404a3
	selinux_compute_user_contexts($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	auth_dontaudit_read_shadow($1_t)
Chris PeBenito 0404a3
	auth_domtrans_chk_passwd($1_t)
Chris PeBenito 0404a3
	auth_rw_login_records($1_t)
Chris PeBenito 0404a3
	auth_rw_lastlog($1_t)
Chris PeBenito cf6a7d
	auth_append_faillog($1_t)
Chris PeBenito 0404a3
Chris PeBenito 80436b
	corecmd_read_bin_symlink($1_t)
Chris PeBenito cf6a7d
	corecmd_getattr_bin_file($1_t)
Chris PeBenito 80436b
	# for sshd subsystems, such as sftp-server.
Chris PeBenito 80436b
	corecmd_getattr_bin_file($1_t)
Chris PeBenito 80436b
Chris PeBenito 0404a3
	domain_wide_inherit_fd($1_t)
Chris PeBenito 0404a3
	domain_subj_id_change_exempt($1_t)
Chris PeBenito 0404a3
	domain_role_change_exempt($1_t)
Chris PeBenito 0404a3
	domain_obj_id_change_exempt($1_t)
Chris PeBenito 0404a3
Chris PeBenito 8fd367
	files_read_etc_files($1_t)
Chris PeBenito 0404a3
	files_read_etc_runtime_files($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	init_rw_script_pid($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	libs_use_ld_so($1_t)
Chris PeBenito 0404a3
	libs_use_shared_libs($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	logging_search_logs($1_t)
Chris PeBenito 0404a3
	logging_send_syslog_msg($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	miscfiles_read_localization($1_t)
Chris PeBenito 0404a3
Chris PeBenito f0574f
	mls_file_read_up($1_t)
Chris PeBenito f0574f
	mls_file_write_down($1_t)
Chris PeBenito f0574f
	mls_file_upgrade($1_t)
Chris PeBenito f0574f
	mls_file_downgrade($1_t)
Chris PeBenito f0574f
	mls_process_set_level($1_t)
Chris PeBenito f0574f
Chris PeBenito 0404a3
	seutil_read_default_contexts($1_t)
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	sysnet_read_config($1_t)
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	userdom_search_all_users_home($1_t)
Chris PeBenito 9ccd96
Chris PeBenito a08248
	# Allow checking users mail at login
Chris PeBenito a08248
	mta_getattr_spool($1_t)
Chris PeBenito a08248
Chris PeBenito 0404a3
	tunable_policy(`use_nfs_home_dirs',`
Chris PeBenito 0404a3
		fs_read_nfs_files($1_t)
Chris PeBenito 0404a3
	')
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	tunable_policy(`use_samba_home_dirs',`
Chris PeBenito 0404a3
		fs_read_cifs_files($1_t)
Chris PeBenito 0404a3
	')
Chris PeBenito 0404a3
Chris PeBenito 25c674
	# cjp: commenting out until typeattribute works in conditional
Chris PeBenito 25c674
	# and require block in optional else is resolved
Chris PeBenito 132880
	#optional_policy(`inetd',`
Chris PeBenito 25c674
	#	tunable_policy(`run_ssh_inetd',`
Chris PeBenito 25c674
	#		allow $1_t self:process signal;
Chris PeBenito 25c674
	#		files_list_pids($1_t)
Chris PeBenito 25c674
	#	',`
Chris PeBenito 25c674
	#		corenet_tcp_bind_ssh_port($1_t)
Chris PeBenito 25c674
	#		init_use_fd($1_t)
Chris PeBenito 25c674
	#		init_use_script_pty($1_t)
Chris PeBenito 25c674
	#	')
Chris PeBenito 25c674
	#',`
Chris PeBenito 80436b
		# These rules should match the else block
Chris PeBenito 80436b
		# of the run_ssh_inetd tunable directly above
Chris PeBenito 80436b
		corenet_tcp_bind_ssh_port($1_t)
Chris PeBenito 80436b
		init_use_fd($1_t)
Chris PeBenito 80436b
		init_use_script_pty($1_t)
Chris PeBenito 25c674
	#')
Chris PeBenito 80436b
Chris PeBenito 132880
	optional_policy(`kerberos',`
Chris PeBenito 0907bd
		kerberos_use($1_t)
Chris PeBenito 0907bd
	')
Chris PeBenito 0907bd
Chris PeBenito 132880
	optional_policy(`mount',`
Chris PeBenito 9ccd96
		mount_send_nfs_client_request($1_t)
Chris PeBenito 9ccd96
	')
Chris PeBenito 0404a3
Chris PeBenito 132880
	optional_policy(`nscd',`
Chris PeBenito c38127
		nscd_use_socket($1_t)
Chris PeBenito 493d6c
	')
Chris PeBenito 493d6c
Chris PeBenito 9ccd96
	ifdef(`TODO',`
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# Read /var.
Chris PeBenito 0404a3
	allow $1_t var_t:dir getattr;
Chris PeBenito 0404a3
Chris PeBenito 80436b
	allow $1_t home_dir_type:dir getattr;
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	dontaudit sshd_t userpty_type:chr_file relabelfrom;
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	') dnl end TODO
Chris PeBenito 0404a3
')
Chris PeBenito 9ccd96
Chris PeBenito 62a7b0
########################################
Chris PeBenito 62a7b0
## <summary>Read ssh server keys</summary>
Chris PeBenito 62a7b0
## <param name="domain">
Chris PeBenito 62a7b0
##	The type of the process performing this action.
Chris PeBenito 62a7b0
## </param>
Chris PeBenito 62a7b0
#
Chris PeBenito 9ccd96
interface(`ssh_dontaudit_read_server_keys',`
Chris PeBenito 9ccd96
	gen_require(`
Chris PeBenito 9ccd96
		type sshd_key_t;
Chris PeBenito 9ccd96
		class file { getattr read };
Chris PeBenito 9ccd96
	')
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	dontaudit $1 sshd_key_t:file { getattr read };
Chris PeBenito 9ccd96
')