简体   繁体   English

如何在实时服务器上保护git repo

[英]How to secure the git repo on a live server

Reading all the tutorials and articles on the internet. 阅读互联网上的所有教程和文章。 As a simple workflow, I have understood that we can create a bare repository on our live server and push updates to it from the local repo etc. 作为一个简单的工作流程,我了解到我们可以在我们的实时服务器上创建一个存储库,并从本地存储库等push更新。

My question and concern is that since the live server will also be a Git repo and it would have the .git folder, Wouldn't that be a security problem? 我的问题和关注是,由于实时服务器也将是一个Git仓库,它将具有.git文件夹,这不是一个安全问题吗? How to prevent access to it? 如何防止访问它?

Update 更新

Suppose my live folder on server is /www and I can access it from the browser http://myserver.com so I can also access http://myserver.com/.git/HEAD ??? 假设我的服务器上的实时文件夹是/ www,我可以从浏览器http://myserver.com访问它,所以我也可以访问http://myserver.com/.git/HEAD ??? How to prevent it? 怎么预防呢?

You may want to consider separating the repository and the working tree. 您可能需要考虑分离存储库和工作树。

For example, somewhere outside of the folder served by your Web server, run git init --bare . 例如,在Web服务器提供的文件夹之外的某个位置,运行git init --bare Then replace the config file in this directory with the following (where /path/to/web/root is the path where the files should be placed). 然后使用以下内容替换此目录中的config文件(其中/path/to/web/root是应放置文件的路径)。

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    worktree = /path/to/web/root
[receive]
    denycurrentbranch = ignore

Finally add hooks/post-receive with the following contents and mark it executable 最后使用以下内容添加hooks/post-receive并将其标记为可执行文件

#!/bin/sh
git checkout -f

Now whenever you push to the repository, the files will be checked out into the correct location and you never have to worry about the repository accidentally being served up. 现在,无论何时推送到存储库,文件都将被检出到正确的位置,您永远不必担心存储库意外被提供。

Git does not care about security of accessing to your .git folders - it is your responsibility and OS enforcing access to them. Git不关心访问.git文件夹的安全性 - 您有责任和操作系统强制访问它们。

Basically, if you can ssh into your server and access .git folder - you can do whatever you want, and so does git. 基本上,如果你可以ssh到你的服务器并访问.git文件夹 - 你可以做任何你想做的事情,git也是如此。

There is very convenitent way to handle users, passwords, ssh key management, etc. is to install Gerrit . 处理用户,密码,ssh密钥管理等非常方便的方法是安装Gerrit Gerrit is Git server implemented in Java, but it also happens to be great code review engine. Gerrit是用Java实现的Git服务器,但它也恰好是很好的代码审查引擎。 Code review part is very useful, however you do not have to use it if you don't want to. 代码审查部分非常有用,但如果您不想使用它,则不必使用它。 You can move to use code review later, but provided git server, web ui and user/keys management, UI to control access permissions to different git repos are very nice. 您可以稍后移动使用代码审查,但提供git服务器,web ui和用户/密钥管理,UI来控制对不同git repos的访问权限非常好。

Love the accepted answer, great example of the use of git hooks. 喜欢接受的答案,使用git hooks的好例子。

How I went around this problem (I also posted a question long time ago whether the website should be a repository) is, after thinking about it, I decided to create git releases, zip-em-up, and decompress into a "live" folder. 我如何解决这个问题(我很久以前也发布了一个问题,网站是否应该是一个存储库),在考虑之后,我决定创建git版本,zip-em-up,并解压缩成“live”夹。

With the use of helper scripts, and git aliases, of course. 当然,使用辅助脚本和git别名。

I have a couple of scripts, such as rgitpropup (which merges branches from the ground up to master, and pushes to origin) and rgitrelease, which creates a GPG signed release, uses a dir prefix as an argument, and zips it up. 我有几个脚本,例如rgitpropup(它将从头开始合并到master,并推送到源)和rgitrelease,它创建一个GPG签名版本,使用dir前缀作为参数,并将其拉上。

I've aliased the propup script (when aliasing scripts, you prefix them with "!", btw.) 我把propup脚本别名(当别名脚本时,你用“!”前缀它们,顺便说一下。)

I guess with hooks you could also manage the installation/decompression into the "live" directory... 我想用钩子你也可以管理安装/解压缩到“live”目录......

EDIT: archive is a git command, and it has built-in support for compressing to archive formats. 编辑: archive是一个git命令,它内置支持压缩到存档格式。 Usually it is used in combination with the tag command, which has bult-in support for pgp/gpg signing (gpg is how digitally sign in git in general, not to be confused with sign-off) 通常它与tag命令结合使用,它对pgp / gpg签名具有bult-in支持(gpg一般是如何通过git进行数字签名,不要与签名混淆)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM