News for hackers. Stuff that matters.
Re:Too Perfect a Mirror by pja on Sunday March 24, 2013 @07:14AM (#5431726)
Relying on consistency checks will not save you if someone does the git equivalent of rm -rf on the master repository. Which is why mirroring (of any description) is not a backup strategy.

Yes, git --mirror should probably automatically invoke the moral equivalent of git fsck by default in order to catch internal repository inconsistency like the other git commands do, and the KDE team have been caught out by this. But they still don't have any protection against user error leading to loss of data with this setup as far as I can see, and that seems like a huge oversight.

Re:Too Perfect a Mirror by mpyne on Sunday March 24, 2013 @10:44AM (#5432181)
> Relying on consistency checks will not save you if someone does the git equivalent of rm -rf on the master repository.

The master repository is coded so that those types of actions are not permitted. Developers cannot force push or delete branches that aren't reintegrated into some other head, without assistance from the sysadmins.

After every routine push to a KDE git repository the new commit will be a descendant of the repo's original head.

With that in mind it's more understandable as to why they felt it was possible to take advantage of Git's design in the backup planning.

No "huge oversight" here, at least on this particular issue.

Re:Too Perfect a Mirror by andrewvc on Sunday March 24, 2013 @02:17PM (#5432902)
Ummm, still not a backup. What if there's an error in the code? What if an admin runs a script directly on the server and resets all repos by mistake? What if a bad release of git comes out and corrupts the master? What if a hacker comes in and wipes them all out?

Only a backup is a backup. Backup, like security, is somewhat onion like.

Re:Too Perfect a Mirror by mpyne on Sunday March 24, 2013 @03:37PM (#5433227)
I never claimed it was a backup, only that it wasn't completely susceptible to user error as was surmised in the comment I replied to.

However, regarding the backup question, an rsync backup would have been just as damaging to the anongit mirrors as git --mirror was. The whole point to git for KDE is that that "distributed" part of the VCS would help handle backups. And it has, that part has not really been in question.

The 'luck' came in where there happened to be an anongit mirror that was fully synced up so that we didn't have to crowdsource repo restoration, which saved a lot of time and anguish.

Had we at KDE ensured that the git repository being synced to an anongit mirror was fully consistent we wouldn't even be speaking about this: the git.kde.org repos would be shut down until the box could be restored and we'd have any of 5 easy backups to choose from to restore the repositories (the rest of the files on the box would be restored from the normal backups used).

I want to stress that this is the larger point here: It's possible in some ways to corrupt a git repository and have its subcommands not notice. You must use the provided git-fsck (directly or indirectly) before backing up a git repository, especially if you don't use git for the backup, or use git-clone --mirror.

The error wasn't that we weren't doing backups, the error was that we were making corrupted backups. tar | /dev/tape will do this to you just as badly if you get the right FS corruption.

COW snapshotting filesystems can help (if they have no bugs) but the KDE sysadmins were working under the errant assumption that git would make the integrity check in situations where that wasn't true, not that backups are simply not required.

Re:Too Perfect a Mirror by derleth on Sunday March 24, 2013 @02:25PM (#5432929)
What if your backup systems get compromised? What if your backup systems get destroyed by inclement weather? Not a backup then, obviously.

Only a backup is a backup, until it's not a backup anymore.

Re:Too Perfect a Mirror by MaulingMonkey on Sunday March 24, 2013 @05:00PM (#5433556)
This is why, if your data is sufficiently important, you'll want to:

1) Test your backups, to detect when your backups are no longer backups.

2) Make geographically diverse backups, so a single tidal wave can't wipe out your data. For bonus points, have enough geographically diverse backups that the world is probably ending if they're all being wiped out -- at which point you have bigger problems to take care of.

3) Make backups with a diverse set of mechanisms, so the failure or compromise of one (or N-1) can't fail and compromise all backup copies. Making backups on write-only media and hiding them means current failure or compromise can't fail and compromise previous backups, and may help back your data up against theft, landlords, angry neighbors, spurned girlfriends, or even the occasional corrupt government official.

Mirroring (be it software or RAID) is not a backup system: It is far too dumb, far too happy to overwrite your old good data with new bad data. You want a history, where old good data is not replaced.

Git is not a backup system: It is a version control system. While it may have some of the properties of a backup system as goals, that is not it's primary use case. As a result we see articles like this where we've seen how it can fail in achieving the goals of a backup system as a practical matter in this very article, even when intentionally attempting to use it as a poor man's backup system in the form of mirrors.

Such problems are not unique to git, of course. On a personal note, I've managed to wipe data with both git and perforce in moments of weakness. If you want to treat me kindly about it, you could say I used both to the point where the statistics were against me not shooting myself in the foot. And, fortunately so far, the use of proper, separate backup mechanisms have always allowed me to restore the majority of my data and left me relatively unscathed.

Re:Too Perfect a Mirror by mpyne on Sunday March 24, 2013 @05:17PM (#5433663)
We're already doing #1, 2, and 3 on the list you provided, just so you know (although we missed out on some areas for #1 in retrospect).
Re:Too Perfect a Mirror by chris_wot on Sunday March 24, 2013 @02:28PM (#5432942)
That's kind of ridiculous. The point that most people are making is that if someone does something incredibly stupid, or there is corruption in the system that follows down the line (like what happened here), it doesn't matter whether you have a repository.

A backup clearly would have helped here.

Re:Too Perfect a Mirror by mpyne on Sunday March 24, 2013 @05:14PM (#5433641)
A backup of a corrupt repository would have been just as corrupt though.

This is the big thing I can't figure out what people are not understanding. git does consistency checking for you already, tar|rsync|etc. don't, so it makes sense to take advantage of that.

What we had was an instance of some of the underlying data becoming corrupt on the filesystem (with indications of that starting on Feb 22!). The big mistake was considering the source repositories as consistent and canonical at the remote anongit end, but the data would have been just as corrupt if we had scp'ed the repos from git.kde.org to the anongit mirrors around the world, since we would have bypassed git's internal checking in that way.

Is it safe to rsync a running mysql database at random times, or are you supposed to use mysql-provided tools to perform a backup?

Re:Too Perfect a Mirror by tempestn on Sunday March 24, 2013 @11:37PM (#5435295)
OK, but what stops them from daily performing a mirror clone, checking it for consistency, then backing that up? As mentioned in the linked update, 30 complete backups would consume only 900GB, so you could keep weeks of daily backups, plus weekly and/or monthlies going back much further, for a terabyte of space. That way, in the worst case, you could go back to a backup before the corruption began. Obviously you would want to have plenty of safeguards in place so that that never happened, but just in case, it's good to have an honest to goodness backup too.
Re:Too Perfect a Mirror by Confusion on Sunday March 24, 2013 @07:26AM (#5431742)

  Relying on consistency checks will not save you if someone 
  does the git equivalent of rm -rf on the master repository.
There is no equivalent of rm -rf in git. If you remove files being versioned and commit them, the previous version still exists and the commit can be reverted. If you remove the metadata, no sync can happen, you are immediately warned (assuming good monitoring was set up) and can restore from one of the clones. If the entire machine crashes and burns, you whip out your git-server-create.sh, which provisions a new VM and restores from one of the clones. There is no additional data to be backup up with git. Any single developer with a recent clone of the repos can setup a new master git server.
Re:Too Perfect a Mirror by tomp on Sunday March 24, 2013 @07:37AM (#5431765)

  git checkout master
  git reset --hard HEAD^
  git push --force origin master
will remove the latest commit. If the mirrored repositories then blindly use the origin's refs, and do a `git gc`, the latest commit will be removed.
Re:Too Perfect a Mirror by gcb0 on Sunday March 24, 2013 @10:20AM (#5432098)
I mostly rather Hg over fit because with Hg it's way harder to "rewrite history", among other things.
Re:Too Perfect a Mirror by gcb0 on Monday March 25, 2013 @02:22PM (#5438657)
*git
Re:Too Perfect a Mirror by dunham on Sunday March 24, 2013 @11:47AM (#5432359)
Doesn't `git gc` keep stuff pointed to by the last 30 days of the ref log?
Re:Too Perfect a Mirror by pja on Monday March 25, 2013 @07:20AM (#5436455)
There's no reflog in bare repositories.
Re:Too Perfect a Mirror by Confusion on Sunday March 24, 2013 @07:42AM (#5431774)
It is impossible to blindly use the origin refs in that case. Git doesn't deal well with rewriting history. If someone force pushes to a centrally shared repo, all hell breaks loose.
Re:Too Perfect a Mirror by pyre on Sunday March 24, 2013 @09:00AM (#5431928)
From the article:

  | New refs are pulled down to the downstream
  | repository; all updates, including forced updates,
  | are mirrored to the downstream repository.

  | As a result, making a mirror clone essentially
  | bypasses the safety checks in the repository
And

  > If someone force pushes to a centrally shared
  > repo, all hell breaks loose.
This would happen to users pulling/pushing from the central repo, but not to the mirrors.
Re:Too Perfect a Mirror by Confusion on Sunday March 24, 2013 @11:04AM (#5432229)
In that case another developer would notice, would get in touch with his fellow developers, they would agree to force push a specific repository condition and all is well and back to normal. There is no need to restore anything from backups or mirrors in that scenario.

So that's an entirely different threat. On the one hand we have FS corruption, which is basically bound to happen and is likely to impact many repositories. On the other hand we have someone (maliciously) force pushing an update on a single repository that throws away all commits.

The first issue is one that needs a backup and restore procedure. The second is one that is at best an inconvenience and at worst a security problem.

Unless you want to include the the worst case scenario someone gaining access to the machine and force pushing such a destructive update on all repos. In that case restoring from developer copies may actually be safer anyway, because the machine and all its backups, be they mirrors or otherwise, may be considered compromised. That's a nightmare for which this discussion about backups is just quibbling.

Re:Too Perfect a Mirror by michaelt on Sunday March 24, 2013 @07:46AM (#5431781)
Surely every backup system has some equivalent of an rm -rf ? A disgruntled employee could phone the off site tape archival company and tell them to toss all the tapes in the shreader.
Re:Too Perfect a Mirror by reeses on Sunday March 24, 2013 @10:51PM (#5435068)
In the specific case of offsite tape archival, let's say someone who has the authority to do so requests that they destroy all tapes.

Most service providers (who stay in business) have enough compliance features in place so that multiple authorized people have to be in collusion, a sufficiently senior executive must make the request, or there will be a "package" ready to be served to the client and relevant policing unit (police, FBI, whatever) so that charges can be brought against the malefactor efficiently.

While you may be limited in financial compensation by your contract with the service provider, it is absolutely in their best interest to avoid the situation with procedures (they do not want to be a party to a crime) and if those fail, to provide extensive records of the movement and disposition of those tapes.

Re:Too Perfect a Mirror by chris_wot on Sunday March 24, 2013 @02:30PM (#5432953)
The probability of this occurring is far less than what happened here.
Re:Too Perfect a Mirror by richo on Sunday March 24, 2013 @07:23AM (#5431737)
Git doesn't nuke objects until you explicitly ask it to.

It might sync broken objects, but it won't actually chose to destroy dangling objects without being asked to.

Re:Too Perfect a Mirror by pja on Sunday March 24, 2013 @07:48AM (#5431785)
(This is missing the wider point, but regardless: AFAIK (do correct me if I'm wrong) git clone --mirror will not copy dangling references & those refs will disappear from the original after a git gc, whenever that happens.)

Human error is human error: sometimes people will do apparently egregiously stupid things if it's possible for them to do so, including things like deleting branches from a repository & then doing a git gc to "save space" shortly before realising that they weren't issuing commands to the shell they thought they were in. A backup strategy should be robust against dumb human mistakes as well as mechanical hardware errors, otherwise it's no backup strategy at all.

Re:Too Perfect a Mirror by DougBTX on Sunday March 24, 2013 @07:45AM (#5431778)
They say in the article that one step of the anongit sync is to delete projects from the anongit servers which have been deleted on the central server. If a user accidentally deletes a project, they should be able to recover it from a backup, but it doesn't sound like there are any backups.

The same idea applies to the individual repos themselves. A git gc will delete objects unreferenced by the reflogs, eg deleted branches over a month old by default. They say that the total set of repos is about 25GB, so it would be reasonable to keep at least monthly backups for at a year or more.

Re:Too Perfect a Mirror by sho_hn on Sunday March 24, 2013 @08:03AM (#5431817)
We do ref backups on branch deletions FWIW.
Re:Too Perfect a Mirror by DougBTX on Sunday March 24, 2013 @08:19AM (#5431841)
Yea, that sounds like a good idea, can you do that in something like a pre-push hook? That plus long reflogs seems like it would make recovery of rebased/deleted branches really easy for end users.
Re:Too Perfect a Mirror by sho_hn on Sunday March 24, 2013 @08:24AM (#5431852)
We don't allow force-pushes without admin involvement, so rebasing isn't so scary for us, but we do cover it that way. And we got the undo operation down to a command on the infra: http://community.kde.org/Sysadmin/GitKdeOrgManual#ohnoes

The rest of that Wiki page is also pretty interesting for a general look at what devs can do on git.kde.org - server-side personal clones, personal repositories, a personal trashcan for repositories, etc. We don't have a pretty web interface for it (yet?), but it has some nice features.