Bug 967764 - SELinux is preventing /usr/sbin/nginx from 'write' accesses on the sock_file btcsrv.sock.
Summary: SELinux is preventing /usr/sbin/nginx from 'write' accesses on the sock_file ...
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 18
Hardware: x86_64
OS: Unspecified
Target Milestone: ---
Assignee: Miroslav Grepl
QA Contact: Fedora Extras Quality Assurance
Whiteboard: abrt_hash:a8df0e27b767ebd5c895ccac614...
Depends On:
TreeView+ depends on / blocked
Reported: 2013-05-28 09:35 UTC by Renich Bon Ciric
Modified: 2013-07-25 00:37 UTC (History)
4 users (show)

Fixed In Version: selinux-policy-3.11.1-98.fc18
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2013-07-25 00:37:40 UTC
Type: ---

Attachments (Terms of Use)

Description Renich Bon Ciric 2013-05-28 09:35:32 UTC
Description of problem:
The other day, I was in #Fedora-SELinux solving this.

A very nice guy there came out with the following solution:

# cat mythin.te; echo; echo; cat mythin.fc 
policy_module(mythin, 1.0.0)
gen_require(` type thin_t, thin_var_run_t; ')
manage_sock_files_pattern(thin_t, thin_var_run_t, thin_var_run_t)
gen_require(` type httpd_t; ')
stream_connect_pattern(httpd_t, thin_var_run_t, thin_var_run_t, thin_t)

/var/run/thin(/.*)? gen_context(system_u:object_r:thin_var_run_t, s0)

I can confirm that this works; but I dunno if it's the best approach.

Usually, you will have your sinatra apps self contained; with certain configs there and all. 
SELinux is preventing /usr/sbin/nginx from 'write' accesses on the sock_file btcsrv.sock.

*****  Plugin catchall (100. confidence) suggests  ***************************

If you believe that nginx should be allowed write access on the btcsrv.sock sock_file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
allow this access for now by executing:
# grep nginx /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

Additional Information:
Source Context                system_u:system_r:httpd_t:s0
Target Context                unconfined_u:object_r:var_run_t:s0
Target Objects                btcsrv.sock [ sock_file ]
Source                        nginx
Source Path                   /usr/sbin/nginx
Port                          <Unknown>
Host                          (removed)
Source RPM Packages           nginx-1.2.9-1.fc18.x86_64
Target RPM Packages           
Policy RPM                    selinux-policy-3.11.1-96.fc18.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     (removed)
Platform                      Linux (removed) 3.9.3-201.fc18.x86_64 #1 SMP Tue
                              May 21 17:02:24 UTC 2013 x86_64 x86_64
Alert Count                   2
First Seen                    2013-05-28 04:32:04 CDT
Last Seen                     2013-05-28 04:32:04 CDT
Local ID                      48a17b07-ebfb-43ca-a011-86b1fdc74ee1

Raw Audit Messages
type=AVC msg=audit(1369733524.220:499): avc:  denied  { write } for  pid=21214 comm="nginx" name="btcsrv.sock" dev="tmpfs" ino=138342 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_run_t:s0 tclass=sock_file

type=SYSCALL msg=audit(1369733524.220:499): arch=x86_64 syscall=connect success=no exit=EACCES a0=b a1=7f04ff67c7e0 a2=6e a3=7fff1e5ec5f2 items=0 ppid=21213 pid=21214 auid=4294967295 uid=990 gid=986 euid=990 suid=990 fsuid=990 egid=986 sgid=986 fsgid=986 ses=4294967295 tty=(none) comm=nginx exe=/usr/sbin/nginx subj=system_u:system_r:httpd_t:s0 key=(null)

Hash: nginx,httpd_t,var_run_t,sock_file,write


#============= httpd_t ==============
allow httpd_t var_run_t:sock_file write;

audit2allow -R
require {
	type var_run_t;
	type httpd_t;
	class sock_file write;

#============= httpd_t ==============
allow httpd_t var_run_t:sock_file write;

Additional info:
reporter:       libreport-2.1.4
hashmarkername: setroubleshoot
kernel:         3.9.3-201.fc18.x86_64
type:           libreport

Comment 1 Miroslav Grepl 2013-05-29 09:07:06 UTC
What does 

# ps -efZ |grep thin

Comment 2 Renich Bon Ciric 2013-05-29 13:25:02 UTC
# ps -efZ |grep thin
system_u:system_r:thin_t:s0     renich     919     1 25 08:23 ?        00:00:01 /usr/bin/ruby /usr/local/bin/thin -C /etc/thin/junkets.evalinux.com.yml start
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 root 1051 952  0 08:23 pts/0 00:00:00 grep --color=auto thin

Comment 3 Renich Bon Ciric 2013-06-01 03:55:04 UTC
I can send you the app if you like. The way to reproduce is:

- create a /etc/tmpfs.d/thin.conf file so /run/thin gets created (systemd-tmpfs.d --create or something)
- put a socket (in my case, from thin) in /run/thin
- configure nginx to read/write it

If you need help, let me konw.

Comment 4 Miroslav Grepl 2013-06-04 12:55:30 UTC
I added fixes.

Comment 5 Fedora Update System 2013-06-27 13:33:37 UTC
selinux-policy-3.11.1-98.fc18 has been submitted as an update for Fedora 18.

Comment 6 Fedora Update System 2013-06-28 06:07:48 UTC
Package selinux-policy-3.11.1-98.fc18:
* should fix your issue,
* was pushed to the Fedora 18 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing selinux-policy-3.11.1-98.fc18'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).

Comment 7 Renich Bon Ciric 2013-07-17 20:01:50 UTC
Well, since it's 3.12.1-63 already, I can't install. Should I force the install?

Comment 8 Miroslav Grepl 2013-07-22 12:33:36 UTC
3.12.1-63 is for Fedora 19. This bug is about Fedora 18.

Comment 9 Fedora Update System 2013-07-25 00:37:40 UTC
selinux-policy-3.11.1-98.fc18 has been pushed to the Fedora 18 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.