使用 git 作为部署实用程序时的安全问题
git 是一个非常强大的工具,但不是那么容易使用
例如,我很高兴使用 git 作为从我的 git 存储库更新我的远程站点的工具。问题是我的网站根目录有一个 .git 目录,外部用户可以简单地使用 site/.git 访问它,这很糟糕,因为他们可以轻松获取我的代码历史记录,基本上是当前代码,他们甚至可以从配置文件中获取密码和私人信息。
那么怎样才是正确的git使用方式,既能充分利用git,又不会引入这些威胁呢?
使用 git clone git://repo site_root 初始化网站,并使用 git pull 获取更改非常方便,但也带来了巨大的安全问题。
有没有什么方法可以像上面所示的步骤一样方便,但没有安全隐患?
git is a very powerful tool, but not that easy to use
For example, I am glad to use git as a tool to update my remote site from my git repository. The problem is there is a .git directory at the root of my website, external users can simply visit it using site/.git, that is terrible, since they can easily get my code history, and basically the current code, they can even get passwords and private informations from the configuration files.
So what is the right way to use git which can make full use of git, but without introducing these threats?
Using git clone git://repo site_root
to initialize web site, and git pull
to get changes is of great convenience, but also brings huge security problems.
Is there any methods that can be as convenient as the steps shown above, but without security pitfalls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Apache 至少默认其配置为禁止 Web 访问任何以
.
开头的文件,并且这也可以在任何其他 Web 服务器中完成。此外,最好将敏感文件保留在 Web 根目录之外,即:
并将网站的文档根目录设为
public/
目录。Apache, at least, defaults its configuration to forbidding web access to any file starting with a
.
, and this could be done in any other webserver as well.Additionally, it's best to keep sensitive files outside the web root, i.e.:
and have the document root for the site be the
public/
directory.好吧,我不太喜欢直接使用 git 自动部署代码的最新版本,但这是另一个问题。
关于您的安全问题,一个真正基本的解决方案是删除对 .git 文件的访问(使用 htaccess 文件?)。
另一件事是从 git 存储库中删除您的密码,在您的版本控制系统中可能没有使用密码。
Well, I'm not really fond of using directly git to automatically deploy the last version of your code, but that's another question.
Regarding your security issue, a really basic solution would be to just remove access to your .git file (with htaccess files?).
Another thing would be to remove your passwords from the git repository, there is probably no use of then in your version control system.
请参阅 http://www.clientcide .com/best-practices/exporting-files-from-git-similar-to-svn-export/
从上面:
See http://www.clientcide.com/best-practices/exporting-files-from-git-similar-to-svn-export/
From the above:
@JaredPar 的评论和@Chris Shain 上面的答案的组合(+1 表示 git 存档)。
我还使用 git archive,然后使用 Chef 进行实际部署。再简单不过了。
git 存档; | gzip > rc.tar.gz
mv rc.tar.gz
到我的食谱在我的服务器上运行的厨师客户端运行配方以将压缩文件复制到 chache 位置并将其解压缩进入我的网络服务器目录。
自我提醒:在 github 上发布食谱
A combination of @JaredPar's comment, and @Chris Shain's answer above (+1 for the git archive).
I use
git archive
also, and then use Chef for the actual deployment. Couldn't be simpler.git archive <tag_name> | gzip > rc.tar.gz
mv rc.tar.gz
to my cookbookThe chef-client running on my server runs the recipe to copy the zipped file to a chache location and extract it into my web server directory.
Note to self: publish the recipe on github
如果需要在生产服务器中拥有完整的存储库,那么就有一个解决方案。
您可以在文件系统中的某个位置拥有整个历史记录,并让 git “指向”它。
如果这样做,您的历史记录将位于无法通过网络访问的
/private/repo.git
中,并且您的工作目录将位于 /public 中,仅提供您指定的文件版本。如需了解更多信息,您可以阅读 progit。
If having the complete repo in the production server is a requirement, then there is a solution.
You can have the whole history somewhere in the file system and have git "point" to it.
If you do that, your history will be in
/private/repo.git
that is not accessible through the web, and your working directory will be in /public, serving only the version of the files you specify.For more information, you can read progit.
我会再次提出这个问题,因为我也在研究安全问题。
您应该使用独立的工作树,如下所述 此处。您可以在 Web 根目录之外创建 git 存储库,并使 git 指向不同目录中的源代码。
I'll resurrect this question because I'm also looking into security issues.
You should use a detached work tree, as explained here. You can create your git repository outside the web root, and have git point to the source code at a different directory.