From f011970b38338d941d85d12bf04550378415cc81 Mon Sep 17 00:00:00 2001 From: JeremyTubongbanua Date: Tue, 23 May 2023 22:34:07 -0400 Subject: [PATCH 1/3] feat: use `USER` env var in `Dockerfile` --- Dockerfile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0c7a14d12..bd9e34d6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,24 +10,25 @@ RUN \ # Second stage of build FROM debian-slim FROM debian:stable-20230522-slim@sha256:d828cca5497a2519da9c6d42372066895fa28a69f1e8a46a38ce8f750bd2adf0 -ENV HOMEDIR=/atsign +ENV USER=atsign +ENV HOMEDIR=/$USER ENV BINARYDIR=/usr/local/at ENV USER_ID=1024 ENV GROUP_ID=1024 -COPY --from=buildimage /app/.startup.sh /atsign/ +COPY --from=buildimage /app/.startup.sh /$USER/ RUN apt-get update && apt-get install -y openssh-server sudo iputils-ping iproute2 ncat telnet net-tools nmap iperf3 tmux traceroute vim;\ - addgroup --gid $GROUP_ID atsign ; \ + addgroup --gid $GROUP_ID $USER ; \ sysctl -w net.ipv4.ping_group_range="0 1024" ; \ - useradd --system --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --home $HOMEDIR atsign ; \ + useradd --system --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --home $HOMEDIR $USER ; \ mkdir -p $HOMEDIR/.atsign/keys ; \ mkdir -p $HOMEDIR/.ssh ; \ touch $HOMEDIR/.ssh/authorized_keys ; \ - chown -R atsign:atsign $HOMEDIR ; \ + chown -R $USER:$USER $HOMEDIR ; \ chmod 600 $HOMEDIR/.ssh/authorized_keys ; \ - usermod -aG sudo atsign ; \ + usermod -aG sudo $USER ; \ mkdir /run/sshd ; \ - chmod 755 /atsign/.startup.sh -COPY --from=buildimage --chown=atsign:atsign /usr/local/at/sshnpd /usr/local/at/ -WORKDIR /atsign + chmod 755 /$USER/.startup.sh +COPY --from=buildimage --chown=$USER:$USER /usr/local/at/sshnpd /usr/local/at/ +WORKDIR /$USER # USER atsign -ENTRYPOINT ["/atsign/.startup.sh"] +ENTRYPOINT ["/$USER/.startup.sh"] From e4d3f96dd6725934df29dee2103952fdde1cae20 Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Wed, 24 May 2023 11:01:58 +0100 Subject: [PATCH 2/3] chore: Bracing of ENV variables --- Dockerfile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index bd9e34d6f..08bbe40b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,32 +3,32 @@ ENV BINARYDIR=/usr/local/at WORKDIR /app COPY . . RUN \ - mkdir -p $BINARYDIR ; \ + mkdir -p ${BINARYDIR} ; \ dart pub get ; \ dart pub update ; \ - dart compile exe bin/sshnpd.dart -o $BINARYDIR/sshnpd + dart compile exe bin/sshnpd.dart -o ${BINARYDIR}/sshnpd # Second stage of build FROM debian-slim FROM debian:stable-20230522-slim@sha256:d828cca5497a2519da9c6d42372066895fa28a69f1e8a46a38ce8f750bd2adf0 ENV USER=atsign -ENV HOMEDIR=/$USER +ENV HOMEDIR=/${USER} ENV BINARYDIR=/usr/local/at ENV USER_ID=1024 ENV GROUP_ID=1024 -COPY --from=buildimage /app/.startup.sh /$USER/ +COPY --from=buildimage /app/.startup.sh ${HOMEDIR}/ RUN apt-get update && apt-get install -y openssh-server sudo iputils-ping iproute2 ncat telnet net-tools nmap iperf3 tmux traceroute vim;\ - addgroup --gid $GROUP_ID $USER ; \ + addgroup --gid ${GROUP_ID} ${USER} ; \ sysctl -w net.ipv4.ping_group_range="0 1024" ; \ - useradd --system --uid $USER_ID --gid $GROUP_ID --shell /bin/bash --home $HOMEDIR $USER ; \ - mkdir -p $HOMEDIR/.atsign/keys ; \ - mkdir -p $HOMEDIR/.ssh ; \ - touch $HOMEDIR/.ssh/authorized_keys ; \ - chown -R $USER:$USER $HOMEDIR ; \ - chmod 600 $HOMEDIR/.ssh/authorized_keys ; \ - usermod -aG sudo $USER ; \ + useradd --system --uid ${USER_ID} --gid ${GROUP_ID} --shell /bin/bash --home ${HOMEDIR} ${USER} ; \ + mkdir -p ${HOMEDIR}/.atsign/keys ; \ + mkdir -p ${HOMEDIR}/.ssh ; \ + touch ${HOMEDIR}/.ssh/authorized_keys ; \ + chown -R ${USER}:${USER} ${HOMEDIR} ; \ + chmod 600 ${HOMEDIR}/.ssh/authorized_keys ; \ + usermod -aG sudo ${USER} ; \ mkdir /run/sshd ; \ - chmod 755 /$USER/.startup.sh -COPY --from=buildimage --chown=$USER:$USER /usr/local/at/sshnpd /usr/local/at/ -WORKDIR /$USER + chmod 755 /${USER}/.startup.sh +COPY --from=buildimage --chown=${USER}:${USER} /usr/local/at/sshnpd /usr/local/at/ +WORKDIR ${HOMEDIR} # USER atsign -ENTRYPOINT ["/$USER/.startup.sh"] +ENTRYPOINT ["/${USER}/.startup.sh"] From 8aab0f23bf944a4eed796fe1b491518777e8df1f Mon Sep 17 00:00:00 2001 From: Chris Swan <478926+cpswan@users.noreply.github.com> Date: Wed, 24 May 2023 14:50:17 +0100 Subject: [PATCH 3/3] fix: Don't use an ENV variable inside ENTRYPOINT --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 08bbe40b6..0e8bd4d9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,4 +31,4 @@ RUN apt-get update && apt-get install -y openssh-server sudo iputils-ping iprout COPY --from=buildimage --chown=${USER}:${USER} /usr/local/at/sshnpd /usr/local/at/ WORKDIR ${HOMEDIR} # USER atsign -ENTRYPOINT ["/${USER}/.startup.sh"] +ENTRYPOINT ["/atsign/.startup.sh"]