Skip to content

Commit cc78b2d

Browse files
author
Arne-Christian Blystad
committed
ref(builder): Remove use of root in gitreceive
This change removes the use of root in gitreceive. Before we had to run a script as root to get Docker access, but this has since been fixed in Docker. The motivation between the change was because of bug #1843, caused by running "git gc" as root. This changed the owner of git files and directories to root:root, which was inaccessable from git:git. This also fixes /buildpacks check which checked if /buildpacks was a file (which it is not, it's a directory).
1 parent 35b8495 commit cc78b2d

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

builder/image/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ RUN useradd -d $GITHOME $GITUSER
3838
RUN mkdir -p $GITHOME/.ssh && chown git:git $GITHOME/.ssh
3939
RUN chown -R $GITUSER:$GITUSER $GITHOME
4040

41-
# let the git user run `sudo /home/git/builder` (not writeable)
42-
RUN echo "%git ALL=(ALL:ALL) NOPASSWD:/home/git/builder" >> /etc/sudoers
43-
4441
# HACK: import progrium/cedarish as a tarball
4542
# see https://github.com/deis/deis/issues/1027
4643
RUN curl -#SL -o /progrium_cedarish.tar.gz \
@@ -56,6 +53,11 @@ CMD ["/app/bin/boot"]
5653
EXPOSE 22
5754
RUN addgroup --quiet --gid 2000 slug && useradd slug --uid=2000 --gid=2000
5855

56+
# $GITUSER is added to docker group to use docker without sudo and to slug
57+
# group in order to share resources with the slug user
58+
RUN usermod -a -G docker $GITUSER
59+
RUN usermod -a -G slug $GITUSER
60+
5961
ADD templates/shim.dockerfile /home/git/
6062
ADD etc /etc
6163
ADD . /app

builder/image/templates/builder

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ if [ ! -f Dockerfile ]; then
102102
BUILD_OPTS+=' -v '
103103
BUILD_OPTS+=$(echo $CACHE_DIR)
104104
BUILD_OPTS+=':/tmp/cache:rw'
105-
# give non-root slugbuilder user R/W perms for docker volumes
106-
chown -R 2000:2000 $TMP_DIR $CACHE_DIR
105+
# give slug group ownership of TMP_DIR and CACHE_DIR.
106+
chown -R :2000 $TMP_DIR
107+
chown :2000 $CACHE_DIR
108+
# TMP_DIR is created using mktemp, which sets permissions to 700. Since
109+
# we share this with the slug group, the slug group needs to be able to
110+
# work with it.
111+
chmod g+rwx $TMP_DIR
107112

108113
BUILD_OPTS+=' deis/slugbuilder'
109114

builder/image/templates/gitreceive

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ EOF
5757
cd $GITHOME
5858
# if we're processing a receive-pack on an existing repo, run a build
5959
if [[ $SSH_ORIGINAL_COMMAND == git-receive-pack* ]]; then
60-
# SECURITY: git user runs the builder as root (for docker access)
61-
sudo $GITHOME/builder $RECEIVE_USER $RECEIVE_REPO $newrev 2>&1 | strip_remote_prefix
60+
$GITHOME/builder $RECEIVE_USER $RECEIVE_REPO $newrev 2>&1 | strip_remote_prefix
6261
fi
6362

6463
rm -f "$LOCKFILE"

0 commit comments

Comments
 (0)