Skip to content

Commit 0b86094

Browse files
committed
fix: WORKDIR before adduser avoids surprises
The additions from `adduser` reading `/etc` does not appear to apply if the directory already exists, and permissions (including SGID) are adjusted properly for the home dir. This mean the excess backup copies in `/etc` are introduced again however.
1 parent 48c180d commit 0b86094

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

Dockerfile

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,14 @@ EOF
7070
FROM scratch
7171
ARG INSTALL_ROOT
7272
COPY --link --from=builder ${INSTALL_ROOT} /
73-
RUN <<EOF
74-
# Create user:
75-
echo 'testssl:x:1000:1000::/home/testssl:/bin/bash' >> /etc/passwd
76-
echo 'testssl:x:1000:' >> /etc/group
77-
echo 'testssl:!::0:::::' >> /etc/shadow
78-
79-
# Create user home with SGID set:
80-
install --mode 2755 --owner testssl --group testssl --directory /home/testssl
81-
82-
# Add relative symlink to point to content that will COPY later:
83-
ln -sr /home/testssl/testssl.sh /usr/local/bin/
73+
WORKDIR /home/testssl
74+
RUN --mount=type=bind,from=busybox:latest,source=/bin,target=/bin <<EOF
75+
/bin/adduser -D -s /bin/bash testssl
76+
/bin/ln -s /home/testssl/testssl.sh /usr/local/bin/
8477
EOF
8578

86-
USER testssl
87-
WORKDIR /home/testssl/
88-
8979
# Copy over build context (after filtered by .dockerignore): bin/ etc/ testssl.sh
9080
COPY --chown=testssl:testssl . /home/testssl/
91-
81+
USER testssl
9282
ENTRYPOINT ["testssl.sh"]
9383
CMD ["--help"]

0 commit comments

Comments
 (0)