-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically source the UID and GID when starting devcontainer on Linux #1155
Comments
@kkom Yeah this was something I was wondering about myself. I think if we did this, what we’d want to do is dynamically run the appropriate commands to add a non-root user during spin up of the container. We could add the concept of //cc: @chrmarti |
Thanks! Looking forward to that @Chuxel !
Nevermind, I didn't read the article carefully / test it on an actual Linux system. The same UID/GID is used inside and outside the container. I now understand the need to dynamically create the user with a specific UID/GID inside the container! This may become quite tricky for images where a specific user with very particular settings/permissions is created... |
@kkom Yeah, this is a specific behavior of Docker on Linux - the pro/con with Linux is its literally the file that is bound without any abstractions. This means perf is native, but the permissions map directly right down to the IDs. On Mac and Windows it goes through a filesystem abstraction so you don’t have the ID issue - but that adds overhead. I suppose we could allow you to specify a user to modify or create via some syntax. See if it exists, then tweak the UID/GID if so, otherwise create. (For the vscode-remote-try-node repo, the base node container has a |
Files keep their numeric UID/GID. So we might need to update existing files inside the container when we change an existing user/group's id. |
@Chuxel I'm adding I assume the Instead of having What about having a variable that is the local user's UID on Linux and empty on Mac and Windows? That can be used in other places in the devcontainer.json, e.g., in environment variables, E.g: That would avoid us having to change |
@chrmarti Yeah, here's how I was thinking that We have to use usermod / groupmod because of configuration files that can sit in the non-root user's home folder. We shouldn't create a new one if it already exists - like it does for node, R, and all of the dev containers in the vscode-dev-containers repo. This also has to happen before things like So I am thinking we would
On Alpine, we would need to verify the The update is what we're telling people to do for the node images right now. The fact this is basically needed 100% of the time on Linux is what makes me think it's important to support. As far as Mac and Windows go, WSL2 support in Docker is changing how bind mounts work so it's current behaviors will change. It's theoretically possible it will behave like Linux - I don't believe it does now, but if your mount point is in WSL2, it very well might. On macOS, it's not needed, but for consistency and debugging, it might be worth just sticking with the same code path in all three. If we did want to support being able to pass in a local UID/GID, I actually think supporting something like "$(id -u)" might be the right way to go since this also allows the execution of other things. We could scope it to the OS like |
That is making a few assumptions about the container ( |
@chrmarti The painful thing here is having to tweak something just to get up and running. We'd also be trying to make this easier for people who really don't understand all this detail so that the majority scenario is things work by default. In some cases, you may not have access to the original Dockerfile to add/modify a user when the build is not setup to do it or the user doesn't have access to modify the images that are generated. With #140, we're also now going to have base images that are pre-built with these UID/GIDs locked so it's immediately a user modification since config needs to land there as well. I'm also increasingly thinking about how VSO would be able to support some of this where things like runArgs wouldn't work and images are more likely to be pre-built or at least not rebuilt. Now, to be clear, we'd clearly let people just specify a user - this is "smart mode" where we do our best to get a good default. So the question is how we'd be able to enable this for the majority use cases. There's really two:
For the most part, if we don't do something here it just pushes it back into all 54 dev containers, samples, and docs. What would be better is if we can document how to resolve the exception cases - but the majority works. Right now the majority doesn't work. If you're worried about user 1000, we could tweak the syntax a bit so that someone could have more control. For example: "remoteUser": {
"name": "vscode", // default would be "vscode"
"uid": "${localUID}", // default would be 1000
"gid": "${localGID}", // default would be 1000,
"createIfMissing": false, // default would be true
"modifyIfExists": true, // default would be true
} Like I said, for Alpine, the Failing all that, I think it's totally ok to fail with a message saying the command is missing in the container. It should be a rare occurrence. |
What would How can we start the container with that user? Wouldn't we want to support passing the local UID as a build argument for that anyway? We could have a Dockerfile in each definition using that build argument to create the user in a distro specific way. (Creating a user is different on Alpine than on other distros, IIRC.) |
@chrmarti With WSL2 on Windows, it would be the WSL user which is 1000 by default. Generally, when in doubt, use 1000. :) Alpine is just missing adduser by default so you use useradd which isn’t as sophisticated. Useradd is also available on other distros - we could look into sticking with that. Unfortunately Alpine is missing usermod by default unlike the others. |
@chrmarti Oops forgot to respond to this part. Yeah, I was focusing on just what I'd been thinking on automatic - that is not a total fix and something that I'd assume we'd limited to (As an aside, for Perhaps the real full fix would be For automatic mode, I'm also thinking of all the feedback we've seen with existing Dockerfiles, external build systems where the user doesn't control, etc - places where our base definitions are not in use. It's just that #140 starts to introduce a similar problem for our own images - but the build system does inject Dockerfiles currently to the definitions to allow this to happen since there's no other option today. |
Ok, what about this (looking for simplicity and flexibility at the same time):
We'll do that with the following limitations:
That has several advantages:
|
@chrmarti Seems like a reasonable starting point. How different is Clearly the compose case came up in the discussions and attach has an open issue as well. (In fact, I think we heard about this first in those two scenarios.) |
@Chuxel I have |
Also adding a property |
Available in VS Code Insiders with the latest version of Remote-Containers (0.86.0). |
Hi, @chrmarti
But issue #1860 is exactly for the attach case. Would there be a future update to support this feature? |
I've tried the Remote-Containers (0.86.0).
The docker scripts looks like this: https://github.com/ApolloAuto/apollo/blob/r3.0.0/docker/scripts/dev_start.sh Any help or suggestion would be great. |
@MikeZhu92 I checked this works for me with the attach config. Please check the user exists and you picked the right config file (use |
Thank you @chrmarti for your help! |
@chrmarti Thanks for this very good news about "remoteUser". We were not able to use remote container because of this problem. Having the IDE creating files as root messed the permission inside the container. I got to 2 mains questions please: 1-
2- Side question please, why having choosed "remoteUser", instead of "execArgs" for instance (so consistant with runArgs, add more freely configurable) ? Thanks a lot for taking time on this issue, so important to make remote-container usable ! |
On 1: You will need to reload the VS Code window after adding On 2: This is the VS Code Server writing the files. The server runs under the We could still introduce |
Ok thanks for explaining this and helpful details about installation. |
Hey @Chuxel, thanks a lot for this example repo!
I have a question about the UID/GID settings mentioned here:
https://github.com/microsoft/vscode-remote-try-node/blob/07cbc3ee99d49b076ac46a85b1697efd1abc1841/.devcontainer/Dockerfile#L11-L16
https://github.com/microsoft/vscode-remote-try-node/blob/07cbc3ee99d49b076ac46a85b1697efd1abc1841/.devcontainer/devcontainer.json#L12-L14
Is it possible to set up VSCode to dynamically source these from the currently running user on the host machine?
The shell should normally be aware of them I think:
It would make the devcontainers really portable across users, which I think is the main reason for using them! :)
Best wishes,
Konrad
PS: CC @theomessin who was interested in that topic too
The text was updated successfully, but these errors were encountered: