Previous Entry Share Next Entry
File Context problems.
If you want to move files to directories that the current policy does not know about you should use the semanage command to tell the system what to label these files.

# semanage fcontext -a -t httpd_sys_script_exec_t '/myweb/cgi(/.*)?'
# restorecon -R -v /myweb/cgi

Semanage is a good tool for this, since it sets up the machine to permanently label these directories with this context.  If the machine is later relabeled, this directory will continue to be labeled correctly.    system-config-selinux also has a graphical mechanism to do this.

  This is preferred over using chcon, since chcon  might not survive a relabel.

If you do this labeling and the policy is updated later on with the same or slightly different context, you can have problems.  I have also seen packages shipping with semanage commands in their post install to set the file context.

You can end up seeing statements like:

/etc/selinux/targeted/contexts/files/file_contexts: Multiple 
different specifications for /var/lib/awstats(/.*)?
(system_u:object_r:httpd_sys_script_rw_t:s0 and
/etc/selinux/targeted/contexts/files/file_contexts: Multiple
different specifications for /usr/share/awstats/wwwroot/cgi-
bin(/.*)? (system_u:object_r:httpd_sys_script_exec_t:s0 and
When restorecon, rpm, matchpathcon, setfiles or any other tools that reads the systems file context sees a conflict they put out this message.

You can remove the conflict by using semange

# semanage fcontext -d '/var/lib/awstats(/.*)?'

One handy qualifier available at least in semanage on Fedora 9

# semanage fcontext -l -C
SELinux fcontext                                   type               Context

/etc/glpi(/.*)?                                    all files          system_u:object_r:httpd_sys_script_rw_t:s0
/var/log/glpi(/.*)?                                all files          system_u:object_r:httpd_sys_script_rw_t:s0
/var/lib/glpi(/.*)?                                all files          system_u:object_r:httpd_sys_script_rw_t:s0
/dev/mapper/Volumes-OldWindowsBackup               all files          system_u:object_r:virt_image_t:s0

This command lists all the local customizations that have been made to your system.  This shows that on my system the glpi program must have setup special labeling and I labeled an virtual image in /dev/mapper.

You can see similar functionality in system-config-selinux by selecting the "File Labeling" list item and then clicking on the "Customized" button.

PSAD SELinux file context


2008-12-20 10:50 pm (UTC)

Just wondering if there is a better way to accomplish what I did after installing PSAD on Fedora 9. There are two files that /sbin/iptables needs to write to:


It was denied because the files were var_log_t. So I changed the file context with:

semanage fcontext -a -t iptables_t "/var/log/psad/psad.ipterr"
semanage fcontext -a -t iptables_t "/var/log/psad/psad.iptout"
restorecon -v /var/log/psad/psad.ipterr
restorecon -v /var/log/psad/psad.iptout

Now everything is good with PSAD and no AVC denied messages in /var/log/messages. Like you mentioned in the original post, I could get into trouble if the context ever changed.

Also is it acceptable to have those files in /var/log with the context system_u:object_r:iptables_t:s0?


No HTML allowed in subject


(will be screened)


Log in