Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1897517 - php-fpm can't write into redis' socket
Summary: php-fpm can't write into redis' socket
Keywords:
Status: NEW
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: selinux-policy
Version: 8.2
Hardware: All
OS: Linux
low
low
Target Milestone: rc
: 8.0
Assignee: Zdenek Pytela
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-11-13 10:08 UTC by Rik Theys
Modified: 2023-04-16 08:28 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1178210
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1875138 0 medium CLOSED php-fpm can't write into redis' socket (Fedora) 2022-05-16 11:32:56 UTC

Description Rik Theys 2020-11-13 10:08:58 UTC
+++ This bug was initially created as a clone of Bug #1178210 +++

Sorry to publish this here, but I couldn't find where to post a bug for EPEL packages.

Description of problem:
php-fpm can't write/read to/from the redis socket

Version-Release number of selected component (if applicable):
selinux-policy-3.7.19-260.el6_6.1.noarch

How reproducible:
First, configure redis to use a socket at /var/run/redis/redis.sock (where the PID is by default).

then, try to use redis from php:

<?php

ini_set( 'display_errors', 'On' );
$redis = new Redis();

$redis->pconnect( '/var/run/redis/redis.sock' );

echo 'sending ping... ';
echo $redis->ping() . "\n";

echo 'setting name ... ' . "\n";
$redis->set( 'Name', 'Renich Bon Ciric' );

echo 'getting name. The name is: ';
echo $redis->get( 'Name' ) . "\n";

?>


Actual results:
[root@web1 public]# ausearch -i -sv no -ts recent 
----
type=SYSCALL msg=audit(01/02/2015 15:33:08.834:23071) : arch=x86_64 syscall=connect success=no exit=-13(Permission denied) a0=0x5 a1=0x7ffffc01ce60 a2=0x1b a3=0x1f3d1a0 items=0 ppid=21091 pid=21103 auid=root uid=apache gid=apache euid=apache suid=apache fsuid=apache egid=apache sgid=apache fsgid=apache tty=(none) ses=3433 comm=php-fpm exe=/usr/sbin/php-fpm subj=unconfined_u:system_r:httpd_t:s0 key=(null) 
type=AVC msg=audit(01/02/2015 15:33:08.834:23071) : avc:  denied  { write } for  pid=21103 comm=php-fpm name=redis.sock dev=dm-2 ino=1701412 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_run_t:s0 tclass=sock_file 
----
type=SYSCALL msg=audit(01/02/2015 15:33:08.833:23070) : arch=x86_64 syscall=connect success=no exit=-13(Permission denied) a0=0x5 a1=0x7ffffc01abc0 a2=0x1b a3=0x1f43840 items=0 ppid=21091 pid=21103 auid=root uid=apache gid=apache euid=apache suid=apache fsuid=apache egid=apache sgid=apache fsgid=apache tty=(none) ses=3433 comm=php-fpm exe=/usr/sbin/php-fpm subj=unconfined_u:system_r:httpd_t:s0 key=(null) 
type=AVC msg=audit(01/02/2015 15:33:08.833:23070) : avc:  denied  { write } for  pid=21103 comm=php-fpm name=redis.sock dev=dm-2 ino=1701412 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_run_t:s0 tclass=sock_file 
[root@web1 public]# ausearch -i -sv no -ts recent | audit2allow


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


Expected results:
It should write and read the var.

--- Additional comment from Daniel Walsh on 2015-01-03 17:44:05 CET ---

Looks like we would need to back port redis policy to make this work.

For now you could add a custom policy module.

--- Additional comment from Renich Bon Ciric on 2015-01-04 20:49:45 CET ---

(In reply to Daniel Walsh from comment #1)
> Looks like we would need to back port redis policy to make this work.
> 
> For now you could add a custom policy module.

Ok, I will.

--- Additional comment from Miroslav Grepl on 2015-04-14 11:05:59 CEST ---

commit cf60c35e07d2e430a4061ab30c6c40a49bfb5704
Author: Miroslav Grepl <mgrepl>
Date:   Tue Apr 14 11:05:24 2015 +0200

    Allow redis to create /var/run/redis/redis.sock.

--- Additional comment from Miroslav Grepl on 2015-06-03 13:20:51 CEST ---

commit a8cc60eeb13cf7f9a636261a26455afbaeacd75e
Author: Miroslav Grepl <mgrepl>
Date:   Wed Jun 3 13:20:00 2015 +0200

    Allow php-fpm write access to /var/run/redis/redis.sock

--- Additional comment from errata-xmlrpc on 2015-07-22 09:10:24 CEST ---

Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-1375.html

--- Additional comment from Angelo Lisco on 2019-10-04 22:13:21 CEST ---

It seems that the patch was lost somewhere around the git repository...

On a rhel7 it was working fine because of the following policy rule:

sesearch -A -s httpd_t -t redis_var_run_t -c sock_file -p write ; echo $?
# Found 1 semantic av rules:
   allow domain pidfile : sock_file { write getattr append open } ; 
0

but I don't have any output querying the selinux target policy on a rhel8 with the following command:
# sesearch -A -s httpd_t -t redis_var_run_t -c sock_file -p write ; echo $?
0

Do I have to open a new bugzilla report?

--- Additional comment from Lukas Vrabec on 2019-10-07 09:04:16 CEST ---

Hi Angelo, 

This is RHEL-6 bugzilla, could you please open ticket for RHEL-8 with your issue? 

Thanks,
Lukas.

Comment 1 Milos Malik 2020-11-20 09:11:56 UTC
The /var/run/redis/redis.sock is mislabeled. Please run the following command which fixes the label:

# restorecon -Rv /var/run/redis

Comment 2 Rik Theys 2020-11-20 11:39:52 UTC
Hi,

The redis socket does seem to have the correct selinux label:

[root@XXX redis]# restorecon -Rvn /var/run/redis
[root@XXX redis]# ls -lZ /var/run/redis/
total 0
srwxrwxrwx. 1 redis redis system_u:object_r:redis_var_run_t:s0 0 Nov 13 11:18 redis.sock

[root@XXX log]# ausearch -m avc |grep -i redis
type=AVC msg=audit(1605261575.507:1755): avc:  denied  { write } for  pid=175150 comm="php-fpm" name="redis.sock" dev="tmpfs" ino=4726705 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:redis_var_run_t:s0 tclass=sock_file permissive=0

What is the label this socket should have?

I've currently created the following selinux module to allow this:

module esat_redis 1.0;

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

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


Regards,
Rik

Comment 3 Milos Malik 2020-11-20 12:33:20 UTC
The redis_var_run_t label is correct for the socket and the policy module you created is correct too.

# rpm -qa selinux\*
selinux-policy-targeted-3.14.3-54.el8.noarch
selinux-policy-3.14.3-54.el8.noarch
# sesearch -s httpd_t -t redis_var_run_t -c sock_file -p write -A --dontaudit
#

Unfortunately, SELinux policy in RHEL-8.3 does not allow that access. Candidate for fixing in RHEL-8.4?


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