Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A note about not running as root: In certain systems if you break out of the application and have access to a shell, it might already be game over. An attacker probably already has access to secrets, to the database, and all the assets worth protecting.

On the other hand, changing the docker user to non root might introduce some failure scenarios (eg file ownership) which might lead to other problems like availability incidents.

Security should start with threat modelling, and taking a risk-based approach. You can spend hours fearing that someone might break out of the Docker virtual machine through a zero day, instead of using that time to fix much more likely and plausible threat scenarios. Pick your battles.



> On the other hand, changing the docker user to non root might introduce some failure scenarios (eg file ownership)

If you application needs root to execute, with very few exceptions, it is already wrong.


Soooo... docker? haha

edit: I joke, I love what containers accomplish, and working with Docker has been a joy (:


That's why I don't use docker anymore. I build images using buildah and unprivileged containers.


If you are are writing the app, I agree with you. Unfortunately in some cases the person/team that wrote the app has been gone for a long time. I've even seen a case where the source code was missing and nobody knew where it was, yet the service had to continue running.

If you're in that boat, there isn't much you can do except work with it.


Agreed. But when copying files to docker and building the image, you will have to take care that files are not written with root ownership in any stage of the build, which would make them inaccessible to the application running as non root.

That's the case I had in mind when writing that quote.


> Agreed. But when copying files to docker and building the image, you will have to take care that files are not written with root ownership in any stage of the build, which would make them inaccessible to the application running as non root.

That's not the case, either. And root inside the container != root outside the container. A completely new user:group namespace is created inside the container. This is, in very large part, what Linux namespaces are for.

Further, you can certainly have a root-owned file accessible to non-root users, via chmod bits.

There are only a handful of excuses, ever, to run a privileged container. If you're not 100% sure, then it is not one of those excuses.


A completely new user:group namespace is created inside the container. This is, in very large part, what Linux namespaces are for.

No. root inside is root outside (if you can get outside). The behavior you describe only applies if you enable user namespace remapping, which docker doesn’t by default.


I'm actually running into this issue right now, in the context of a test that I'm writing. The test needs to copy some data out of an image. The image contains a full filesystem, and some of the files are read-only. The copy is done via docker cp, which requires elevated privileges on the host to copy read-only files (see https://github.com/moby/moby/issues/35987 for more info).

As a result, the test needs to be run using sudo to work correctly. The test environment is containerized, so there is a Dockerfile, but as the article mentioned the user in the container should not be root. Is there any plausible way around this? Updating the image is not under my control, and changing the copy code is also riskier than I would like.

Since this is in the context of CI, the threat is lower than live production, but still....




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: