====== Voraussetzungen ====== * [[lpi2:apache|Apache httpd]] installiert ====== HTML Datei im Zielverzeichnis anlegen ====== cd /var/www/html/ id -Z ls -dZ . matchpathcon . -> Type: ''httpd_sys_content_t'' Hello SELinux! Hello SELinux ls -Z test.html -> Type: ''httpd_sys_content_t'', Webserver kann darauf zugreifen ====== HTML Datei im Heimatverzeichnis anlegen ====== als root: cd id -Z ls -dZ . matchpathcon . -> Type: ''admin_home_t'' Hello SELinux! Hello SELinux ls -Z test.html -> Type: ''admin_home_t'' mv test.html /var/www/html -> Webserver kann //nicht// darauf zugreifen ((Security Context: //mv// verhält sich anders als //cp//. //mv// behält den Security Context der Quelle, während //cp// den Security Context des Ziels übernimmt.)) ===== SELinux file type korrigieren ===== ==== setroubleshootd ==== Wenn zum Zeitpunkt des Zugriffs setroubleshootd aktiviert ist, gibt es hier Hilfe: journalctl -f _COMM=setroubleshootd -> ''SELinux is preventing /usr/sbin/httpd from getattr access on the file /var/www/html/test.html'' ==== auditd ==== Wenn zum Zeitpunkt des Zugriffs der auditd läuft: ausearch -m avc -c httpd -> ''denied { getattr } … comm="httpd" path="/var/www/html/test.html" … tcontext=…admin_home_t'' ==== chcon ==== chcon -t httpd_sys_content_t /var/www/html/test.html oder chcon --reference /var/www/html /var/www/html/test.html ((Change Security Context: Bei dem Befehl //chcon// handelt es sich um eine temporäre Lösung, die durch ein Relabling des Filesystem überschrieben wird. Eine dauerhafte Lösung wird mit Hilfe von //semanage// erzielt.)) ==== restorecon ==== restorecon /var/www/html/test.html ====== HTML Datei außerhalb des DocumentRoot anlegen ====== Alias /srv /srv/test Require all granted apachectl graceful mkdir -p /srv/test ls -dZ /srv/test/ -> Type: ''var_t'' chcon --reference /var/www/html /srv/test ls -dZ /srv/test/ -> Type: ''httpd_sys_content_t'' matchpathcon /srv/test/ -> Type: ''var_t'' (**Achtung!**) Hello SELinux! Hello SELinux ls -Z /srv/test/test.html -> Type: ''var_t'', Webserver kann **nicht** darauf zugreifen chcon --reference /var/www/html /srv/test/test.html ls -Z /srv/test/test.html -> Type: ''httpd_sys_content_t'', Webserver kann darauf zugreifen restorecon -RF /srv/test/ ls -Z /srv/test/test.html -> Type: ''var_t'', Webserver kann **nicht** darauf zugreifen semanage fcontext --add -t httpd_sys_content_t '/srv/test(/.*)?' restorecon -RF /srv/test/ -> Type: ''httpd_sys_content_t'', Webserver kann darauf zugreifen