Bug 981848 - SELinux is preventing /usr/sbin/nginx from 'write' accesses on the sock_file btcsrv.sn.g02.org.sock.
Summary: SELinux is preventing /usr/sbin/nginx from 'write' accesses on the sock_file ...
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: 19
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Miroslav Grepl
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: abrt_hash:a8df0e27b767ebd5c895ccac614...
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-07-06 09:41 UTC by Renich Bon Ciric
Modified: 2015-02-18 13:58 UTC (History)
3 users (show)

Fixed In Version: selinux-policy-3.12.1-65.fc19
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-02-18 13:58:39 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Renich Bon Ciric 2013-07-06 09:41:37 UTC
Description of problem:
Same problem as in F18. Bugfix already applied but happened again.
SELinux is preventing /usr/sbin/nginx from 'write' accesses on the sock_file btcsrv.sn.g02.org.sock.

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

If you believe that nginx should be allowed write access on the btcsrv.sn.g02.org.sock sock_file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
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                system_u:object_r:var_run_t:s0
Target Objects                btcsrv.sn.g02.org.sock [ sock_file ]
Source                        nginx
Source Path                   /usr/sbin/nginx
Port                          <Unknown>
Host                          (removed)
Source RPM Packages           nginx-1.4.1-1.fc19.x86_64
Target RPM Packages           
Policy RPM                    selinux-policy-3.12.1-57.fc19.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     (removed)
Platform                      Linux (removed) 3.9.8-300.fc19.x86_64 #1 SMP Thu
                              Jun 27 19:24:23 UTC 2013 x86_64 x86_64
Alert Count                   6
First Seen                    2013-07-06 04:40:30 CDT
Last Seen                     2013-07-06 04:40:33 CDT
Local ID                      ee79fb45-6556-45e5-8009-e4d8b2d63213

Raw Audit Messages
type=AVC msg=audit(1373103633.491:1719): avc:  denied  { write } for  pid=26894 comm="nginx" name="btcsrv.sn.g02.org.sock" dev="tmpfs" ino=10957578 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=sock_file


type=SYSCALL msg=audit(1373103633.491:1719): arch=x86_64 syscall=connect success=no exit=EACCES a0=c a1=7fbc4e1a8e30 a2=6e a3=7fffc18f1210 items=0 ppid=26893 pid=26894 auid=4294967295 uid=996 gid=996 euid=996 suid=996 fsuid=996 egid=996 sgid=996 fsgid=996 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

Additional info:
reporter:       libreport-2.1.5
hashmarkername: setroubleshoot
kernel:         3.9.8-300.fc19.x86_64
type:           libreport

Potential duplicate: bug 967764

Comment 1 Daniel Walsh 2013-07-10 23:12:53 UTC
fce11d3fa690af8e040f9de82430d272cdc880f3 has additional fixes for this in git.

The problem you have is the /var/run/thin directory is not labeled correctly

Comment 2 Fedora Update System 2013-07-17 11:53:23 UTC
selinux-policy-3.12.1-65.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/selinux-policy-3.12.1-65.fc19

Comment 3 Fedora Update System 2013-07-18 06:01:46 UTC
Package selinux-policy-3.12.1-65.fc19:
* should fix your issue,
* was pushed to the Fedora 19 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.12.1-65.fc19'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2013-13172/selinux-policy-3.12.1-65.fc19
then log in and leave karma (feedback).

Comment 4 Renich Bon Ciric 2013-07-18 13:09:51 UTC
(In reply to Fedora Update System from comment #3)
> Package selinux-policy-3.12.1-65.fc19:
> * should fix your issue,
> * was pushed to the Fedora 19 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.12.1-65.fc19'
> as soon as you are able to.
> Please go to the following url:
> https://admin.fedoraproject.org/updates/FEDORA-2013-13172/selinux-policy-3.
> 12.1-65.fc19
> then log in and leave karma (feedback).

Still have the problem:

Still have the problem.

type=AVC msg=audit(1374152922.172:1360): avc:  denied  { connectto } for  pid=18413 comm="nginx" path="/run/thin/www.evalinux.com.sock" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:initrc_t:s0 tclass=unix_stream_socket
type=SYSCALL msg=audit(1374152922.172:1360): arch=c000003e syscall=42 success=no exit=-13 a0=d a1=7fe0768b5a10 a2=6e a3=7fff5f8bb940 items=0 ppid=18412 pid=18413 auid=4294967295 uid=996 gid=996 euid=996 suid=996 fsuid=996 egid=996 sgid=996 fsgid=996 ses=4294967295 tty=(none) comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)

Comment 5 Fedora Update System 2013-07-20 09:33:33 UTC
selinux-policy-3.12.1-65.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 6 Miroslav Grepl 2013-07-29 10:43:51 UTC
What does

# ps -efZ |grep initrc

Comment 7 Renich Bon Ciric 2013-08-01 06:31:10 UTC
(In reply to Miroslav Grepl from comment #6)
> What does
> 
> # ps -efZ |grep initrc

# ps -efZ |grep initrc
system_u:system_r:initrc_t:s0   redis      503     1  0 Jul31 ?        00:01:08 /usr/sbin/redis-server /etc/redis.conf
system_u:system_r:initrc_t:s0   root     12699     1  0 00:33 ?        00:00:02 /usr/bin/ruby-mri /usr/local/bin/thin -C /srv/www/sinatra/btcsrv.com/default/config/thin.yml start
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 root 17961 17922  0 01:30 pts/0 00:00:00 grep --color=auto initrc

Comment 8 Miroslav Grepl 2013-08-02 13:08:33 UTC
We need a policy for /usr/sbin/redis-server.

Comment 9 Miroslav Grepl 2013-08-02 13:14:07 UTC
Also

system_u:system_r:initrc_t:s0   root     12699     1  0 00:33 ?        00:00:02 /usr/bin/ruby-mri /usr/local/bin/thin -C /srv/www/sinatra/btcsrv.com/default/config/thin.yml start

is it your own thin instance?

Comment 10 Renich Bon Ciric 2013-08-02 16:45:30 UTC
(In reply to Miroslav Grepl from comment #9)
> Also
> 
> system_u:system_r:initrc_t:s0   root     12699     1  0 00:33 ?       
> 00:00:02 /usr/bin/ruby-mri /usr/local/bin/thin -C
> /srv/www/sinatra/btcsrv.com/default/config/thin.yml start
> 
> is it your own thin instance?

Yep, it is.

Any thin instance will generate a socket file. Maybe keeping it with a .sock extension would be convenient for SELinux so it could label those as something?

Also, redis uses sockets.

I think we solved it with: 

[root@web1 selinux]# cat mynginxsockwrite.te

module mynginxsockwrite 1.0;

require {
	type var_run_t;
	type httpd_t;
	class sock_file write;
}

#============= httpd_t ==============
allow httpd_t var_run_t:sock_file write;
[root@web1 selinux]# cat mythin.te 
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)
apache_read_sys_content(thin_t)
gen_require(` type httpd_t; ')
stream_connect_pattern(httpd_t, thin_var_run_t, thin_var_run_t, thin_t)

Comment 11 Miroslav Grepl 2013-08-05 05:35:52 UTC
We have these rules. 

$ rpm -q selinux-policy


Basically we would need to get a script which starts this thin instance. See

http://mgrepl.wordpress.com/2012/11/30/how-would-tools-like-paster-work-with-selinux-thin-story/

Then we could have a policy with

thin_btcsrv_t

domain type.

Comment 12 Fedora End Of Life 2015-01-09 22:11:04 UTC
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 13 Fedora End Of Life 2015-02-18 13:58:39 UTC
Fedora 19 changed to end-of-life (EOL) status on 2015-01-06. Fedora 19 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


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