devcontainers-contrib / features

🐳 Extra add-in features for Devcontainers and GitHub Codespaces
MIT License
214 stars 108 forks source link

zsh-plugin not working in combination with non-root container-user #579

Open schoelst opened 4 months ago

schoelst commented 4 months ago

Feature id and version

ghcr.io/devcontainers-contrib/features/zsh-plugins:0.0.4

Devcontainer base Image

python:3.10

What happened?

If I set the containerUser and remoteUser to vscode the zsh-plugin stops working. The default shell is set to zsh and oh-my-zsh and the .zshrc seem to be set up correctly, however, with the wrong user rights (root, see output). A re-owning at the end of the install script should solve the matter.

For the sake of completeness I create the vscode user like so (extract from Dockerfile):

ARG USERNAME=vscode
ARG USER_UID=1001
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    # Add sudo support.
    && apt-get update \
    && apt-get install -y sudo \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME

Also the location of the home dir is derived in a fragile manner in the install script (/home/$USERNAME) consider reading its location from the users $HOME.

Relevant log output

9bbbba51e624% pwd
/home/vscode
9bbbba51e624% ls -lha
total 16K
drwxr-xr-x. 1 vscode vscode  175 Feb 12 08:14 .
drwxr-xr-x. 1 root   root     20 Feb 12 08:13 ..
-rw-r--r--. 1 vscode vscode  220 Apr 23  2023 .bash_logout
-rw-r--r--. 1 vscode vscode 3.5K Apr 23  2023 .bashrc
drwxr-xr-x. 3 vscode vscode   24 Feb 12 08:13 .cache
drwxr-xr-x. 2 vscode vscode   37 Feb 12 08:14 .dbclient
drwxr-xr-x. 2 vscode vscode  103 Feb 12 08:13 .devcontainer
-rw-r--r--. 1 vscode vscode  299 Feb 12 08:13 .gitconfig
drwx------. 2 vscode vscode   82 Feb 12 08:13 .gnupg
drwxr-xr-x. 3 root   root     20 Feb 12 08:13 .oh-my-zsh
-rw-r--r--. 1 vscode vscode  807 Apr 23  2023 .profile
drwxr-xr-x. 2 vscode vscode   25 Feb 12 08:13 .ssh
drwxr-xr-x. 6 vscode vscode   70 Feb 12 08:13 .vscode-server
-rw-r--r--. 1 root   root      0 Feb 12 08:13 .zshrc

EDIT: Adjusted command used to create vscode user.

schoelst commented 4 months ago

Here is my work around: After adding the following to my devcontainers.json it works now:

"postCreateCommand": " sudo cp /root/.zshrc /home/vscode && sudo cp -r /root/.oh-my-zsh /home/vscode && sudo chown -R vscode:vscode /home/vscode"