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 e88003
#
Chris PeBenito 199895
template(`ssh_per_userdomain_template',`
Chris PeBenito 9ccd96
	##############################
Chris PeBenito 9ccd96
	#
Chris PeBenito 9ccd96
	# Declarations
Chris PeBenito 9ccd96
	#
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	type $1_home_ssh_t; #, $1_file_type;
Chris PeBenito 8fd367
	files_type($1_home_ssh_t)
Chris PeBenito 0404a3
	role $1_r types $1_ssh_t;
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	type $1_ssh_t; #, nscd_client_domain;
Chris PeBenito 9ccd96
	domain_type($1_ssh_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	type $1_ssh_agent_t;
Chris PeBenito 9ccd96
	domain_type($1_ssh_agent_t)
Chris PeBenito 9ccd96
	role $1_r types $1_ssh_agent_t;
Chris PeBenito 9ccd96
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 9ccd96
	allow $1_ssh_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem dyntransition };
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 0404a3
	domain_auto_trans($1_t, ssh_exec_t, $1_ssh_t)
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 aad5b9
	allow $1_ssh_t $1_t:unix_stream_socket rw_socket_perms;
Chris PeBenito aad5b9
	allow $1_ssh_t $1_t:unix_stream_socket connectto;
Chris PeBenito aad5b9
Chris PeBenito aad5b9
	# user can manage the keys and config
Chris PeBenito aad5b9
	allow $1_t $1_home_ssh_t:dir rw_dir_perms;
Chris PeBenito aad5b9
	allow $1_t $1_home_ssh_t:file create_file_perms;
Chris PeBenito aad5b9
	allow $1_t $1_home_ssh_t:lnk_file create_lnk_perms;
Chris PeBenito aad5b9
	allow $1_t $1_home_ssh_t:sock_file create_file_perms;
Chris PeBenito aad5b9
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 d3b892
	corenet_tcp_bind_all_nodes($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 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 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 d3b892
Chris PeBenito aad5b9
	userdom_use_unpriv_users_fd($1_ssh_t)
Chris PeBenito aad5b9
Chris PeBenito d3b892
	tunable_policy(`use_dns',`
Chris PeBenito d3b892
		allow $1_ssh_t self:udp_socket { create ioctl read getattr write setattr append bind getopt setopt shutdown connect };
Chris PeBenito d3b892
		corenet_udp_sendrecv_all_if($1_ssh_t)
Chris PeBenito d3b892
		corenet_udp_sendrecv_all_nodes($1_ssh_t)
Chris PeBenito d3b892
		corenet_udp_sendrecv_dns_port($1_ssh_t)
Chris PeBenito d3b892
		corenet_udp_bind_all_nodes($1_ssh_t)
Chris PeBenito d3b892
	')
Chris PeBenito d3b892
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 a7a979
	optional_policy(`kerberos.te',`
Chris PeBenito a7a979
		kerberos_use($1_ssh_t)
Chris PeBenito a7a979
	')
Chris PeBenito a7a979
Chris PeBenito ab940a
	optional_policy(`nis.te',`
Chris PeBenito ab940a
		nis_use_ypbind($1_ssh_t)
Chris PeBenito ab940a
	')
Chris PeBenito 0404a3
Chris PeBenito ab940a
	ifdef(`TODO',`
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	allow $1 sbin_t:dir r_dir_perms;
Chris PeBenito 9ccd96
	allow $1 sbin_t:notdevfile_class_set r_file_perms;
Chris PeBenito 0404a3
Chris PeBenito 9ccd96
	if (read_default_t) {
Chris PeBenito 9ccd96
		allow $1 default_t:dir r_dir_perms;
Chris PeBenito 9ccd96
		allow $1 default_t:notdevfile_class_set r_file_perms;
Chris PeBenito 9ccd96
	}
Chris PeBenito 0404a3
Chris PeBenito 0404a3
	# Read /var.
Chris PeBenito 0404a3
	allow $1_ssh_t var_t:dir r_dir_perms;
Chris PeBenito 0404a3
	allow $1_ssh_t var_t:notdevfile_class_set r_file_perms;
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:dir search;
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
	# Write to the user domain tty.
Chris PeBenito 9ccd96
	allow $1_ssh_t $1_tty_device_t:chr_file { read write getattr ioctl };
Chris PeBenito 9ccd96
	allow $1_ssh_t devpts_t:dir { read search getattr };
Chris PeBenito 9ccd96
	allow $1_ssh_t $1_devpts_t:chr_file { read write getattr ioctl };
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
	ifdef(`xserver.te', `
Chris PeBenito 0404a3
	# Communicate with the X server.
Chris PeBenito 0404a3
	ifdef(`startx.te', `
Chris PeBenito 0404a3
	can_unix_connect($1_ssh_t, $1_xserver_t)
Chris PeBenito 0404a3
	allow $1_ssh_t $1_xserver_tmp_t:sock_file rw_file_perms;
Chris PeBenito 0404a3
	allow $1_ssh_t $1_xserver_tmp_t:dir search;
Chris PeBenito 0404a3
	')dnl end if startx
Chris PeBenito 0404a3
	ifdef(`xdm.te', `
Chris PeBenito 0404a3
	allow $1_ssh_t { xdm_xserver_tmp_t xdm_tmp_t }:dir search;
Chris PeBenito 0404a3
	allow $1_ssh_t { xdm_tmp_t }:sock_file write;
Chris PeBenito 0404a3
	')
Chris PeBenito 0404a3
	')dnl end if xserver
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 0404a3
	ifdef(`xdm.te', `
Chris PeBenito 0404a3
	# should be able to remove these two later
Chris PeBenito 0404a3
	allow $1_ssh_t xdm_xserver_tmp_t:sock_file { read write };
Chris PeBenito 0404a3
	allow $1_ssh_t xdm_xserver_tmp_t:dir search;
Chris PeBenito 0404a3
	allow $1_ssh_t xdm_xserver_t:unix_stream_socket connectto;
Chris PeBenito 0404a3
	allow $1_ssh_t xdm_xserver_t:shm r_shm_perms;
Chris PeBenito 0404a3
	allow $1_ssh_t xdm_xserver_t:fd use;
Chris PeBenito 0404a3
	allow $1_ssh_t xdm_xserver_tmpfs_t:file read;
Chris PeBenito 0404a3
	allow $1_ssh_t xdm_t:fd use;
Chris PeBenito 0404a3
	')dnl end if xdm.te
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 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 9ccd96
	allow $1_ssh_agent_t { $1_ssh_agent_t $1_t }: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 9ccd96
	domain_auto_trans($1_t, ssh_agent_exec_t, $1_ssh_agent_t)
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 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 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 9ccd96
	if (use_nfs_home_dirs) {
Chris PeBenito 9ccd96
		fs_manage_nfs_files($1_ssh_agent_t)
Chris PeBenito 9ccd96
	}
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	if (use_samba_home_dirs) {
Chris PeBenito 9ccd96
		fs_manage_cifs_files($1_ssh_agent_t)
Chris PeBenito 9ccd96
	}
Chris PeBenito 9ccd96
Chris PeBenito ab940a
	optional_policy(`nis.te',`
Chris PeBenito ab940a
		nis_use_ypbind($1_ssh_agent_t)
Chris PeBenito ab940a
	')
Chris PeBenito ab940a
Chris PeBenito 9ccd96
	ifdef(`TODO',`
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# Write to the user domain tty.
Chris PeBenito 9ccd96
	access_terminal($1_ssh_agent_t, $1)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# Allow the user shell to signal the ssh program.
Chris PeBenito 9ccd96
	allow $1_t $1_ssh_agent_t:process signal;
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
	allow $1_ssh_agent_t proc_t:dir search;
Chris PeBenito 9ccd96
	dontaudit $1_ssh_agent_t proc_t:{ lnk_file file } { getattr read };
Chris PeBenito 9ccd96
	dontaudit $1_ssh_agent_t selinux_config_t:dir search;
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
	# for ssh-add
Chris PeBenito 9ccd96
	can_unix_connect($1_t, $1_ssh_agent_t)
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# transition back to normal privs upon exec
Chris PeBenito 9ccd96
	domain_auto_trans($1_ssh_agent_t, { bin_t shell_exec_t $1_home_t }, $1_t)
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t bin_t:dir search;
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t bin_t:lnk_file read;
Chris PeBenito 9ccd96
	if (use_nfs_home_dirs) {
Chris PeBenito 9ccd96
	domain_auto_trans($1_ssh_agent_t, nfs_t, $1_t)
Chris PeBenito 9ccd96
	}
Chris PeBenito 9ccd96
	if (use_samba_home_dirs) {
Chris PeBenito 9ccd96
	domain_auto_trans($1_ssh_agent_t, cifs_t, $1_t)
Chris PeBenito 9ccd96
	}
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t { home_root_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
	ifdef(`xdm.te', `
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t xdm_t:fd use;
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t xdm_t:fifo_file { read write };
Chris PeBenito 9ccd96
Chris PeBenito 9ccd96
	# kdm: sigchld
Chris PeBenito 9ccd96
	allow $1_ssh_agent_t xdm_t:process sigchld;
Chris PeBenito 9ccd96
	')
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 9ccd96
	allow $1_ssh_t $1_t:unix_stream_socket connectto;
Chris PeBenito 9ccd96
	allow $1_ssh_t sshd_t:unix_stream_socket connectto;
Chris PeBenito 9ccd96
	') dnl endif TODO
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 aad5b9
	type $1_t, ssh_server; #, nscd_client_domain;
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 0404a3
	corenet_tcp_bind_all_nodes($1_t)
Chris PeBenito 0404a3
	corenet_udp_bind_all_nodes($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 0404a3
Chris PeBenito 80436b
	corecmd_read_bin_symlink($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 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 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 80436b
	optional_policy(`inetd.te',`
Chris PeBenito 80436b
		tunable_policy(`run_ssh_inetd',`
Chris PeBenito 80436b
			allow $1_t self:process signal;
Chris PeBenito 80436b
			files_list_pids($1_t)
Chris PeBenito 80436b
		',`
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 80436b
		')
Chris PeBenito 80436b
	',`
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 80436b
	')
Chris PeBenito 80436b
Chris PeBenito 9ccd96
	optional_policy(`mount.te', `
Chris PeBenito 9ccd96
		mount_send_nfs_client_request($1_t)
Chris PeBenito 9ccd96
	')
Chris PeBenito 0404a3
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
')