Skip to content

Commit 957f1e0

Browse files
authored
Merge pull request #333 from infosiftr/su-noexec
Replace `su-exec` with `gosu`
2 parents 00027a1 + f44d7a0 commit 957f1e0

13 files changed

+158
-25
lines changed

5.0/alpine3.19/Dockerfile

+30-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.0/alpine3.19/docker-entrypoint.sh

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.0/alpine3.20/Dockerfile

+30-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.0/alpine3.20/docker-entrypoint.sh

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.0/bookworm/Dockerfile

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.1/alpine3.19/Dockerfile

+30-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.1/alpine3.19/docker-entrypoint.sh

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.1/alpine3.20/Dockerfile

+30-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.1/alpine3.20/docker-entrypoint.sh

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.1/bookworm/Dockerfile

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile-alpine.template

+32-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ RUN set -eux; \
1010
bash \
1111
ca-certificates \
1212
findutils \
13-
su-exec \
1413
tini \
1514
tzdata \
1615
wget \
@@ -28,6 +27,36 @@ RUN set -eux; \
2827
imagemagick \
2928
;
3029

30+
# grab gosu for easy step-down from root
31+
# https://github.com/tianon/gosu/releases
32+
ENV GOSU_VERSION 1.17
33+
RUN set -eux; \
34+
\
35+
apk add --no-cache --virtual .gosu-deps \
36+
ca-certificates \
37+
dpkg \
38+
gnupg \
39+
; \
40+
\
41+
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
42+
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
43+
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
44+
export GNUPGHOME="$(mktemp -d)"; \
45+
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
46+
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
47+
gpgconf --kill all; \
48+
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
49+
\
50+
apk del --no-network .gosu-deps; \
51+
\
52+
# smoke test
53+
chmod +x /usr/local/bin/gosu; \
54+
gosu --version; \
55+
gosu nobody true
56+
{{ if [ "5.0", "5.1" ] | index(env.version) then ( -}}
57+
RUN set -eux; ln -svf gosu /usr/local/bin/su-exec; su-exec nobody true # backwards compatibility (removed in Redmine 5.2+)
58+
{{ ) else "" end -}}
59+
3160
ENV RAILS_ENV production
3261
WORKDIR /usr/src/redmine
3362

@@ -75,7 +104,7 @@ RUN set -eux; \
75104
zlib-dev \
76105
; \
77106
\
78-
su-exec redmine bundle config --local without 'development test'; \
107+
gosu redmine bundle config --local without 'development test'; \
79108
# https://github.com/redmine/redmine/commit/23dc108e70a0794f444803ac827a690085dcd557
80109
# ("gem puma" already exists in the Gemfile, but under "group :test" and we want it all the time)
81110
puma="$(grep -E "^[[:space:]]*gem [:'\"]puma['\",[:space:]].*\$" Gemfile)"; \
@@ -87,7 +116,7 @@ RUN set -eux; \
87116
echo "$adapter:" >> ./config/database.yml; \
88117
echo " adapter: $adapter" >> ./config/database.yml; \
89118
done; \
90-
su-exec redmine bundle install --jobs "$(nproc)"; \
119+
gosu redmine bundle install --jobs "$(nproc)"; \
91120
rm ./config/database.yml; \
92121
# fix permissions for running as an arbitrary user
93122
chmod -R ugo=rwX Gemfile.lock "$GEM_HOME"; \

Dockerfile-debian.template

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ RUN set -eux; \
5858
gosu --version; \
5959
gosu nobody true
6060

61-
6261
ENV RAILS_ENV production
6362
WORKDIR /usr/src/redmine
6463

apply-templates.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,9 @@ for version; do
5353

5454
mkdir -p "$dir"
5555

56-
cp -f docker-entrypoint.sh "$dir/"
57-
5856
case "$variant" in
5957
alpine*)
6058
template='Dockerfile-alpine.template'
61-
sed -i -e 's/gosu/su-exec/g' "$dir/docker-entrypoint.sh"
6259
;;
6360
*)
6461
template='Dockerfile-debian.template'
@@ -69,5 +66,7 @@ for version; do
6966
generated_warning
7067
gawk -f "$jqt" "$template"
7168
} > "$dir/Dockerfile"
69+
70+
cp -a docker-entrypoint.sh "$dir/"
7271
done
7372
done

0 commit comments

Comments
 (0)