首页 文章

允许nginx连接到具有CentOS目标SELinux策略的Unix域套接字

提问于
浏览
0

我需要允许连接到具有CentOS目标SELinux策略的Unix域套接字 .

我想出了以下模块:

module httpd_unix 0.0.0;

require {
        attribute file_type;
        class unix_stream_socket connectto;
        class sock_file write;
        type httpd_t;
}

type httpd_unix_t;
typeattribute httpd_unix_t file_type;
allow httpd_t httpd_unix_t: unix_stream_socket connectto;
allow httpd_t httpd_unix_t: sock_file write;

但审计说:

type=AVC msg=audit(1491380970.041:396): avc:  denied  { connectto } for  pid=985 comm="nginx" path="/run/tsubonesystem3/tsubonesystem3.sock" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:init_t:s0 tclass=unix_stream_socket

当然,上下文设置为文件 .

$ sudo ls -Z /var/run/tsubonesystem3/tsubonesystem3.sock
srw-rw----. tsubonesystem tsubonesystem system_u:object_r:httpd_unix_t:s0 /var/run/tsubonesystem3/tsubonesystem3.sock

我该如何解决这个问题?

1 回答

  • 0

    解决:我必须修复绑定到Unix流文件的套接字的上下文 . 它的权限是从创建它的进程(侦听器)继承的,因此允许连接进程连接到侦听器的上下文 .

    例如,如果您的侦听器在 listner_t 中运行且连接过程在 connector_t 中:

    allow connector_t listener_t: unix_stream_socket connectto;
    

    在我的情况下,监听器在 init_t 中运行,但允许nginx监听 init_t 中的任何进程太多了 . 我为侦听器创建了一个新的上下文,并允许nginx使用上下文连接到进程 .

相关问题