< SELinux

SELinux/apache

Structure

Domains

The apache module provides the following domains:

DomainProcess(es)Description
httpd_tapache, lighttpdWebserver processes
httpd_helper_thtsslpassDomain for the htsslpass process
httpd_php_tphp-cgiDomain for PHP support through CGI (php-cgi process)
httpd_rotatelogs_trotatelogsDomain for the rotatelogs process
httpd_suexec_tsuexecDomain used by the webserver suexec process to switch to another user before calling and executing a script
httpd_sys_script_tDomain used by the system/package-provided CGI scripts
httpd_user_script_tDomain used by the user-provided CGI scripts
Important
The apache module allows other modules to define their own domains and types for use by the webservers. This is done through templates. The reference policy by default enabled two of such templated sets for user and sys, which you can see in domains like httpd_sys_script_t and httpd_user_script_t. It is very well possible that on your system, more of these template-instantiated domains exist.

File types/labels

The following table lists the file type/labels defined in the apache module.

  • If the function mentions (templated) then it means that the types are generated by the apache module, but that similar others might exist on your system (called through other modules).
  • When talking about scripts, we mean CGI scripts or other scripts that are triggered from the webserver, not from an interactive shell session.
TypeFunctionDescription
httpd_exec_tEntrypointEntrypoint for the webserver processes
httpd_initrc_exec_tEntrypointEntrypoint for the webserver init scripts
httpd_helper_exec_tEntrypointEntrypoint for the webserver helper processes
httpd_php_exec_tEntrypointEntrypoint for the PHP scripts
httpd_rotatelogs_exec_tEntrypointEntrypoint for the rotatelog helper
httpd_suexec_exec_tEntrypointEntrypoint for the suexec wrapper
httpd_sys_script_exec_tEntrypoint (templated)Entrypoint for system CGI scripts (or other callable scripts) that need access to the system content files (httpd_sys_content_t)
httpd_user_script_exec_tEntrypoint (templated)Entrypoint for the user-provided scripts callable from the webserver instances
httpd_squirrelmail_tContentSquirrelmail files
squirrelmail_spool_tContentSquirrelmail attachment location
httpd_sys_content_tContent (templated)Readable content for the webservers and system scripts, offered through the system / packages.
httpd_sys_htaccess_tContent (templated)Label for the htaccess files, readable by the webserver but not from scripts or other webserver related domains.
httpd_sys_rw_content_tContent (templated)Read and writeable content for the webservers and system scripts (not user scripts).
httpd_sys_ra_content_tContent (templated)Read and appendable content for the webservers and system scripts (not user scripts).
httpd_user_content_tContent (templated)Readable content for the webservers and user scripts, offered by (and writeable by) users.
httpd_user_htaccess_tContent (templated)Label for the htaccess files, readable by the webserver but not from scripts or other webserver related domains.
httpd_user_rw_content_tContent (templated)Read and writeable content for the webservers and user scripts (not system scripts).
httpd_user_ra_content_tContent (templated)Read and appendable content for the webservers and user scripts (not system scripts).
httpd_php_tmp_tTemporary FilesTemporary files from the PHP scripts
httpd_suexec_tmp_tTemporary FilesTemporery files for the suexec domain
httpd_tmp_t, httpd_tmpfs_tTemporary FilesTemporary files from the httpd domain
httpd_cache_tWeb server cache
httpd_config_tConfiguration files
httpd_lock_tLock files
httpd_log_tWeb server log files
httpd_modules_tWebserver modules
httpd_var_lib_tWebserver libraries
httpd_var_run_tRuntime files for httpd

Using apache SELinux module

File locations

The policy offered only contains the right file context rules for the default locations. If you deviate from these locations, you'll need to update the contexts accordingly.

The following table provides an overview of common Apache settings (variables in httpd.conf) that are often changed by end users, and the file context that it should have. If you use a different webserver you'll need to base it on the description instead.

Setting in httpd.confDescriptionDefault locationFile context(s)
DocumentRootLocation where web content is stored (html pages and such)/srv/localhost/wwwsystem_u:object_r:httpd_sys_content_t
DocumentLocation where CGI scripts are stored/srv/localhost/cgi-binsystem_u:object_r:httpd_sys_script_exec_t
DirectoryUser home directory location where user-provided content is stored/home/*/public_htmlsystem_u:object_r:httpd_user_content_t
DirectoryUser home directory location where user-provided CGI scripts are stored/home/*/public_html/cgi-binsystem_u:object_r:httpd_user_script_exec_t

Sharing files

The SELinux policy (as part of the miscfiles module) supports two additional types: public_content_t and public_content_rw_t. These are used for what is called anonymous files which are readable by all file-serving services. If all services only need to read from it, then public_content_t is used. If at least one services needs to write to it, use public_content_rw_t and toggle the right SELinux boolean for the domain that needs write access to it (allow_DOMAIN_anon_write).

For instance, if you have files that are shared by Apache, NFS, Samba, ... you label these public_content_t (read-only) or public_content_rw_t (read-write for some) and then toggle the appropriate booleans:

root #setsebool -P allow_httpd_sys_script_anon_write on

Booleans

The apache module has several booleans which manipulate the allowed permissions within your installation. The table below gives an overview of the booleans, but also mentions which USE flags you could associate with it. Note that the booleans are not linked to USE flags. However, if you have set a particular USE flag for the webserver environment, then you might want to toggle these booleans as well.

BooleanDescriptionGentoo USE flag suggestion
allow_httpd_anon_writeAllow the webserver to modify public files (labeled public_content_rw_t)
allow_httpd_sys_script_anon_writeAllow the system scripts to modify public files
allow_httpd_user_script_anon_wrietAllow the user scripts to modify public files
allow_httpd_mod_auth_pamAllow the webserver to use the auth_pam module
httpd_builtin_scriptingNeeded when your webservers use internal scripting languages like PHP (languages that are read and interpreted by the webserver directly rather than called through separate processes like with CGI)
httpd_can_network_connectAllow the webserver scripts and modules to connect to the network
httpd_can_network_connect_dbAllow the webserver scripts and modules to connect to databases over the network
httpd_can_network_relayAllow webservers to act as a relay
httpd_can_sendmailAllow webservers to send e-mails
httpd_dbus_avahiAllow webservers to communicate with avahi service via dbus
httpd_enable_cgiAllow webservers to call CGI scripts (labeled httpd_sys_script_exec_t or httpd_user_script_exec_t)
httpd_enable_ftp_serverAllow webservers to act as an FTP server by listening on the FTP ports
httpd_enable_homedirsAllow webservers to read home directories (user_home_t). Not to be mistaken with httpd_user_content_t, which resides in the users' home directory but is labeled, well, httpd_user_content_t ;-)
httpd_ssi_execAllow webservers to run SSI executables in the same domain as the CGI scripts
httpd_tty_comUnify webservers to communicate with the terminal. This is needed when you need to enter a passphraze for certificates at the terminal.
httpd_unifiedWhen enabled, the various webserver content types (all types with attribute httpdcontent set) are not differentiated anymore, but all considered to be readable, writeable and executable by the webserver.
httpd_use_cifsAllow webservers to access CIFS file systems
httpd_use_gpgAllow webservers to run gpg
httpd_use_nfsAllow webservers to access NFS file systems

If you want to toggle booleans, you can do so through setsebool:

root #setsebool -P httpd_enable_homedirs on

Ports

If you need to run the webserver on a non-default port, you can either mark this port as an HTTP port (http_port_t) or create the appropriate rule to allow it to bind to the specified port.

To mark a particular port (say 81) as an HTTP port, use semanage:

root #semanage port -a -t http_port_t -p tcp 81

If you need to allow the webserver to bind on a port but are not allowed to modify that ports' type, you'll need to create a policy that allows the httpd_t domain to bind to the particular port. For instance, to allow it to bind on the SMTP port:

allow httpd_t smtp_port_t:tcp_socket name_bind;
This article is issued from Gentoo. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.