wsgi脚本的环境被隔离在httpd,CentOS 7上

我正在使用mod_wsgiCentOS 7上托pipe一个简单的wsgi应用程序 ,并尝试删除下面所示的隔离。

wsgi应用程序,

以下脚本是我的wsgi应用程序。

  • 它会创build一个名为/tmp/test-wsgi.txt的文件
  • 枚举/tmp的内容作为一个简单的json列表

码:

 def application(environ, start_response): status = '200 OK' headers = [('Content-Type', 'application/json')] start_response(status, headers) with open('/tmp/test-wsgi.txt', 'w+') as w: w.write('hello world') files = os.listdir('/tmp') return json.dumps(files) 

当我访问我的Web应用程序时,我收到以下回复

 ["test-wsgi.txt"] 

太好了!


然而,

以root身份连接到相同的主机服务器,

我打开了一个shell并执行cat /tmp/test-wsgi.txt

在这里输入图像说明

从玩弄它,似乎在我的wsgi脚本内的任何文件系统操作(枚举/创build/套接字访问)是“环境隔离” (如chroot监狱)。 奇怪的是我没有configuration任何types的隔离。


httpdconfiguration

/etc/httpd/conf.d/my-app.conf

 <VirtualHost *:80> DocumentRoot /opt/my-app/ WSGIScriptAlias / /opt/my-app/apache/wsgi.py <Directory /opt/my-app/apache> Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> 

/etc/httpd/conf/httpd.conf中

 ... User apache Group apache ... 

安全function, PrivateTmp

这是一个名为PrivateTmp的安全function,默认情况下使用httpd systemd服务进行configuration。

如何禁用它?

编辑/usr/lib/systemd/system/httpd.service删除以下行:

 PrivateTmp=true 

然后运行以下命令,

 sudo systemctl daemon-reload sudo service httpd restart