Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Commit

Permalink
Drop privs to buildkite-agent in containers
Browse files Browse the repository at this point in the history
  • Loading branch information
lox committed Jan 22, 2016
1 parent 186ea17 commit 5049404
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LABEL com.buildkite.distro="alpine" \
com.buildkite.docker_compose_version=1.5.1

RUN apk add --update --repository http://dl-1.alpinelinux.org/alpine/edge/testing/ tini \
&& apk-install curl wget bash git perl openssh-client py-pip py-yaml docker\<1.9.2 \
&& apk-install sudo curl wget bash git perl openssh-client py-pip py-yaml docker\<1.9.2 \
&& pip install -U pip docker-compose==1.5.1 \
&& rm -rf /tmp/* /root/.cache `find / -regex '.*\.py[co]'`

Expand All @@ -19,7 +19,9 @@ ENV BUILDKITE_AGENT_VERSION=${BUILDKITE_AGENT_VERSION} \

COPY ./scripts/docker/entrypoint.sh ./assets/ssh-env-config.sh /usr/local/bin/
COPY ./assets/${BUILDKITE_AGENT_VERSION}-386 /buildkite
RUN ln -s /buildkite/buildkite-agent /usr/local/bin/buildkite-agent
RUN ln -s /buildkite/buildkite-agent /usr/local/bin/buildkite-agent \
&& adduser -S buildkite-agent \
&& chown -R buildkite-agent: /buildkite

ENTRYPOINT ["/usr/bin/tini", "-vg", "--", "/usr/local/bin/entrypoint.sh", "buildkite-agent"]
CMD ["start"]
3 changes: 2 additions & 1 deletion scripts/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ if [[ -e /buildkite/bootstrap.sh ]] ; then
export BUILDKITE_BOOTSTRAP_SCRIPT_PATH=/buildkite/bootstrap.sh
fi

exec /usr/local/bin/ssh-env-config.sh "$@"
# Run the remainder as the buildkite-agent user
exec sudo --preserve-env -H -u buildkite-agent /usr/local/bin/ssh-env-config.sh "$@"
10 changes: 9 additions & 1 deletion scripts/test_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ echo ">> Buildkite version: "
docker run --rm --entrypoint "buildkite-agent" "${DOCKER_IMAGE_NAME}" --version
echo -e "\033[33;32mOk\033[0m"

echo ">> Checking entrypoint drops privileges to buildkite-agent: "
if ! docker run --rm --entrypoint "/usr/local/bin/entrypoint.sh" "${DOCKER_IMAGE_NAME}" whoami | grep "buildkite-agent" ; then
echo -e "\033[33;31mAgent isn't running as buildkite-agent\033[0m"
exit 1
else
echo -e "\033[33;32mOk\033[0m"
fi

if [[ -n $(docker_label $DOCKER_IMAGE_NAME "com.buildkite.docker_version") ]] ; then
echo -e ">> Checking docker client for ${DOCKER_IMAGE_NAME}"
docker run --rm --entrypoint "docker" "${DOCKER_IMAGE_NAME}" --version
Expand All @@ -41,7 +49,7 @@ if [[ -n $(docker_label $DOCKER_IMAGE_NAME "com.buildkite.docker_compose_version
docker run --rm --entrypoint "docker-compose" "${DOCKER_IMAGE_NAME}" --version
echo -e "\033[33;32mOk\033[0m"
else
echo -e ">>Skipping docker-compose checks"
echo -e ">> Skipping docker-compose checks"
fi

if [[ $(docker_label $DOCKER_IMAGE_NAME "com.buildkite.docker_dind") == "true" ]] ; then
Expand Down
4 changes: 3 additions & 1 deletion ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ ENV BUILDKITE_AGENT_VERSION=${BUILDKITE_AGENT_VERSION} \

COPY ./scripts/docker/entrypoint.sh ./assets/ssh-env-config.sh /usr/local/bin/
COPY ./assets/${BUILDKITE_AGENT_VERSION}-386 /buildkite
RUN ln -s /buildkite/buildkite-agent /usr/local/bin/buildkite-agent
RUN ln -s /buildkite/buildkite-agent /usr/local/bin/buildkite-agent \
&& adduser --system buildkite-agent \
&& chown -R buildkite-agent: /buildkite

ENTRYPOINT ["/usr/local/bin/tini", "-vg", "--", "/usr/local/bin/entrypoint.sh", "buildkite-agent"]
CMD ["start"]

0 comments on commit 5049404

Please sign in to comment.