So I have a web application running on Centos 6.5.

The application is a Ruby/Rails app, but the images are served by Apache HTTPD.

The application folder is in a user home folder, but I've granted HTTPD the correct permissions, and have enabled httpd\_enable\_home\_dirs within SELinux. All static images are working just fine.

The problem I am seeing is when an end user uploads an image (A profile icon), the SELinux context for the file is getting set to unconfined\_u:object\_r:user\_tmp\_t:s0 instead of unconfined\_u:object\_r:usr\_t:s0.

If I manually run restorcon on the file, the context gets fixed, and the image works. Any idea how I can make sure the file gets created with the correct context? I've looked into using restorcond, but it looks like it won't recursively check subdirectories, and the subdirectory structure is not predictable.

Any help is appreciated.