-
Notifications
You must be signed in to change notification settings - Fork 302
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
Docker Feature: "postCreateUser" to specify user during "postCreateCommand" #3283
Comments
@chrmarti Would you already know if this is added to the (short-term) roadmap? |
No, not currently. We have a fix for this when you run VS Code on Linux and connect to a local container ( |
Has the usage of |
Unfortunately not, no. Have you tried running the user_mapping.sh as part of the Dockerfile? You can use |
Building our docker takes about 30 minutes on our, rather powerful, build server. This is controlled by a Jenkins pipeline and the result is pushed to JFrog artifactory. Our .devcontainer.json is pulling this image from artifactory. Building the docker locally is not really an option. So what we need is 'some way' to start the container (as root) execute a command (to install the user) and from there on continue... At some point I thought that the 'initializeCommand' could help us, but this is executed before the container is created... We would need something to be executed (as root) just after the point where the container is created. |
@diricxbart What do you mean when saying "Container is created"? Docker image create as a part of docker build or Docker container create as a part of the docker run command. I suppose, docker container create. At this moment entry point script or program is executed as it is defined in CMD and ENTRYPOINT directives of the dockerfile. VSCode has nothing to do with it because VSCode is neither container builder nor container runner. Docker container is not EXE or VM to execute a kind of user login. All its resources including users and access control it borrows from the host OS/VM on which the Docker engine runs. The creation of a new user during the container lifetime means a violation of the container isolation principle. Running a container with the default root user means that the container has unrestricted access to the host resources. |
@diricxbart You can build the image on the build server and then pull it in with a Dockerfile that only runs your user_mapping.sh. |
@diricxbart All additional users except root have to be added to the image, not the container on the build server using useradd. The USER command doesn't create a user. The developer can set a default user to run the first process with the Dockerfile USER instruction. When starting a container, the operator can override the USER instruction by passing the -u option with docker run command explicitly. -u="", --user="": Sets the username or UID used and optionally the groupname or GID for the specified command. The followings examples are all valid: |
The "custom_user" that I'm referring to above is added to the container image, indeed using useradd:
With What we then want to accomplish is to be able to run this container as user "custom_user", but with the The reason for this is that we use volume mounts to access specific (sensitive) data, for which access permissions are linked to the user. If "custom_user" inside the docker container uses the uid/gid of the user outside of the container, than we can R/W the data with the permissions of this user. I don't think that the -u flag supports running as a "custom_user" with the User/Group ID of the user on the shared server (id -u / id -g output), correct? If there's a way to accomplish the same without the post-create command, then I of course want to explore this... @chrmarti That could indeed be done locally, an option to consider... |
@chrmarti I gave your suggestion a try and this is indeed working! Some details: I created a Dockerfile containing:
Then I modified the .devcontainer.json:
All seems to work as expected ( Just an idea: if other people would need similar functionality, it might be interesting to have VSCode do all this for you. To add a command like For me this feature request can be closed (unless you prefer to keep it open for the "installUser" idea)... |
Thanks for the feedback @diricxbart! Closing, I suggest to open new issues for any remaining feature requests to keep the discussions separate. |
Security consideration: be careful with USER in the dockerfile: the stolen using docker pull image will mean the stolen user. It can't belong to any powerful group. Such a container can be stored only locally or local registry. The "testuser" deafult value is common |
Feature request
Allow to specify a user, using a new "postCreateUser" setting, which is used to execute the "postCreateCommand".
This user may be a different user then the "remoteUser" or the "containerUser".
This would allow to connect to the container remotely using the "postCreateUser", execute the "postCreateCommand" and next connect to the container using the "remoteUser".
Example use case
The use case for this is the following:
ssh remote_server_name -L localhost:2375:/var/run/docker.sock -N
In this setup we first want to map the 'custom_user' to the correct UID and GID of the user in the Linux server.
However changing the UID and GID requires 'root' permissions (or sudo). And editing files in VSCode as root, screws up the file permissions. Alternative might be changing UID and GID using 'custom_user' and sudo, but also here experiments have shown that changing the UID / GID of the active connected user also corrupts things.
As a fix for this, we would like to first execute a "postCreateCommand" which changes the UID and GID, while specifying the "postCreateUser" as "root". Next we would want the 'regular' VSCode connection to be made using the user 'custom_user', with the correct UID and GID.
We would specify the following in our devcontainer.json:
In the Docker image $USER would be set to "custom_user" and the following /user_mapping.sh would also be present:
This was originally requested here, but has now been moved into a dedicated feature request upon request of @chrmarti .
The text was updated successfully, but these errors were encountered: