-
Notifications
You must be signed in to change notification settings - Fork 532
Description
When building a Dev Container on top of a base image that already defines a non-root user whose primary group name differs from the username, the common-utils feature fails with a chown error during installation. This happens because the feature hard-codes group_name="${USERNAME}" and later runs chown ${USERNAME}:${USERNAME}, even if the user’s primary group is different.
Example context:
In my Dockerfile I pre-create the development user before features run:
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=100
RUN groupadd --gid $USER_GID users \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
This results in vscode:users, where users (GID 100) already exists in the base image.
When common-utils runs, it tries to ensure ownership with chown vscode:vscode, producing:
chown: invalid group: 'vscode:vscode'
ERROR: Feature "Common Utilities" failed to install!
Root cause:
install.sh assumes that ${USERNAME} and the user’s primary group name are identical. When a user already exists with a differing group name, the feature tries to create or modify a conflicting group and later chowns to a non-existent vscode group.
Expected behavior:
If the user already exists, the script should:
- Detect the actual primary group via id -gn "$USERNAME", and
- Use that value for group_name and subsequent chown operations instead of assuming ${USERNAME}.
Proposed fix:
Replace the current unconditional group_name="${USERNAME}" assignment with something like:
group_name="$(id -gn "$USERNAME" 2>/dev/null || echo "$USERNAME")"
and skip groupadd/groupmod if that group already exists.
This would make the feature compatible with base images that already define non-root users.