Changing context in SELinux

Recently I was working on a Drupal installation in a server running CentOS which is a Linux distribution built from the sources provided by Red Hat of their Red Hat Enterprise Linux product, and I was running into a very frustrating problem: somehow Drupal couldn’t see any of the newly installed modules that I had dropped into the /all/modules/ directory. I tried moving them around, changing permissions, changing ownership, but nothing would work.

After a few really frustrating days of working on this and almost giving up I finally figured out the culprit: SELinux.

SELinux is a security framework that provides extra mechanisms such as access control policies, that protect the system beyond regular permissions. One of these access control policies is context. So while I was changing permissions and ownership of files, the context of the files I had dropped in the www/ directory was still user_home_t when it should really be httpd_sys_content_t in order for Apache to be able to access these files. So how did I solve this you ask? A simple command:

$ sudo chcon -R -h -t httpd_sys_content_t www/

This will recursively apply the access policy to everything under the web root directory. By the way, if you need to see what context your files and directories are in you can do this with the ls command:

$ ls -lZ

This will give you a listing of all the permissions and context of the files in the directory.

So according to Wikipedia, SELinux was developed by the National Security Agency and then open-sourced to the community. So next time you find yourself frustrated by all the nice “features” that this framework provides you know who to thank.

Tagged , , ,

One thought on “Changing context in SELinux

  1. [...] Changing context in SELinux (ederscubicle.wordpress.com) [...]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.