How to allow WordPress to upload images on an SELinux enabled server
I recently had to put up a blog running the WordPress system. There are a lot of things I like about WordPress and in general the difficulty in getting the site up and running was low.
The problem came about when an image was needed on the site. The software gave me the infamous “Is its parent directory writable by the server” message. After confirming the permissions where correct I began to dig deeper. It turned out that SELinux was causing an access denied message.
After much research on the matter, I learned a few things. First, most people simply turn off (example, example, example) SELinux. That was not an option for me. I want the extra contextual security provided. Second, it was not a WordPress problem, or even an SELinux problem. In reality, it’s simply a configuration setting put in place to make unauthorized uploads less likely.
It turns out that the security policy will only allow the httpd service to upload to the /tmp directory. Examination of that directory shows that the context includes tmp_t. That is the ticket that got things working for me. Here’s my solution to this issue:
- Change directory to the wp-content directory of the WordPress software.
- Made the uploads folder manually.
mkdir uploads - Changed the owner of uploads to the appropriate user that apache runs as (as root).
chown httpuser:httpuser uploads - Changed permissions to allow the apache user to write to the directory (as root).
chmod 755 uploads - Changed the SE context of the directory to allow httpd to upload file (as root).
chcon -t tmp_t uploads
That did it. Not terribly difficult, but there is not a lot of concise documentation to be found when looking for this problem. It is very possible that there is a better way to accomplish these results, and if you know that it is please let me know! I can say that my configuration is working today and, at least so far, everything seems to be working fine and as secure as it can be.
The final output of ls -Z for the uploads directory should look something like this:
drwxr-xr-x httpd httpd root:object_r:tmp_t uploads
Cheers.
Share this:
Like this:
January 24, 2008 - Posted by palehorse | Blogging, Linux, Operating Systems
3 Comments »
Leave a Reply Cancel reply
Pale Tweets
- I just unlocked the “Flame Broiled” badge on @foursquare! Cheeseburgers all around! http://t.co/a8qihs58 3 days ago
- I just ousted Doug S. as the mayor of Excel Fitness on @foursquare! http://t.co/LzAXKJUx 2 weeks ago
- I just ousted @passi0n as the mayor of Timbers on @foursquare! http://t.co/MGG1KhxA 1 month ago
The Cloud
Archives
Pale’s Social Graph
Google Reader Shared Stuff- Microsoft releases Bing app for Android, iOS, not Windows Phone 7
- Google Tweaks Algorithm As Concern Over Bing Grows
- First Android Device Certified For DoD Personnel
- Stupid Router Tricks (or how to use DD-WRT to extend the range of a network)
- Steve Jobs Biography Reveals Reflections On Apple, Contempt For Android
- Galaxy Nexus signup page includes seven US carriers, endless speculation
- I swear to God this is what they must be doing
- Google Promises Android 4.0 For The Nexus S, “Theoretically” For Gingerbread Devices, Too
- Mac Trojan Disables XProtect Updates
- HTML 5 and CSS: Six complete lessons, free for students, faculty, you and me too!
Pale Tweets
- I just unlocked the “Flame Broiled” badge on @foursquare! Cheeseburgers all around! http://t.co/a8qihs58 3 days ago
- I just ousted Doug S. as the mayor of Excel Fitness on @foursquare! http://t.co/LzAXKJUx 2 weeks ago
- I just ousted @passi0n as the mayor of Timbers on @foursquare! http://t.co/MGG1KhxA 1 month ago
Blogroll
You can try chcon -t httpd_tmp_t uploads
SELinux is all about labelling. There is a label on every process and a label on every file/directory. Then there are rules governing the access between the process label and the file/directory label.
If SELinux is complaining, it is usually an issue with labeling.
man httpd_selinux
Gives a good explanation on setting up labelling for apache in SELinux.
http://docs.fedoraproject.org/selinux-managing-confined-services-guide/en-US/F11/html/
This guide also explains setting up different services.
Nice link to the guide Dan, thank you!