Skip to content

Commit

Permalink
fix: cannot run sudo command in Devcontainer (#1879)
Browse files Browse the repository at this point in the history
The filenames in the sudoers.d directory cannot contain '~' and '.'. In previous Devcontainer, if a username contains a ., it cannot be granted root permissions as the filename generated is not effective.
Ref: https://superuser.com/questions/869144/why-does-the-system-have-etc-sudoers-d-how-should-i-edit-it
  • Loading branch information
bilosikia authored Jan 16, 2025
1 parent 0885bb8 commit ec008e1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ RUN source /tmp/.env && rm /tmp/.env; \
fi; \
useradd --uid $USER_UID --gid $GROUP_GID -m $USERNAME; \
if [ -n "$USER_PASSWORD" ]; then echo "$USERNAME:$USER_PASSWORD" | chpasswd; fi; \
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME; \
chmod 0440 /etc/sudoers.d/$USERNAME; \
# the filename should not have the . or ~ symbol.
USER_SUDOER_FILE=$(echo $USERNAME | sed 's/\./-/g'); \
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER_SUDOER_FILE; \
chmod 0440 /etc/sudoers.d/$USER_SUDOER_FILE; \
chown -R $USERNAME:$GROUPNAME /opt $(eval echo ~$USERNAME); \
chmod -R 755 $(eval echo ~$USERNAME);

USER $USERNAME

RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct
RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct

0 comments on commit ec008e1

Please sign in to comment.