diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-09-22 15:56:38 +0000 |
---|---|---|
committer | Baserock Gerrit <gerrit@baserock.org> | 2015-10-07 00:03:04 +0000 |
commit | 1b3cf19369bce2c638f84ad8350e7de6c2f9ece6 (patch) | |
tree | 654f2ce0274bc1e2dfea8865fb1f2ce5726228ca | |
parent | c521d6fa5a8a18ce3ed420d475ef0a3cc7b51ee5 (diff) | |
download | morph-1b3cf19369bce2c638f84ad8350e7de6c2f9ece6.tar.gz |
Ensure Git clones in a chunk build directory have correct ownership
When preparing the build directory for a chunk, Morph clones the Git repo
being built (and any submodules) into the staging area.
Instead of using `git clone --no-hardlinks`, the
morphlib.git.copy_repository() function uses 'cp -a' plus some faffing
to achieve the same thing a bit faster.
The 'cp -a' command will preserve the ownership and permissions of the
cached copy. These may not match up with which user is doing the build.
I found that files in my Git cache were owned by UID 1002. This caused
chunks that needed to access the .git directory at build time to fail
with strange errors. Worse, it would trigger a bug in Git[1] that leads
to a fork bomb, which would cause Linux to freeze up completely. This
occured even though I was building as `root`, because of the way
`linux-user-chroot` drops certain privileges: presumably, setting
SECBIT_NOROOT leads to CAP_DAC_OVERRIDE being unset.
To avoid this bug, the code now ensures the copied .git repos are owned
by the user and group who ran `morph`.
Another way to fix this would be to change the
morphlib.gits.copy_repository() function to use `git clone
--no-hardlinks`. This is what YBD does. I found that there is a slight
speed benefit to using the current code ... these are results of cloning
repos from the cache with the 2 methods:
With 'cp -a' plus a chown:
upstream:bison: 4.54 seconds average (10 results)
upstream:ybd: 0.13 seconds average (10 results)
upstream:linux: 40.51 seconds average (10 results)
With 'git clone --hardlinks':
upstream:bison: 6.23 seconds average (10 results)
upstream:ybd: 0.11 seconds average (10 results)
upstream:linux: 43.36 seconds average (10 results)
Test code is: <https://gist.github.com/ssssam/833e0ef8d04fb1fb6ff3>.
Ideally we would fix `git clone --no-hardlinks` to be faster, but we
may as well keep the existing code for the time being.
[1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=750687
Change-Id: Ieea87322ea7b7f62975b9480f877755665656217
-rw-r--r-- | morphlib/git.py | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/morphlib/git.py b/morphlib/git.py index acda6137..b6f54d02 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -233,6 +233,7 @@ def copy_repository(runcmd, repo, destdir, is_mirror=True): return runcmd(['cp', '-a', repo, os.path.join(destdir, '.git')]) + runcmd(['chown', '-R', '%s:%s' % (os.getuid(), os.getgid()), destdir]) # core.bare should be false so that git believes work trees are possible gitcmd(runcmd, 'config', 'core.bare', 'false', cwd=destdir) # we do not want the origin remote to behave as a mirror for pulls |