156 points · by g4k · 9y ago · 86 comments
A much better approach (or at least, what I use) would be to set up the repo somewhere private with --bare and set a receive hook to checkout HEAD to the htdocs folder, this way the htdocs only has the content and you get the extra feature that you can sneak extra commands on the checked out source (such as building/minifying) without changing the original source
> Another approach is to use git’s --git-dir and --work-tree switches to move the git repository out of the document root.
Yet another option is to make the htdocs directory a worktree of the git repository, which doesn't require passing flags around, or setting environment variables. Technically, this still leaves a .git, but it's only a file containing the actual location to the real .git directory.
If your history has sensitive info, see about rewriting the history. If that's not possible, maybe fork the repo, remove the sensitive info, and get the team to switch to the fork. If that's not possible either, make the sensitive info meaningless (reset your DB passwork, revoke the API tokens, etc).
a) how do you search a repository's history, along all branches (including undeployed development branches, which may nonetheless contain production secrets) to find secrets mistakenly stored in version control? b) what happens when somebody stores a secret which isn't easily rotated (because legacy systems have hard-coded the secrets etc.)? How do you deal with trying to rotate secrets which aren't well-managed, because the real problem isn't that your teams are storing secrets in source control but that you don't have proper secret management set up across your organization?
The simpler (and more correct!) way to deal with this is to stop using version control for deployments and to start using proper package management and deployment tooling. Version control is not designed as a deployment tool; it is a poor replacement for proper deployment tooling; and teams which think they only have hammers to hit what are not nails but screws, need to learn that sometimes they'll have to go out and get a set of screwdrivers too.
(When building systems for clients, this is something I stress. "We should be operating as if it is assumed that an attacker has a VPN into your network space and has nmapped all your stuff.")
And don't just stop with .git: Delete any folder/file that's not required to operate the app in production.
We do something similar. "Clean and minimal" is a good strategy when you're deploying assets to publicly accessible systems.
Step one: stop randomly smearing crap around. Prod should only have files that came from a .deb or .rpm signed by the legit build process, because that's how you know your system is reproducible and has everything it should and nothing else.
If the deploy process is "git pull", you're praying that Joe McGee didn't push some untested crap to the relevant branch 5 seconds before you deployed.
I'll argue with "that's how you know your system is reproducible and has everything it should and nothing else", though. To get there, you need to look at immutable infrastructure, where you're building a new container or VM image for every deploy. Otherwise you might have libfoo installed on the app server, despite your app dropping support for foo 2 years ago.
You can use git for deployment but indeed you must have a clear commit policy to do that (and it's a good idea anyway to push only major curated versions on master).
It's also solved the exact same ways, by scripting your stuff on one level or another.
You can actually use git in production, properly.
I personally like to mount gitRepo volumes on Kubernetes, and have my CI pipeline automatically update the revision of the deployment whenever it validates tests. Then I have kubernetes roll out the update automatically.
shameless plug: I've developed a service that you run to check against vulnerabilities in your apps/servers and it has a free plan (https://my.gauntlet.io/registration.html) in case you're interested (https://gauntlet.io).
For example, static websites for open source projects, et al.
> It seemed like an accessible git repository was intended on some websites - mostly open source projects where the website’s sourcecode is available online.
> On the other side, we had to hold our breath when we noticed that more than 100 projects used HTTP-Authentication for server-client communication. That means, that the protocol://user:password@host/repository combination is saved in the .git/config file, giving attackers access to the users (companies) GitLab-instance or GitHub/BitBucket account. With a bit of luck an attacker gets access to the CI-Server and then runs malicious code to further compromise your infrastructure.
I just rechecked with [1] and you seem to be right.
I'll update the blogpost in a second. Thanks for the hint!
Not that you should have .git exposed on your public webserver anyway. I do remember participating in a CTF that had a problem like this a few years ago, it's possible that it was the same one the author mentioned.
Hasn't dvcs-ripper [1] been around for longer? It supports other VCSes as well.
Also, the article fails to mention that a simple `git clone` would usually work as well, although that tends to be blocked in similar CTF challenges.
I knew about dvcs-ripper, but thought that implementing another variant might be fun and let me learn about git internals.
Does a simple `git clone` really work? I just tested it and it failed:
``` $> git clone http://x.domain.tld/ fatal: repository 'http://x.domain.tld/' not found
$> git clone http://x.domain.tld/.git/ fatal: repository 'http://x.domain.tld/.git/' not found ```
And yes, the post's background is a CTF challenge that blocked a simple `git clone`.
Parts are even in metasploit.
here's one of the blogpost's authors. Although it has been a while since we published the blogpost, I'll try to answer any questions or listen to any suggestions.
So if I post my website's sourcecode on github, I'm equally vulnerable? I could see problems if said checkout contained a credential cache, but that doesn't seem to be mentioned.
So if your deploy process is an anonymous git checkout of Drupal, there's no credential leaking to worry about.
> no guarantee a future feature of Git that you've never heard of doesn't make the problem worse
Okay.
/mysite/.git
/mysite/mysiteroot/index.html
/mysite/.gitignore
/mysite/lib/common # deny access to HG and Git repositories
location ~ /\.(hg|git)/ {
deny all;
}These type of snarky responses discourage newcomers to participate in discussions. I have seen this happen to many people, so please dial back the snark.
Hey! That's not very kind to disparage everyone using a text file in a git repo to manage their passwords/keys.
Putting keys into a git repo is fine! But be careful when publishing that repo, as something you thought was private could suddenly become public.
If your code is public then what does it matter? If it's not then you should be protecting it like any other sensitive information.
You can unintentionally expose your repository by deploying .git by mistake.