Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


admin_grundlagen:selinux_-_webserver_inhalte_freigeben

Voraussetzungen

HTML Datei im Zielverzeichnis anlegen

cd /var/www/html/
id -Z
ls -dZ .
matchpathcon .

→ Type: httpd_sys_content_t

test.html
<html>
  <head>
    <title>Hello SELinux!</title>
  </head>
  <body>
    Hello SELinux
  </body>
</html>
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

test.html
<html>
  <head>
    <title>Hello SELinux!</title>
  </head>
  <body>
    Hello SELinux
  </body>
</html>
ls -Z test.html

→ Type: admin_home_t

mv test.html /var/www/html

→ Webserver kann nicht darauf zugreifen 1)

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

2)

restorecon

restorecon /var/www/html/test.html

HTML Datei außerhalb des DocumentRoot anlegen

/etc/httpd/conf.d/srv.conf
Alias /srv /srv/test
 
<Directory /srv/test>
  Require all granted
</Directory>
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!)

test.html
<html>
  <head>
    <title>Hello SELinux!</title>
  </head>
  <body>
    Hello SELinux
  </body>
</html>
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

1)
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.
2)
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.
admin_grundlagen/selinux_-_webserver_inhalte_freigeben.txt · Zuletzt geändert: 2019/08/14 09:03 von dhoppe