Dev Docker container runs as root
The dev container now seems like running as root:
e.g. Inside VS Code's terminal:
Running inside Docker containers as a non-root user is generally recommended for increased security (1, 2).
Here, in the case of the dev container, I can think of 2 drawbacks of running as root:
- less security, especially when running Docker on a remote server.
- inconvenient file ownership on local files created by the dev container on POSIX systems (macOS, Linux/WSL).
In previous (cookiecutter) versions of this template, the dev container was running as UID 1000 thanks to a USER user instruction at the end of image build. It seems like the current version runs as root (UID=0).
This adds inconvenience for the user, when for instance you try to rm -rf some-project that was created by Substrate as a regular user, you get a denied permission because various files it contains that were created by the tools running inside the dev container got created as root (UID 0). The files created become impossible to delete without root permission.
Example files that get created with the root permission:
I would recommend getting the local user's UID in the dev container Dockerfile and use that same UID in the container for convenient permissions when files get written to the workspace (which is a mounted local directory).
Hi @vanolucas, first off thank you for reporting this!
Indeed, we now act as the root user, but only inside the dev container. For app images, we still create a dedicated non-root user, specifically for security as you mention. The move away from a non-root user for dev containers is intended to simplify the dev target in the Dockerfile, which had a lot of setup specifically to accommodate the fact that we are a root user (creating the user & homedir, giving permissions, installing sudo and adding to the sudoers file, ...), which is now no longer necessary.
As to the file ownership issues, I haven't faced them yet myself. I tried to reproduce your issue by creating a new project from within a dev container (as root). Inside the dev container, I see ownership root-root just like you, but from outside the dev container, the ownership is still fully mine, and I'm free to do anything with that directory. For reference, I am running macOS, but I suspect you're using WSL based on your screenshot. I'll investigate if I can reproduce your issue there!
@sinopeus, thanks for clarifying!
I confirm screenshots are while running on WSL, with Docker Desktop installed on Windows 11 (v4.34.2). I guess in this implementation, Docker runs as root by default, which might not be the case on macOS or on newer versions of Docker Desktop. Something to look into.
Just realised, I also got the same issue when running Docker Engine on a fresh Debian 12, so this is not just happening on WSL/Docker Desktop/Windows.
Should be solved with v1.2.0!