devcontainers / devcontainers/features

[Feature Request][common-utils]: add updateUsername option to common-utils feature

Open
#540 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
1.5k
Forks
621
Avg merge
2d 11h
Merged PRs (30d)
4

Description

As per the comment in #535.

Add an `updateUsername` option that will update the users username based on the UID.

`updateUsername` bool Updates the username of the user who has the UID of `userUid` to the value contained in `username`. Default `false`

---------
*edit*

thinking about this more, a better way to think about using this role is to separate out the userIdMode from the logic of the update or add. This would make the role work in two steps.

1. Identify the user by 'userIdMode'
2. Update or create user based on presence using 'userIdMode'.

Where 'userIdMode' is one of UID, ausername, or auto/automatic.

If the user exists, then the role updates, if not it adds.

It might be worth setting defaults to assume that the 'userIdMode' is UID and the default UID is 1000 so that the role works as expected on a second run if the user wants a different username. I'm kind of assuming a different username is the more likely scenario and that the user will use the base images that create a user with UID of 1000. Maybe somebody will say that isn't the best assumption.

It might also be worth adding multiple options for UID and GID so the vscode wizard can add or edit the existing users. Probably 1000 & 1001 and 1002. It might be a bug in the GitHub devcontainers vscode implementation that users can't manually set a value, or maybe that is intentional as part of the devcontainers spec. I'm not sure if 'option' the word necessarily implies 'every possible value' and actually I'm pretty sure it doesn't, but I'm not too familiar with the spec.

Anyway, I think we've Zuckerberg'd [TM, patent pending, lolol] this pretty well. With the issues I've created and comments we can probably move all user related activities into a separate feature 'users' feature, I'm not stuck on the name so feel free to suggest alternatives, that is well documented and specified.

I'll probably work on this in the near future, but if somebody has already done it or is currently doing it let me know so I don't duplicate work. For all I know somebody could do this while I'm in a meeting now... So if anybody wanted to know what I'm planning on doing, all they'd have to do is follow my GitHub account. :) Yup.

*end edit*

--------

The way the feature currently works is that it will create a new user if the username is not already on the system and modifies the user otherwise, setting the UID, GID, etc. The new implementation would allow users to update the username if the UID is present on the system. Possibly also update the GID if desired by the implementers.

TODO: confirm behavior for automatic mode.
The behavior is the same regardless of the way username is determined.
https://github.com/devcontainers/features/blob/main/src/common-utils/main.sh#L345

I think what automatic tries to do is to sync the username with the remote username if it isn't root and tries to find one of the 'option' usernames if it is root and then uses vscode if it can't find an existing option user.
https://github.com/devcontainers/features/blob/main/src/common-utils/main.sh#L323

```
It might be worth adding a `modifyUsername` parameter so that users can update the username instead of assume the intention is to create a new user when the username doesn't match the username of the base image.

_Originally posted by @raymond-chetty in https://github.com/devcontainers/features/pull/535#discussion_r1181121433_
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.