【问题标题】:Docker Nginx worker process runs as non-root user but still can access a file owned by rootDocker Nginx 工作进程以非 root 用户身份运行,但仍然可以访问 root 拥有的文件
【发布时间】:2019-03-23 20:36:14
【问题描述】:

我使用的是docker nginx官方镜像https://github.com/nginxinc/docker-nginx/blob/master/stable/alpine/Dockerfile。我像docker exec -it -v drupal:/var/www/drupal/web 一样运行它

web 是我的文档根目录。当我 cd 进入 /var/www/drupal/webls -al 时,我看到文件权限如下所示。一切都归 root 所有,而 nginx 工作进程nginx 非 root 用户所有。但是当去 localhost:80 我可以访问我的网站。这怎么可能 ? nginx用户如何访问root拥有的文件?有什么安全问题吗?

-rw-r--r--    1 root     root          1025 Oct 18 23:39 .csslintrc
-rw-r--r--    1 root     root           357 Oct 18 23:39 .editorconfig
-rw-r--r--    1 root     root           151 Oct 18 23:39 .eslintignore
-rw-r--r--    1 root     root            41 Oct 18 23:39 .eslintrc.json
-rw-r--r--    1 root     root          3858 Oct 18 23:39 .gitattributes
-rw-r--r--    1 root     root          2314 Oct 18 23:39 .ht.router.php
-rw-r--r--    1 root     root          7866 Oct 18 23:39 .htaccess
-rw-rw-rw-    1 root     root           385 Oct 18 23:39 autoload.php
drwxr-xr-x   44 root     root          1408 Oct 18 23:38 core
-rw-r--r--    1 root     root           549 Oct 18 23:39 index.php
drwxr-xr-x    3 root     root            96 Oct 18 23:39 modules
drwxr-xr-x    3 root     root            96 Oct 18 23:39 profiles
-rw-r--r--    1 root     root          1594 Oct 18 23:39 robots.txt
drwxr-xr-x    6 root     root           192 Oct 18 23:39 sites
drwxr-xr-x    3 root     root            96 Oct 18 23:39 themes
-rw-r--r--    1 root     root           848 Oct 18 23:39 update.php
-rw-r--r--    1 root     root          4555 Oct 18 23:39 web.config

Nginx容器流程如下:

17     1 nginx    S    14344   1%   0   0% nginx: worker process
 1     0 root     S    13896   1%   0   0% nginx: master process

【问题讨论】:

    标签: linux docker nginx drupal permissions


    【解决方案1】:

    ls -l 列表中,第八列中的r 表示该文件是全球可读的;第十列带有x的目录也可以被任何人访问。从您发布的内容来看,没有任何内容可以访问它无权访问的任何内容。

    (全球可写autoload.php 可能很危险,如果它允许任何对系统具有 shell 访问权限的人编写您的 Web 服务器将运行的任意代码。)

    【讨论】:

    • 所以为了让网站安全,只有我们应该关心通过 nginx 暴露给世界的文件是否不应该具有写入权限??
    • 这是一个复杂的问题。例如,您可能不希望您的 .gitattributes 文件由 nginx 提供服务,即使您拥有正确的文件权限,您的脚本中也可能存在会危及事物的错误。
    猜你喜欢
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2019-06-24
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多