22 SELinux Apache DocumentRoot Directory audit.log AVC | source/target context | semanage-fcontext | restorecon

[root@localhost tmp]# mkdir /web && cd /web
[root@localhost web]# pwd
/web
[root@localhost web]# touch index.html
[root@localhost web]# vim index.html

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#

#DocumentRoot "/var/www/html"
DocumentRoot "/web"
#
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
<Directory "/web">
    AllowOverride None
    Require all granted
</Directory>


#<Directory "/var/www/html">
<Directory "/web>

==========================
after change directory to /web , new index.html page doesn't open
==========================
[root@localhost ~]# grep -i avc /var/log/audit/audit.log 

type=AVC msg=audit(1506190824.005:780): avc:  denied  { read } for  pid=13135 comm="httpd" name="index.html" dev="dm-0" ino=70280759 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file
type=AVC msg=audit(1506190824.005:780): avc:  denied  { open } for  pid=13135 comm="httpd" path="/web/index.html" dev="dm-0" ino=70280759 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file

source context - httpd_t
target context - default_t
=========================
man semanage 
man semanage-fcontext

Add file-context for everything under /web
       # semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
       # restorecon -R -v /web

=========================
when you copy file, it changes context according to new location
after copying/removing and copying back file to restore it run
restorecon -v /etc/vconsole.conf


[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
[root@localhost ~]# restorecon -R -v /web
restorecon reset /web context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /web/index.html context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
[root@localhost ~]# 
=========================
!el
shows index.html 
========================


Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all