Abstract
Playing about with Django’s excellent admin interface this morning I came across a little problem that I am sure others will find if using Django in an SELinux environment. This concerns the ability to upload files to a server – in my case using Apache, mod_wsgi (not in daemon mode), and Fedora 10 with SELinux running.
Method
I was getting a [Errno 13] Permission denied error when trying to upload a file – pretty obvious that the server wasn’t happy about something there then. First of all I decided to check and see which user Apache was running – a convenient way to do this is to use the top command. Once in there, type u followed by apache (the apache process owner in my case) and this exposes only running processes by apache.
top - 12:33:00 up 24 min, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 93 total, 1 running, 92 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 254128k total, 139884k used, 114244k free, 5536k buffers Swap: 524280k total, 0k used, 524280k free, 51376k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1870 apache 20 0 38604 16m 4664 S 0.0 6.6 0:00.53 httpd ...
That was fine then – next to check the directory I was trying to upload files to:
[user@lapwing media]$ ls -l drwxr--r-- 2 apache apache 4096 2009-05-22 12:16 images
Also looked ok – one last thing to check…
SELinux…
Yes, the old SELinux chestnut again… I solved this by changing the directory SELinux context:
[root@lapwing media]# chcon -t tmp_t images
Then check
[root@lapwing media]# ls -dZ images/ drwxr--r-- apache apache system_u:object_r:tmp_t:s0 images/
Tried the upload again – this time it worked.
No Comments on “Writing Files with Django Under SELinux”
You can track this conversation through its atom feed.