Hier werden die Unterschiede zwischen zwei Versionen gezeigt.
Nächste Überarbeitung | Vorherige Überarbeitung | ||
admin_grundlagen:selinux_-_webserver_inhalte_freigeben [2018/11/12 21:33] ingo_wichmann angelegt |
admin_grundlagen:selinux_-_webserver_inhalte_freigeben [2019/08/14 09:03] (aktuell) dhoppe |
||
---|---|---|---|
Zeile 2: | Zeile 2: | ||
* [[lpi2:apache|Apache httpd]] installiert | * [[lpi2:apache|Apache httpd]] installiert | ||
+ | ====== HTML Datei im Zielverzeichnis anlegen ====== | ||
+ | cd /var/www/html/ | ||
+ | id -Z | ||
+ | ls -dZ . | ||
+ | matchpathcon . | ||
+ | -> Type: ''httpd_sys_content_t'' | ||
+ | |||
+ | <file html test.html> | ||
+ | <html> | ||
+ | <head> | ||
+ | <title>Hello SELinux!</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | Hello SELinux | ||
+ | </body> | ||
+ | </html> | ||
+ | </file> | ||
+ | |||
+ | 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'' | ||
+ | |||
+ | <file html test.html> | ||
+ | <html> | ||
+ | <head> | ||
+ | <title>Hello SELinux!</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | Hello SELinux | ||
+ | </body> | ||
+ | </html> | ||
+ | </file> | ||
+ | |||
+ | 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 ====== | ||
+ | <file txt /etc/httpd/conf.d/srv.conf> | ||
+ | Alias /srv /srv/test | ||
+ | |||
+ | <Directory /srv/test> | ||
+ | Require all granted | ||
+ | </Directory> | ||
+ | </file> | ||
+ | |||
+ | 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!**) | ||
+ | |||
+ | <file html test.html> | ||
+ | <html> | ||
+ | <head> | ||
+ | <title>Hello SELinux!</title> | ||
+ | </head> | ||
+ | <body> | ||
+ | Hello SELinux | ||
+ | </body> | ||
+ | </html> | ||
+ | </file> | ||
+ | |||
+ | 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 |