Apache HTTPd et SELinux

Rédigé par Nicolas Sulek Aucun commentaire
Classé dans : Services réseaux Mots clés : Apache, CentOS, FTP, IMAP, Memcached, MySQL, PAM, POP3, Samba, SELInux, Spam
L'activation de SELinux avec la politique targeted sur CentOS peut nécessiter quelques modifications pour qu'Apache HTTPd fonctionne comme désiré. Voici quelques explications.

Règles mises en place par défaut par SELinux


Paramètres par défaut


[root@web ~]# getsebool -a |grep httpd
allow_httpd_anon_write --> off
allow_httpd_mod_auth_ntlm_winbind --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> on
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_read_user_content --> off
httpd_setrlimit --> on
httpd_ssi_exec --> off
httpd_tmp_exec --> off
httpd_tty_comm --> on
httpd_unified --> on
httpd_use_cifs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off

Quelques explications


allow_httpd_anon_write


Autorise l'écriture dans des fichiers "publics", c'est-à-dire ayant pour contextes SELinux public_content_t et public_content_rw_t. Utile dans le cas de partage de fichiers entre plusieurs domaines SELinux (Apache, FTP, Samba, ...).

allow_httpd_mod_auth_ntlm_winbind :


Autorise l'utilisation de l'authentification NTLM avec Winbind (Samba).

allow_httpd_mod_auth_pam


Autorise l'utilisation de l'authentification en utilisant les modules PAM.

allow_httpd_sys_script_anon_write


Autorise des scripts systèmes d'Apache HTTPd à écrire dans des fichiers "publics". Similaire à allow_httpd_anon_write.

httpd_builtin_scripting


Active les interpréteurs de scripts (PHP ou d'autres modules du même genre).

httpd_can_check_spam


Permet à Apache HTTPd à vérifier les spams.

httpd_can_network_connect


Permet aux scripts exécutés par Apache HTTPd à se connecter à d'autres réseaux.

httpd_can_network_connect_cobbler


Autorise Apache HTTPd ou ses modules à se connecter à un serveur Cobbler.

httpd_can_network_connect_db


Autorise Apache HTTPd ou ses modules à se connecter à un serveur de base de données par le réseau.

httpd_can_network_memcache


Autorise Apache HTTPd ou ses modules à se connecter à un serveur memcache.

httpd_can_network_relay


Autorise Apache HTTPd à se comporter comme un serveur relai.

httpd_can_sendmail


Autorise Apache HTTpd ou ses modules à se connecter à un serveur de messagerie (SMTP, POP, IMAP).

httpd_dbus_avahi


Apache HTTPd peut être configuré avec le support Avahi. Ce booléen permet d'autoriser le communication DBUS entre Apache HTTPd et le service Avahi.

httpd_enable_cgi


Active le support des scripts CGI.

httpd_enable_ftp_server


Permet à Apache HTTPd d'être configuré comme un serveur FTP et d'écouter sur le port FTP.

httpd_enable_homedirs


Autorise Apache HTTPd à accéder aux répertoires utilisateurs.

httpd_execmem


Donne la permission execmem (mémoire exécutable) à Apache HTTPd. A ne pas faire pour des raisons de sécurité.

httpd_read_user_content


Permet à Apache HTTPd de lire le contenu des répertoires utilisateurs.

httpd_setrlimit


Autorise Apache HTTPd à changer les limites systèmes.

httpd_ssi_exec


Permet à Apache HTTPd d'utiliser les SSI dont les directives sont inclues dans les pages HTML.

httpd_tmp_exec


Autorise Apache HTTPd à exécuter des fichiers stockés dans /tmp.

httpd_tty_comm


Permet à Apache HTTPd d'accéder aux terminaux des consoles (tty).

httpd_unified


Apache HTTPd peut être configuré pour ne pas différencier les contrôles de fichiers en se basant sur le contexte SELinux, c'est-à-dire tous les fichiers labellisés avec le contexte httpd peuvent être lus, écrits, modifiés. Positionner ce booléen à false permet de mettre en place une politique de sécurité telle qu'un service httpd ne peut interférer avec un autre.

httpd_use_cifs


Autorise Apache HTTPd à utiliser CIFS pour les transferts de fichiers.

httpd_use_gpg


Permet à Apache HTTPd de changer les limites systèmes pour les extensions GPG fonctionnant dans le même domaine SELinux que httpd.

httpd_use_nfs


Autorise Apache HTTPd à utiliser NFS pour les transferts de fichiers.

Quelques modifications utiles


Connexion à des bases de données


Par défaut, la politique targeted de SELinux interdit à Apache HTTPd, ainsi que ses modules (par exemple PHP), de se connecter à un serveur de base de données :
[root@bob ~]# getsebool httpd_can_network_connect_db
httpd_can_network_connect_db --> off

Il peut être utile de modifier ce booléen si on désire utiliser des applications Web nécessitant des connexions à des bases de données MySQL ou PostgreSQL :
[root@bob ~]# setsebool -P httpd_can_network_connect_db=1
[root@bob ~]# getsebool httpd_can_network_connect_db
httpd_can_network_connect_db --> on

Le -P permet de rendre le changement permanent

Utilisation de serveurs de messagerie


Par défaut, la politique targeted de SELinux interdit à Apache HTTPd d'utiliser des serveurs de messageries (SMTP, POP3, IMAP) :
[root@bob ~]# getsebool httpd_can_sendmail
httpd_can_sendmail --> off

Il peut être utile d'autoriser ces connexions, notamment si on utilise un Webmail comme Roundcube :
[root@bob ~]# setsebool -P httpd_can_sendmail=1
[root@bob ~]# getsebool httpd_can_sendmail
httpd_can_sendmail --> on

Permission d'écriture pour Apache HTTPd


Avec les règles mises en place, HTTPd ne peut pas écrire dans les fichiers ou les répertoires, car ils sont par défaut dans le contexte httpd_sys_content_t :
[root@bob ~]# ls -Z /var/www/html/
drwxr-xr-x. munin munin system_u:object_r:httpd_munin_content_t:s0 munin
drwxr-x---. apache apache system_u:object_r:httpd_sys_content_t:s0 roundcube
drwxr-x---. apache apache system_u:object_r:httpd_sys_content_t:s0 tmp
drwxr-x---. apache apache system_u:object_r:httpd_sys_content_t:s0 wordpress

Le changement de contexte s'effectue avec chcon. Par exemple, pour rendre /var/www/html/tmp modifiable par Apache HTTPd :
[root@bob ~]# chcon -R -t httpd_sys_content_rw_t /var/www/tmp
[root@bob ~]# ls -Z /var/www/html/
drwxr-xr-x. munin munin system_u:object_r:httpd_munin_content_t:s0 munin
drwxr-x---. apache apache system_u:object_r:httpd_sys_content_t:s0 roundcube
drwxr-x---. apache apache system_u:object_r:httpd_sys_content_rw_t:s0 tmp
drwxr-x---. apache apache system_u:object_r:httpd_sys_content_t:s0 wordpress

Le -R rend la commande récursive, comme pour chmod, chown, ...

Les commentaires sont fermés.