我发现 Apache 2 的错误日志是致命的:
unsafe repository ('/home/repon' is owned by someone else)
它发生是因为我有git rev-parse --symbolic-full-name --abbrev-ref HEAD'
在 PHP 代码中,它看起来像新的 Git 安全变更 https://github.blog/2022-04-12-git-security-vulnerability-announced/不再允许www-data
运行此 Git 命令。
运行以下命令不起作用:
git config --global --add safe.directory /homerepon
有解决方法来解决这个问题吗?
git版本:2.35.3
PHP版本:7.4
阿帕奇2版本:2.4.41
随着 Git 2.35.2 安全更新的发布,该问题开始出现,该更新修复了所述漏洞here https://github.blog/2022-04-12-git-security-vulnerability-announced/。致谢@Juan-Kabbali
以下是四种可能的解决方案:
- 信任 Git 目录(如果您知道目录内容是安全的,请执行此操作)
git config --global --add safe.directory /home/repon
这增加了safe
分组到文件〜/.gitconfig如本例所示:
[safe]
directory = /home/repon
sudo -u ubuntu -- git status
Note: 这需要用户www-data
拥有以用户身份执行Git命令的权限ubuntu
(假设ubuntu是存储库所有者)。为此,您需要在其中添加一个新文件/etc/sudoers.d/
包含以下内容:
www-data ALL=(ubuntu) NOPASSWD: /usr/bin/git
这可能会产生安全隐患,因此请先咨询您的安全人员。
sudo chown -R www-data:www-data /home/repon
- 降级 Git 作为临时解决方案。例如,在 Ubuntu 中:
apt install git-man=1:2.17.0-1ubuntu1 git=1:2.17.0-1ubuntu1
Note:至少在 Windows 上,可弹出驱动器上的所有 Git 存储库似乎都被认为是不安全的,并且更改所有权似乎不起作用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)