Skip to content

Commit 055719e

Browse files
author
Matthew Fisher
committed
Merge pull request #2875 from Blystad/builder_non-root_docker
ref(builder): Remove use of root in gitreceive
2 parents 1629773 + cc78b2d commit 055719e

3 files changed

Lines changed: 13 additions & 13 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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ BUILD_OPTS+=$(echo $RESPONSE | /app/bin/get-app-values)
9494
# if no Dockerfile is present, use slugbuilder to compile a heroku slug
9595
# and write out a Dockerfile to use that slug
9696
if [ ! -f Dockerfile ]; then
97-
if [ -f /buildpacks ]; then
98-
BUILD_OPTS+=' -v /buildpacks:/tmp/buildpacks:rw'
99-
# give non-root slugbuilder user R/W perms for docker volumes
100-
chown -R 2000:2000 /buildpacks
101-
fi
102-
10397
# run in the background, we'll attach to it to retrieve logs
10498
BUILD_OPTS+=' -d'
10599
BUILD_OPTS+=' -v '
@@ -108,8 +102,13 @@ if [ ! -f Dockerfile ]; then
108102
BUILD_OPTS+=' -v '
109103
BUILD_OPTS+=$(echo $CACHE_DIR)
110104
BUILD_OPTS+=':/tmp/cache:rw'
111-
# give non-root slugbuilder user R/W perms for docker volumes
112-
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
113112

114113
BUILD_OPTS+=' deis/slugbuilder'
115114

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)