Apache2: 设置挂载命名空间失败:权限被拒绝。

4
我有一台Debian 10的VPS服务器,我想使用选项PrivateTmp=true启动Apache2,但在启动时出现错误:apache2.service:在命名空间步骤中启动/usr/sbin/apachectl失败:权限被拒绝
    ● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2020-11-27 17:17:43 CET; 5s ago
     Docs: https://httpd.apache.org/docs/2.4/
  Process: 523 ExecStart=/usr/sbin/apachectl start (code=exited, status=226/NAMESPACE)

Nov 27 17:17:43 5091-server systemd[1]: Starting The Apache HTTP Server...
Nov 27 17:17:43 5091-server systemd[523]: apache2.service: Failed to set up mount namespacing: Permission denied
Nov 27 17:17:43 5091-server systemd[523]: apache2.service: Failed at step NAMESPACE spawning /usr/sbin/apachectl: Permission denied
Nov 27 17:17:43 5091-server systemd[1]: apache2.service: Control process exited, code=exited, status=226/NAMESPACE
Nov 27 17:17:43 5091-server systemd[1]: apache2.service: Failed with result 'exit-code'.
Nov 27 17:17:43 5091-server systemd[1]: Failed to start The Apache HTTP Server.

我查看了tmp文件夹的权限:

root@5091-server:~# ls -ld /tmp
drwxrwxrwt 8 root root 4096 Nov 27 17:17 /tmp
root@5091-server:~# ls -ld /var/tmp
drwxrwxrwt 2 root root 4096 Nov 27 17:17 /var/tmp

你有没有想过是哪些权限有问题?

3个回答

2
这与新的systemd安全功能(v220+?)冲突,这些功能与Proxmox内部的非特权LXC容器等不具备特权的LXC容器有关。
  1. Edit apache config (the clean way):

    sudo systemctl edit apache2.service
    
  2. Add this to disable new systemd security features (affect LXC containers like the ones inside Proxmox)

    [Service]
    PrivateDevices=false
    PrivateTmp=false
    ProtectControlGroups=false
    ProtectKernelModules=false
    ProtectSystem=false
    

    Maybe only necessary:

    ProtectHome=false
    ProtectSystem=false
    
  3. Then

    sudo systemctl start apache2.service
    sudo systemctl status apache2.service  # Just to check the output
    
我在apache2和memcached上看到了这个问题。还有systemd-logind。在最后一种情况下,SSH连接速度受到了影响。 ssh -vvv(没有VPN)停留在debug1: pledge: filesystem上,而在使用VPN时停留在debug1: pledge: network上。正如这里这里所提到的,启用Proxmox容器中的嵌套模式(也可以在这里找到)可以解决这个问题。

如果容器是非特权的,可能只需启用"嵌套"功能即可使systemd使用其命名空间功能。

相关


1
具体来说,运行 pct set <CTID> --features nesting=1 对我有用。谢谢! - Tim

1

这可以工作...

sudo sed -i -e 's,PrivateTmp=true,PrivateTmp=false\nNoNewPrivileges=yes,g' /lib/systemd/system/apache2.service
sudo systemctl daemon-reload
sudo systemctl start apache2.service
sudo systemctl status apache2.service

0

在较新的操作系统版本上,我在 Docker 中使用 systemd 时遇到了相同的错误。我的用例是一个测试设置。

事实证明,我的 Docker 主机系统启用了 AppArmor,并且这限制了容器内部对 systemd 的使用。

最后我使用了

    security_opts:
      - "apparmor=unconfined"

在 ansible molecule.yml 中。
可以通过运行以下命令检查设置: $ docker inspect $CONTAINERNAME --format '{{ .Id }}: SecurityOpt={{ .HostConfig.SecurityOpt }}'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接