Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fe9eaef

Browse files
authoredMay 9, 2021
Check the logged user instead of $USER
Given that `sudo usermod --login "$DOCKER_USER" coder` and `sudo groupmod -n "$DOCKER_USER" coder` modify the container's disk it'll persist across restarts, but environment variables will be reset to whatever state they had at the end of `Dockerfile`. In this case, `$USER` is set to `coder`, so this branch will always be true. By checking with the output of `whoami`, which gets it's information from `/etc/passwd`, we make sure to get the real logged user and not the one defined by $USER. We also move `USER="$DOCKER_USER"` out of the branch, since we always want this to happen at entry-point. If we don't do this assignment, $USER will contain `coder` upon restart.
1 parent 02a0e05 commit fe9eaef

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎ci/release-image/entrypoint.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ set -eu
55
# Otherwise the current container UID may not exist in the passwd database.
66
eval "$(fixuid -q)"
77

8-
if [ "${DOCKER_USER-}" ] && [ "$DOCKER_USER" != "$USER" ]; then
8+
USER="$DOCKER_USER"
9+
10+
if [ "${DOCKER_USER-}" ] && [ "$DOCKER_USER" != "$(whoami)" ]; then
911
echo "$DOCKER_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/nopasswd >/dev/null
1012
# Unfortunately we cannot change $HOME as we cannot move any bind mounts
1113
# nor can we bind mount $HOME into a new home as that requires a privileged container.
1214
sudo usermod --login "$DOCKER_USER" coder
1315
sudo groupmod -n "$DOCKER_USER" coder
1416

15-
USER="$DOCKER_USER"
16-
1717
sudo sed -i "/coder/d" /etc/sudoers.d/nopasswd
1818
fi
1919

0 commit comments

Comments
 (0)
Please sign in to comment.