2017-04-05 60 views
0

我需要允許使用CentOS目標SELinux策略連接到Unix域套接字。允許nginx使用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 

我該如何解決這個問題?

回答

0

解決:我必須修復綁定到Unix流文件的套接字的上下文。它的權限是從創建它的進程(偵聽器)繼承的,因此允許連接進程連接到偵聽器的上下文。

例如,如果你的聽衆是listner_t運行和連接過程是connector_t

allow connector_t listener_t: unix_stream_socket connectto; 

在我的情況,聽者在init_t運行,但允許nginx的聽任何過程中init_t是太多了。我爲偵聽器創建了一個新的上下文,並允許nginx使用上下文連接到進程。