From 44c7c161acde8e652fd2e788a6a4cdd4db5db941 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Tue, 24 Apr 2018 18:23:46 +0300 Subject: [PATCH] Docker run-as imporovements. - Remove hard-coded dependency on /volume location, use working directory instead. - Assorted small changes. --- content/docker_uid.rst | 6 +++--- content/static/runas-busybox | 2 +- content/static/runas-gnu | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/content/docker_uid.rst b/content/docker_uid.rst index ab8e789..36dea6d 100644 --- a/content/docker_uid.rst +++ b/content/docker_uid.rst @@ -42,7 +42,7 @@ commands. uid="$(stat . --format '%u')" gid="$(stat . --format '%g')" groupadd --force --non-unique --gid "$gid" builder - useradd --non-unique --uid "$uid" --gid "$gid" --home-dir /volume --no-create-home --shell /bin/bash builder + useradd --non-unique --uid "$uid" --gid "$gid" --home-dir "$PWD" --no-create-home --shell /bin/bash builder sudo -Eu "#$uid" -g "#$gid" -- "$@" The script is also available for `download @@ -55,9 +55,9 @@ into your Dockerfile, or download it via the :code:`ADD` directive, like so: .. code:: shell FROM debian:stable - RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y sudo build-essential - ADD [ "https://www.shore.co.il/blog/static/runas-gnu", "/entrypoint"] + ADD [ "https://www.shore.co.il/blog/static/runas-gnu", "/entrypoint" ] ENTRYPOINT [ "/bin/sh", "/entrypoint" ] VOLUME /volume WORKDIR /volume diff --git a/content/static/runas-busybox b/content/static/runas-busybox index 01b3f7d..74f92d3 100755 --- a/content/static/runas-busybox +++ b/content/static/runas-busybox @@ -4,5 +4,5 @@ command -v sudo > /dev/null || { echo "Can't find sudo, exiting."; exit 1; } uid="$(stat . -c '%u')" gid="$(stat . -c '%g')" addgroup -g "$gid" builder -adduser -h /volume -s /bin/sh -G builder -u "$uid" -H -D builder +adduser -h "$PWD" -s /bin/sh -G builder -u "$uid" -H -D builder sudo -Eu "#$uid" -g "#$gid" -- "$@" diff --git a/content/static/runas-gnu b/content/static/runas-gnu index a78926a..d3dd2f7 100755 --- a/content/static/runas-gnu +++ b/content/static/runas-gnu @@ -4,5 +4,5 @@ command -v sudo > /dev/null || { echo "Can't find sudo, exiting."; exit 1; } uid="$(stat . --format '%u')" gid="$(stat . --format '%g')" groupadd --force --non-unique --gid "$gid" builder -useradd --non-unique --uid "$uid" --gid "$gid" --home-dir /volume --no-create-home --shell /bin/bash builder +useradd --non-unique --uid "$uid" --gid "$gid" --home-dir "$PWD" --no-create-home --shell /bin/bash builder sudo -Eu "#$uid" -g "#$gid" -- "$@" -- GitLab