简体   繁体   English

Apache代理+UNIX插座+SELINUX:怎么做的?

[英]Apache proxy + UNIX socket + SELINUX: How is it done?

I'm trying to get gunicorn running behind an Apache proxy via a UNIX socket in the file system.我试图通过文件系统中的 UNIX 套接字让 gunicorn 在 Apache 代理后面运行。 Long story short, it works with SELinux in non-enforcing mode but not when enforcing.长话短说,它在非强制模式下与 SELinux 一起工作,但在强制模式下却不行。 I'm trying to fix that.我正在努力解决这个问题。 Here's my socket file as created by gunicorn:这是我由 gunicorn 创建的套接字文件:

srwxrwxrwx. dh dh system_u:object_r:httpd_sys_content_t:s0 /var/www/wsgi/dham_wsgi.sock

Here's what audit2why has to say about this after a failed access via Apache:以下是 audit2why 在通过 Apache 访问失败后必须说的:

type=AVC msg=audit(1641287516.397:870181): avc:  denied  { connectto } for  pid=23897 comm="httpd" path="/var/www/wsgi/dham_wsgi.sock" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:init_t:s0 tclass=unix_stream_socket permissive=0
    
        Was caused by:
            Missing type enforcement (TE) allow rule.

            You can use audit2allow to generate a loadable module to allow this access.

Let's follow that hint, read some man pages and the Internet, and get to work:让我们按照这个提示,阅读一些手册页和 Internet,然后开始工作:

$ sudo cat /var/log/audit/audit.log | audit2allow -m httpd_socket -l > httpd_socket.te
$ cat httpd_socket.te

module httpd_socket 1.0;

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

#============= httpd_t ==============
allow httpd_t httpd_sys_content_t:sock_file write;
$ checkmodule -M -m -o httpd_socket.mod httpd_socket.te
checkmodule:  loading policy configuration from httpd_socket.te
checkmodule:  policy configuration loaded
checkmodule:  writing binary representation (version 19) to httpd_socket.mod
$ semodule_package -o httpd_socket.pp -m httpd_socket.mod
$ sudo semodule -i httpd_socket.pp

But it doesn't work, everything is as before.但它不起作用,一切都和以前一样。 Restarting Apache makes no difference.重新启动 Apache 没有区别。 What now?现在怎么办?

My initital audit2allow seems not to have caught all problems because I used the '-l' flag (last policy reload).我的初始 audit2allow 似乎没有发现所有问题,因为我使用了“-l”标志(上次策略重新加载)。 Using a more aggressive approach like below got me a few more entries in the generated module.使用如下更激进的方法让我在生成的模块中获得了更多条目。 After installing that, it worked.安装后,它工作。

sudo grep dham_wsgi /var/log/audit/audit.log | audit2allow -M httpd_socket

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM