我阅读文档:
https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md
https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox.md
https://chromium.googlesource.com/chromium/src/+/master/docs/linux_sandboxing.md
https://chromium.googlesource.com/chromium/src/+/master/docs/linux_sandbox_ipc.md
但无法找到正确配置沙箱的方法,也无法在我的系统上找到脚本 update-linux-sandbox.sh
。
我找到了 here
但我得到:
$ ./update-linux-sandbox.sh
/tmp/../out/Debug does not exist. Use "BUILDTYPE=Release ./update-linux-sandbox.sh" If you are building in Release mode
$ BUILDTYPE=Release ./update-linux-sandbox.sh
/tmp/../out/Release does not exist. Use "BUILDTYPE=Release ./update-linux-sandbox.sh" If you are building in Release mode
我唯一不安全的解决方法是使用:
const browser = await puppeteer.launch(
{headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox']}
);
知道如何正确地做事吗?
最佳答案
如果你在这里寻找一种在没有 --no-sandbox
arg 的情况下在 Centos7 中运行 Puppeteer 的方法,那么@MevatlaveKraspek 的答案将不起作用
我设法让 Puppeteer 在没有 --no-sandbox
标志 arg 的情况下截取屏幕截图,方法是设置 Linux 内核参数以启用命名空间(在 CentOS Linux 版本 7.4.1708 上)。
以root用户运行:
echo "user.max_user_namespaces=15000">>/etc/sysctl.conf
检查它是否适用于:
sudo sysctl -a | grep user.max_user_namespaces
现在重新启动您的系统并在不使用 --no-sandbox
的情况下运行脚本,例如 const browser = await puppeteer.launch();
如果它仍然不起作用,您可能使用的是较旧的 Linux 内核,并且需要在内核中设置一些额外的参数。
以root用户运行:
grubby --args="user_namespace.enable=1 namespace.unpriv_enable=1"--update-kernel="$(grubby --default-kernel)"
现在重新启动您的系统并检查您刚刚添加的 2 个参数的内核命令行
cat/proc/cmdline
如果他们在命令行中运行脚本而不再次使用 --no-sandbox
例如 const browser = await puppeteer.launch();
现在应该可以了。如果不是,您可能正在使用不支持命名空间的旧内核。
您可以通过以下方式检查您的内核版本:
uname -a
这是我的内核版本,我让 Puppeteer 在没有 --no-sandbox
arg 的情况下运行。
Linux centos7 3.10.0-693.21.1.el7.x86_64
希望这有帮助:)
关于node.js - 如何在 linux 上正确使用带有 puppeteer 的沙箱并停止变得不安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49554676/