以非root用户身份运行Gunicorn

时间:2019-10-17 09:57:47

标签: python docker gunicorn

我正在使用Gunicorn http服务器运行python应用程序。作为安全性加强的一部分,我们从根用户转移到运行该过程的专用用户。

Gunicorn是否使用了任何文件(PID / config / app文件除外)?我担心在不久的将来我们会遇到访问文件的权限问题

2 个答案:

答案 0 :(得分:1)

如果您真的很担心,可以使用strace启动gunicorn并查看其打开的内容。以非root用户身份运行是一种非常标准的配置,而gunicorn从概念上讲非常简单,因此,如果启动并运行一分钟,您可能会很好。

使用gunicorn时您需要担心的一些事情是心跳系统阻止了所有操作,并且线程不足导致负载均衡器查询无法获得响应。有关解决此问题的建议,请参见此处:https://pythonspeed.com/articles/gunicorn-in-docker/

答案 1 :(得分:0)

Gunicorn正在项目文件夹中创建临时文件:

  File "/home/**/.local/lib/python3.6/site-packages/gunicorn/pidfile.py", line 36, in create
    fd, fname = tempfile.mkstemp(dir=fdir)
  File "/usr/lib64/python3.6/tempfile.py", line 344, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "/usr/lib64/python3.6/tempfile.py", line 262, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
PermissionError: [Errno 13] Permission denied: '/src/tmpqg7t98e3'

因此拥有项目根文件夹以使其正常工作

相关问题