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 885b83
##	<summary>
Chris PeBenito e88003
##	The prefix of the user domain (e.g., user
Chris PeBenito e88003
##	is the prefix for user_t).
Chris PeBenito 885b83
##	</summary>
Chris PeBenito e88003
## </param>
Chris PeBenito 451c1e
## <param name="user_domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 451c1e
##	The type of the user domain.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 451c1e
## </param>
Chris PeBenito 451c1e
## <param name="user_role">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 451c1e
##	The role associated with the user domain.
Chris PeBenito 885b83
##	</summary>
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 103fe2
	userdom_user_home_content($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 24a637
	type $1_ssh_keysign_t;
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 24a637
	type $1_ssh_tmpfs_t;
Chris PeBenito 24a637
	files_tmpfs_file($1_ssh_tmpfs_t)
Chris PeBenito 24a637
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 24a637
	allow $1_ssh_t $1_ssh_tmpfs_t:dir rw_dir_perms;
Chris PeBenito 24a637
	allow $1_ssh_t $1_ssh_tmpfs_t:file manage_file_perms;
Chris PeBenito 24a637
	allow $1_ssh_t $1_ssh_tmpfs_t:lnk_file create_lnk_perms;
Chris PeBenito 24a637
	allow $1_ssh_t $1_ssh_tmpfs_t:sock_file manage_file_perms;
Chris PeBenito 24a637
	allow $1_ssh_t $1_ssh_tmpfs_t:fifo_file manage_file_perms;
Chris PeBenito 103fe2
	fs_tmpfs_filetrans($1_ssh_t,$1_ssh_tmpfs_t,{ dir file lnk_file sock_file fifo_file })
Chris PeBenito 24a637
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 103fe2
	files_tmp_filetrans($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 103fe2
	userdom_search_user_home_dirs($1,$1_ssh_t)
Chris PeBenito f6abfd
	allow $1_ssh_t $1_home_ssh_t:dir r_dir_perms;
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 445522
	kernel_read_kernel_sysctls($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 1815ba
	corecmd_read_sbin_symlinks($1_ssh_t)
Chris PeBenito df00b2
	# cjp: these are probably not needed:
Chris PeBenito 1815ba
	corecmd_read_sbin_files($1_ssh_t)
Chris PeBenito 1815ba
	corecmd_read_sbin_pipes($1_ssh_t)
Chris PeBenito 1815ba
	corecmd_read_sbin_sockets($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 15722e
	domain_use_interactive_fds($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 103fe2
	userdom_use_unpriv_users_fds($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 bb7170
	optional_policy(`
Chris PeBenito a7a979
		kerberos_use($1_ssh_t)
Chris PeBenito a7a979
	')
Chris PeBenito a7a979
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito ab940a
		nis_use_ypbind($1_ssh_t)
Chris PeBenito ab940a
	')
Chris PeBenito 0404a3
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 1815ba
		nscd_socket_use($1_ssh_t)
Chris PeBenito 493d6c
	')
Chris PeBenito 493d6c
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 24a637
		xserver_user_client_template($1,$1_ssh_t,$1_ssh_tmpfs_t)
Chris PeBenito 3b3113
		xserver_domtrans_user_xauth($1,$1_ssh_t)
Chris PeBenito 3b3113
	')
Chris PeBenito 3b3113
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
	# allow ps to show ssh
Chris PeBenito 0404a3
	can_ps($1_t, $1_ssh_t)
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 02bcb8
	allow $1_ssh_agent_t self:unix_stream_socket { connectto rw_socket_perms };
Chris PeBenito 02bcb8
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 445522
	kernel_read_kernel_sysctls($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 15722e
	domain_use_interactive_fds($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 1815ba
	libs_read_lib_files($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 bb7170
	optional_policy(`
Chris PeBenito ab940a
		nis_use_ypbind($1_ssh_agent_t)
Chris PeBenito ab940a
	')
Chris PeBenito ab940a
Chris PeBenito bb7170
#	optional_policy(`
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 bb7170
	optional_policy(`
Chris PeBenito 1815ba
		nscd_socket_use($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 885b83
##	<summary>
Chris PeBenito 8fd367
##	The prefix of the server domain (e.g., sshd
Chris PeBenito 8fd367
##	is the prefix for sshd_t).
Chris PeBenito 885b83
##	</summary>
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 103fe2
	files_pid_filetrans($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 445522
	kernel_read_kernel_sysctls($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 1815ba
	corecmd_read_bin_symlinks($1_t)
Chris PeBenito 1815ba
	corecmd_getattr_bin_files($1_t)
Chris PeBenito 80436b
	# for sshd subsystems, such as sftp-server.
Chris PeBenito 1815ba
	corecmd_getattr_bin_files($1_t)
Chris PeBenito 80436b
Chris PeBenito 15722e
	domain_interactive_fd($1_t)
Chris PeBenito 1815ba
	domain_subj_id_change_exemption($1_t)
Chris PeBenito 1815ba
	domain_role_change_exemption($1_t)
Chris PeBenito 1815ba
	domain_obj_id_change_exemption($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 68228b
	init_rw_utmp($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 1815ba
	userdom_dontaudit_relabelfrom_unpriv_users_ptys($1_t)
Chris PeBenito 103fe2
	userdom_search_all_users_home_content($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 bb7170
	#optional_policy(`
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 1c1ac6
	#		init_use_fds($1_t)
Chris PeBenito 1815ba
	#		init_use_script_ptys($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 1c1ac6
		init_use_fds($1_t)
Chris PeBenito 1815ba
		init_use_script_ptys($1_t)
Chris PeBenito 25c674
	#')
Chris PeBenito 80436b
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 0907bd
		kerberos_use($1_t)
Chris PeBenito 0907bd
	')
Chris PeBenito 0907bd
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 9ccd96
		mount_send_nfs_client_request($1_t)
Chris PeBenito 9ccd96
	')
Chris PeBenito 0404a3
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 1815ba
		nscd_socket_use($1_t)
Chris PeBenito 493d6c
	')
Chris PeBenito 0404a3
')
Chris PeBenito 9ccd96
Chris PeBenito 62a7b0
########################################
Chris PeBenito 3b3113
## <summary>
Chris PeBenito 3b3113
##	Send a SIGCHLD signal to the ssh server.
Chris PeBenito 3b3113
## </summary>
Chris PeBenito 3b3113
## <param name="domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 3b3113
##	Domain allowed access.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 3b3113
## </param>
Chris PeBenito 3b3113
#
Chris PeBenito 3b3113
interface(`ssh_sigchld',`
Chris PeBenito 3b3113
	gen_require(`
Chris PeBenito 3b3113
		type sshd_t;
Chris PeBenito 3b3113
	')
Chris PeBenito 3b3113
Chris PeBenito 3b3113
	allow $1 sshd_t:process sigchld;
Chris PeBenito 3b3113
')
Chris PeBenito 3b3113
Chris PeBenito 3b3113
########################################
Chris PeBenito 3b3113
## <summary>
Chris PeBenito 3b3113
##	Read a ssh server unnamed pipe.
Chris PeBenito 3b3113
## </summary>
Chris PeBenito 3b3113
## <param name="domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 3b3113
##	Domain allowed access.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 3b3113
## </param>
Chris PeBenito 3b3113
#
Chris PeBenito 1815ba
interface(`ssh_read_pipes',`
Chris PeBenito 3b3113
	gen_require(`
Chris PeBenito 3b3113
		type sshd_t;
Chris PeBenito 3b3113
	')
Chris PeBenito 3b3113
Chris PeBenito 3b3113
	allow $1 sshd_t:fifo_file { getattr read };
Chris PeBenito 3b3113
')
Chris PeBenito 3b3113
Chris PeBenito 3b3113
########################################
Chris PeBenito 3b3113
## <summary>
Chris PeBenito 3b3113
##	Do not audit attempts to read and write
Chris PeBenito 3b3113
##	ssh server TCP sockets.
Chris PeBenito 3b3113
## </summary>
Chris PeBenito 3b3113
## <param name="domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 3b3113
##	Domain to not audit.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 3b3113
## </param>
Chris PeBenito 3b3113
#
Chris PeBenito 1815ba
interface(`ssh_dontaudit_rw_tcp_sockets',`
Chris PeBenito 3b3113
	gen_require(`
Chris PeBenito 3b3113
		type sshd_t;
Chris PeBenito 3b3113
	')
Chris PeBenito 3b3113
Chris PeBenito 3b3113
	dontaudit $1 sshd_t:tcp_socket { read write };
Chris PeBenito 3b3113
')
Chris PeBenito 3b3113
Chris PeBenito 3b3113
########################################
Chris PeBenito 3b3113
## <summary>
Chris PeBenito 24a637
##	Connect to SSH daemons over TCP sockets.
Chris PeBenito 24a637
## </summary>
Chris PeBenito 24a637
## <param name="domain">
Chris PeBenito 24a637
##	<summary>
Chris PeBenito 24a637
##	Domain allowed access.
Chris PeBenito 24a637
##	</summary>
Chris PeBenito 24a637
## </param>
Chris PeBenito 24a637
#
Chris PeBenito 24a637
interface(`ssh_tcp_connect',`
Chris PeBenito 24a637
	gen_require(`
Chris PeBenito 24a637
		type sshd_t;
Chris PeBenito 24a637
	')
Chris PeBenito 24a637
Chris PeBenito 24a637
	allow $1 sshd_t:tcp_socket { connectto recvfrom };
Chris PeBenito 24a637
	allow sshd_t $1:tcp_socket { acceptfrom recvfrom };
Chris PeBenito 24a637
	kernel_tcp_recvfrom($1)
Chris PeBenito 24a637
')
Chris PeBenito 24a637
Chris PeBenito 24a637
########################################
Chris PeBenito 24a637
## <summary>
Chris PeBenito 3b3113
##	Read ssh server keys
Chris PeBenito 3b3113
## </summary>
Chris PeBenito 62a7b0
## <param name="domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 3b3113
##	Domain allowed access.
Chris PeBenito 885b83
##	</summary>
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
	')
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	dontaudit $1 sshd_key_t:file { getattr read };
Chris PeBenito 9ccd96
')