Chris PeBenito fc6524
Chris PeBenito 2dbd38
policy_module(ftp,1.2.6)
Chris PeBenito fc6524
Chris PeBenito fc6524
########################################
Chris PeBenito fc6524
#
Chris PeBenito fc6524
# Declarations
Chris PeBenito fc6524
#
Chris PeBenito fc6524
Chris PeBenito fc6524
type ftpd_t;
Chris PeBenito fc6524
type ftpd_exec_t;
Chris PeBenito fc6524
init_daemon_domain(ftpd_t,ftpd_exec_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
type ftpd_etc_t;
Chris PeBenito 9bbc75
files_config_file(ftpd_etc_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
# ftpd_lock_t is only needed when ftpd_is_daemon is true, but we cannot define types conditionally
Chris PeBenito fc6524
type ftpd_lock_t;
Chris PeBenito fc6524
files_lock_file(ftpd_lock_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
type ftpd_tmp_t;
Chris PeBenito fc6524
files_tmp_file(ftpd_tmp_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
type ftpd_tmpfs_t;
Chris PeBenito fc6524
files_tmpfs_file(ftpd_tmpfs_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
type ftpd_var_run_t;
Chris PeBenito fc6524
files_pid_file(ftpd_var_run_t)
Chris PeBenito fc6524
Chris PeBenito 75fbbb
type ftpdctl_t;
Chris PeBenito 75fbbb
type ftpdctl_exec_t;
Chris PeBenito 75fbbb
init_system_domain(ftpdctl_t,ftpdctl_exec_t)
Chris PeBenito 75fbbb
Chris PeBenito 75fbbb
type ftpdctl_tmp_t;
Chris PeBenito 75fbbb
files_tmp_file(ftpdctl_tmp_t)
Chris PeBenito 75fbbb
Chris PeBenito fc6524
type xferlog_t;
Chris PeBenito fc6524
logging_log_file(xferlog_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
########################################
Chris PeBenito fc6524
#
Chris PeBenito 75fbbb
# ftpd local policy
Chris PeBenito fc6524
#
Chris PeBenito fc6524
Chris PeBenito fc6524
allow ftpd_t self:capability { chown fowner fsetid setgid setuid sys_chroot sys_nice sys_resource };
Chris PeBenito fc6524
dontaudit ftpd_t self:capability sys_tty_config;
Chris PeBenito fc6524
allow ftpd_t self:process signal_perms;
Chris PeBenito fc6524
allow ftpd_t self:process { getcap setcap setsched setrlimit };
Chris PeBenito fc6524
allow ftpd_t self:fifo_file rw_file_perms;
Chris PeBenito fc6524
allow ftpd_t self:unix_dgram_socket { sendto create_socket_perms };
Chris PeBenito 75fbbb
allow ftpd_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito fc6524
allow ftpd_t self:tcp_socket create_stream_socket_perms;
Chris PeBenito fc6524
allow ftpd_t self:udp_socket create_socket_perms;
Chris PeBenito fc6524
Chris PeBenito e6a2ea
allow ftpd_t ftpd_etc_t:file r_file_perms;
Chris PeBenito fc6524
Chris PeBenito fc6524
allow ftpd_t ftpd_tmp_t:dir create_dir_perms;
Chris PeBenito fc6524
allow ftpd_t ftpd_tmp_t:file create_file_perms;
Chris PeBenito 103fe2
files_tmp_filetrans(ftpd_t, ftpd_tmp_t, { file dir })
Chris PeBenito fc6524
Chris PeBenito e6a2ea
allow ftpd_t ftpd_tmpfs_t:fifo_file create_file_perms;
Chris PeBenito e6a2ea
allow ftpd_t ftpd_tmpfs_t:dir create_dir_perms;
Chris PeBenito e6a2ea
allow ftpd_t ftpd_tmpfs_t:file create_file_perms;
Chris PeBenito e6a2ea
allow ftpd_t ftpd_tmpfs_t:lnk_file create_lnk_perms;
Chris PeBenito e6a2ea
allow ftpd_t ftpd_tmpfs_t:sock_file create_file_perms;
Chris PeBenito 103fe2
fs_tmpfs_filetrans(ftpd_t,ftpd_tmpfs_t,{ dir file lnk_file sock_file fifo_file })
Chris PeBenito fc6524
Chris PeBenito 2dbd38
allow ftpd_t ftpd_var_run_t:file manage_file_perms;
Chris PeBenito e6a2ea
allow ftpd_t ftpd_var_run_t:dir rw_dir_perms;
Chris PeBenito 2dbd38
allow ftpd_t ftpd_var_run_t:sock_file manage_file_perms;
Chris PeBenito 1c1ac6
files_pid_filetrans(ftpd_t,ftpd_var_run_t,file)
Chris PeBenito e6a2ea
Chris PeBenito 75fbbb
# proftpd requires the client side to bind a socket so that
Chris PeBenito 75fbbb
# it can stat the socket to perform access control decisions,
Chris PeBenito 75fbbb
# since getsockopt with SO_PEERCRED is not available on all
Chris PeBenito 75fbbb
# proftpd-supported OSs
Chris PeBenito 75fbbb
allow ftpd_t ftpdctl_tmp_t:sock_file { getattr unlink };
Chris PeBenito 75fbbb
Chris PeBenito fc6524
# Create and modify /var/log/xferlog.
Chris PeBenito 8cfa5a
allow ftpd_t xferlog_t:dir search_dir_perms;
Chris PeBenito fc6524
allow ftpd_t xferlog_t:file create_file_perms;
Chris PeBenito 1c1ac6
logging_log_filetrans(ftpd_t,xferlog_t,file)
Chris PeBenito fc6524
Chris PeBenito 445522
kernel_read_kernel_sysctls(ftpd_t)
Chris PeBenito fc6524
kernel_read_system_state(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
dev_read_sysfs(ftpd_t)
Chris PeBenito fc6524
dev_read_urand(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito 049e11
corecmd_exec_bin(ftpd_t)
Chris PeBenito 049e11
corecmd_exec_sbin(ftpd_t)
Chris PeBenito 049e11
# Execute /bin/ls (can comment this out for proftpd)
Chris PeBenito 049e11
# also may need rules to allow tar etc...
Chris PeBenito 049e11
corecmd_exec_ls(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito b516e8
corenet_non_ipsec_sendrecv(ftpd_t)
Chris PeBenito fc6524
corenet_tcp_sendrecv_all_if(ftpd_t)
Chris PeBenito fc6524
corenet_udp_sendrecv_all_if(ftpd_t)
Chris PeBenito fc6524
corenet_tcp_sendrecv_all_nodes(ftpd_t)
Chris PeBenito fc6524
corenet_udp_sendrecv_all_nodes(ftpd_t)
Chris PeBenito fc6524
corenet_tcp_sendrecv_all_ports(ftpd_t)
Chris PeBenito fc6524
corenet_udp_sendrecv_all_ports(ftpd_t)
Chris PeBenito fc6524
corenet_tcp_bind_all_nodes(ftpd_t)
Chris PeBenito 9a879b
corenet_tcp_bind_ftp_port(ftpd_t)
Chris PeBenito fc6524
corenet_tcp_bind_ftp_data_port(ftpd_t)
Chris PeBenito fc6524
corenet_tcp_bind_generic_port(ftpd_t)
Chris PeBenito fc6524
corenet_tcp_connect_all_ports(ftpd_t)
Chris PeBenito 9a879b
corenet_sendrecv_ftp_server_packets(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito 15722e
domain_use_interactive_fds(ftpd_t)
Chris PeBenito 049e11
Chris PeBenito 049e11
files_search_etc(ftpd_t)
Chris PeBenito 049e11
files_read_etc_files(ftpd_t)
Chris PeBenito 049e11
files_read_etc_runtime_files(ftpd_t)
Chris PeBenito 9e04f5
files_search_var_lib(ftpd_t)
Chris PeBenito 049e11
Chris PeBenito 049e11
fs_search_auto_mountpoints(ftpd_t)
Chris PeBenito 049e11
fs_getattr_all_fs(ftpd_t)
Chris PeBenito 049e11
Chris PeBenito fc6524
term_dontaudit_use_console(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito 049e11
auth_use_nsswitch(ftpd_t)
Chris PeBenito e6a2ea
auth_domtrans_chk_passwd(ftpd_t)
Chris PeBenito fc6524
# Append to /var/log/wtmp.
Chris PeBenito fc6524
auth_append_login_records(ftpd_t)
Chris PeBenito fc6524
#kerberized ftp requires the following
Chris PeBenito fc6524
auth_write_login_records(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito 1c1ac6
init_use_fds(ftpd_t)
Chris PeBenito 1815ba
init_use_script_ptys(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
libs_use_ld_so(ftpd_t)
Chris PeBenito fc6524
libs_use_shared_libs(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
logging_send_syslog_msg(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
miscfiles_read_localization(ftpd_t)
Chris PeBenito fc6524
miscfiles_read_public_files(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
seutil_dontaudit_search_config(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
sysnet_read_config(ftpd_t)
Chris PeBenito 85a0f9
sysnet_use_ldap(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito 103fe2
userdom_dontaudit_search_sysadm_home_dirs(ftpd_t)
Chris PeBenito 15722e
userdom_dontaudit_use_unpriv_user_fds(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
ifdef(`targeted_policy',`
Chris PeBenito 9e04f5
	files_dontaudit_read_root_files(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito 1815ba
	term_dontaudit_use_generic_ptys(ftpd_t)
Chris PeBenito 1815ba
	term_dontaudit_use_unallocated_ttys(ftpd_t)
Chris PeBenito fc6524
')
Chris PeBenito fc6524
Chris PeBenito fc6524
tunable_policy(`allow_ftpd_anon_write',`
Chris PeBenito fc6524
	miscfiles_manage_public_files(ftpd_t)
Chris PeBenito 522b59
')
Chris PeBenito 522b59
Chris PeBenito 522b59
tunable_policy(`allow_ftpd_use_cifs',`
Chris PeBenito 522b59
	fs_read_cifs_files(ftpd_t)
Chris PeBenito 522b59
	fs_read_cifs_symlinks(ftpd_t)
Chris PeBenito 522b59
')
Chris PeBenito 522b59
Chris PeBenito 522b59
tunable_policy(`allow_ftpd_use_cifs && allow_ftpd_anon_write',`
Chris PeBenito 522b59
	fs_manage_cifs_files(ftpd_t)
Chris PeBenito 522b59
')
Chris PeBenito 522b59
Chris PeBenito 522b59
tunable_policy(`allow_ftpd_use_nfs',`
Chris PeBenito 522b59
	fs_read_nfs_files(ftpd_t)
Chris PeBenito 522b59
	fs_read_nfs_symlinks(ftpd_t)
Chris PeBenito 522b59
')
Chris PeBenito 522b59
Chris PeBenito 522b59
tunable_policy(`allow_ftpd_use_nfs && allow_ftpd_anon_write',`
Chris PeBenito 522b59
	fs_manage_nfs_files(ftpd_t)
Chris PeBenito 522b59
')
Chris PeBenito fc6524
Chris PeBenito fc6524
tunable_policy(`ftp_home_dir',`
Chris PeBenito 165b42
	allow ftpd_t self:capability { dac_override dac_read_search };
Chris PeBenito 165b42
Chris PeBenito fc6524
	# allow access to /home
Chris PeBenito d8636f
	files_list_home(ftpd_t)
Chris PeBenito 103fe2
	userdom_read_all_users_home_content_files(ftpd_t)
Chris PeBenito 103fe2
	userdom_manage_all_users_home_content_dirs(ftpd_t)
Chris PeBenito 103fe2
	userdom_manage_all_users_home_content_files(ftpd_t)
Chris PeBenito 103fe2
	userdom_manage_all_users_home_content_symlinks(ftpd_t)
Chris PeBenito d8636f
Chris PeBenito d8636f
	ifdef(`targeted_policy',`
Chris PeBenito 103fe2
		userdom_generic_user_home_dir_filetrans_generic_user_home_content(ftpd_t,{ dir file lnk_file sock_file fifo_file })
Chris PeBenito d8636f
	')
Chris PeBenito fc6524
')
Chris PeBenito fc6524
Chris PeBenito 522b59
tunable_policy(`ftp_home_dir && use_nfs_home_dirs',`
Chris PeBenito 522b59
	fs_manage_nfs_files(ftpd_t)
Chris PeBenito 522b59
	fs_read_nfs_symlinks(ftpd_t)
Chris PeBenito 522b59
')
Chris PeBenito 522b59
Chris PeBenito 522b59
tunable_policy(`ftp_home_dir && use_samba_home_dirs',`
Chris PeBenito 522b59
	fs_manage_cifs_files(ftpd_t)
Chris PeBenito 522b59
	fs_read_cifs_symlinks(ftpd_t)
Chris PeBenito 522b59
')
Chris PeBenito 522b59
Chris PeBenito fc6524
tunable_policy(`ftpd_is_daemon',`
Chris PeBenito fc6524
	allow ftpd_t ftpd_lock_t:file create_file_perms;
Chris PeBenito 1c1ac6
	files_lock_filetrans(ftpd_t,ftpd_lock_t,file)
Chris PeBenito fc6524
Chris PeBenito fc6524
	corenet_tcp_bind_ftp_port(ftpd_t)
Chris PeBenito fc6524
')
Chris PeBenito fc6524
Chris PeBenito bb7170
optional_policy(`
Chris PeBenito fc6524
	corecmd_exec_shell(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito 77f6e2
	files_read_usr_files(ftpd_t)
Chris PeBenito fc6524
Chris PeBenito fc6524
       	cron_system_entry(ftpd_t, ftpd_exec_t)
Chris PeBenito fc6524
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito fc6524
		logrotate_exec(ftpd_t)
Chris PeBenito fc6524
	')
Chris PeBenito fc6524
')
Chris PeBenito fc6524
Chris PeBenito bb7170
optional_policy(`
Chris PeBenito 44d5d9
	daemontools_service_domain(ftpd_t, ftpd_exec_t)
Chris PeBenito 44d5d9
')
Chris PeBenito 44d5d9
Chris PeBenito bb7170
optional_policy(`
Chris PeBenito 784a3b
	#reh: typeattributes not allowed in conditionals yet.
Chris PeBenito 784a3b
	#tunable_policy(`! ftpd_is_daemon',`
Chris PeBenito 784a3b
	#	inetd_tcp_service_domain(ftpd_t,ftpd_exec_t)
Chris PeBenito 784a3b
	#')
Chris PeBenito fc6524
Chris PeBenito 73ef29
	inetd_tcp_service_domain(ftpd_t,ftpd_exec_t)
Chris PeBenito 73ef29
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 77f6e2
		tunable_policy(`! ftpd_is_daemon',`
Chris PeBenito fc6524
			tcpd_domtrans(tcpd_t)
Chris PeBenito fc6524
		')
Chris PeBenito 77f6e2
	')
Chris PeBenito fc6524
')
Chris PeBenito fc6524
Chris PeBenito bb7170
optional_policy(`
Chris PeBenito 1815ba
	nscd_socket_use(ftpd_t)
Chris PeBenito e6a2ea
')
Chris PeBenito e6a2ea
Chris PeBenito bb7170
optional_policy(`
Chris PeBenito fc6524
	seutil_sigchld_newrole(ftpd_t)
Chris PeBenito fc6524
')
Chris PeBenito fc6524
Chris PeBenito bb7170
optional_policy(`
Chris PeBenito fc6524
	udev_read_db(ftpd_t)
Chris PeBenito fc6524
')
Chris PeBenito 75fbbb
Chris PeBenito 75fbbb
########################################
Chris PeBenito 75fbbb
#
Chris PeBenito 75fbbb
# ftpdctl local policy
Chris PeBenito 75fbbb
#
Chris PeBenito 75fbbb
Chris PeBenito 75fbbb
# Allow ftpdctl to talk to ftpd over a socket connection
Chris PeBenito 75fbbb
allow ftpdctl_t ftpd_t:unix_stream_socket connectto;
Chris PeBenito 75fbbb
allow ftpdctl_t ftpd_var_run_t:dir search;
Chris PeBenito 75fbbb
allow ftpdctl_t ftpd_var_run_t:sock_file write;
Chris PeBenito 75fbbb
Chris PeBenito 75fbbb
# ftpdctl creates a socket so that the daemon can perform
Chris PeBenito 75fbbb
# access control decisions (see comments in ftpd_t rules above)
Chris PeBenito 75fbbb
allow ftpdctl_t ftpdctl_tmp_t:sock_file { create setattr };
Chris PeBenito 75fbbb
files_tmp_filetrans(ftpdctl_t, ftpdctl_tmp_t, sock_file)
Chris PeBenito 75fbbb
Chris PeBenito 75fbbb
# Allow ftpdctl to read config files
Chris PeBenito 75fbbb
files_read_etc_files(ftpdctl_t)
Chris PeBenito 75fbbb
Chris PeBenito 75fbbb
libs_use_ld_so(ftpdctl_t)
Chris PeBenito 75fbbb
libs_use_shared_libs(ftpdctl_t)
Chris PeBenito 75fbbb
Chris PeBenito 75fbbb
ifdef(`targeted_policy',`
Chris PeBenito 75fbbb
	term_use_generic_ptys(ftpdctl_t)
Chris PeBenito 75fbbb
')