When running the tests locally, they must be started as root, as the volume mappings are written to by a root user from inside the container. This requires all commands from the makefile and tests to be run as root and reduces the security inside the container.
The container does not run the processes as a privileged user.
Don't map the folders but copy them using docker cp. This requires explicit syncing, when some file is changed.
Not running under root should improve the overall security and ease the development of tests. (I often forget to prepend sudo when running them.)
I like this, but docker is root-equivalent, so in practice there is no major difference. It would be nice to skip the sudo though!
@erik-wramner is correct. But I'm all for this too. How can we go about this?
but docker is root-equivalent, so in practice there is no major difference
I beg to differ. See for example: https://pythonspeed.com/articles/root-capabilities-docker-security/
I am no security specialist but running as root inside the container increases the probability of breaking out into root on the host.
Anyways, since there are no objections for other reasons, my plan would be as follows:
access denied on the old, root owned, configuration filesRegarding the initial motivation of getting the test mapping root free: Am I right in the assumption that writing to the config volumes is mostly done by our own configuration scripts? If so, that would be a good place to start as we have the most control over them.
I beg to differ. See for example: https://pythonspeed.com/articles/root-capabilities-docker-security/
The vulnerability it links to was patched. Running as a non-root user was only one mitigation, it could also be avoided with user namespace remapping (can run as root within the container but is treated as a different UID on the host), among several other options.
More importantly, the only mentioned avenue of attack was the system already deployed a malicious image or a malicious service running as root was being run to carry out the exploit.
Beyond that, an attack would first need to breach access into the container, and that's the more realistic attack vector to consider that this project and the user deploying the image would be more responsible over and able to control (vs upstream images/software being compromised).
I am no security specialist but running as root inside the container increases the probability of breaking out into root on the host.
Somewhat, yes. I can better avoid the rare chances of a fatal accident from a car accident or plane crash if I stay indoors. It'd be rather paranoid and inconvenient though wouldn't it?
This describes the minimal benefit from running Postfix daemon as non-root (unrelated to Docker).
Don't get me wrong, I'm all for improving security when it's practical. I'm just concerned about how disruptive of a change that might be for this particular project. It may be well meant, but if it's security for the sake of it and requires technical debt negatively impacting maintenance and support or worse introducing bugs / failures due to assumptions... I'm not in support of that :-1:
For example, let's just consider the ports we use. Won't this change require them to be replaced with ports beyond the 1024 range?
/etc/services, were you aware of this? (if not, would you likely have missed it and could it have silently introduced a difficult to track bug, what other unknowns might be involved with a project of this scope?)/etc/services contents can vary for example, as can UID/GID mappings (as can the related utilities and file hierarchy IIRC). Alpine is commonly found to trip up users due to it's usage of musl, but the UID/GID differences I've found to vary across OpenSUSE, Debian, Fedora, Ubuntu, which tripped me up years ago with a Docker image targeting specific standard user/groups (they just had different IDs or name variations). This is a minor issue, but the project has changed base image in the past, so any system level changes should be well documented for future maintenance. It's unlikely any potential updates to such files being overwritten/modified by the project will cause problems, but it's a possibility.I assume you'd need to take into consideration user supplied files too:
If the changes to support non-root running processes is not going to be invasive by deviating from upstream and standard ports, great, bring it on :+1:
Otherwise, I would like you to really consider the actual value of what is being proposed. For example chasing scores/grades from testssl.sh or Qualys SSL test reports without understanding when it's overkill often brings notable disadvantages, while a non-perfect rating can be plenty secure, despite certain penalties that a tool may raise but don't actually apply or aren't feasible / practical to carry out on just anyone.
We've had some misinformation cited from contributors in this project in the past to explain why cipher suite capability for some macOS/iOS clients ended up broken (which happened more than once from updates that were only security focused, but not well informed). I have preference towards proper justification for changes where possible, sometimes sources are parroting "better safe than sorry" reasons (not referring to your linked resource, but it's a common sight with some blogs on configuring software without properly understanding it).
I'd expect for some valid examples / frequency of Docker containers being breached to perform such exploits in the first place (in particular, those that would present actual risk to this project). Unless you're being specifically targeted, generally the risk isn't as bad as implied.
A better direction might be splitting services out into separate containers, but I think having it all in one deployable image is what users often choose this project for over alternatives that already take the modular approach.
I think the README/Wiki shows configs to run the project with two capabilities added NET_ADMIN(Fail2Ban) and SYS_PTRACE (Not sure about this one?), but splitting that service out to a separate container would complicate things and many users may update without noticing that it needs to be deployed separately.
Perhaps as the official Docker docs for USER suggest, you can still run things as root and drop privileges with gosu in the entrypoint / startmailserver.sh script?
Hmm, I guess what @polarathene describes here makes sense. I haven't read through all the links you mentioned, but the detailed explanation makes everything clear, I guess.
Perhaps as the official Docker docs for USER suggest, you can still run things as root and drop privileges with gosu in the entrypoint / startmailserver.sh script?
This would be worth investigating.
Thanks for the feedback @polarathene. As I said above
I am no security specialist
May main motivation was stated upfront:
When running the tests locally, they must be started as root, as the volume mappings are written to by a root user from inside the container.
This makes test development painful, as forgetting to run everything in sudo can lead to non obvious errors. I just raised the security issues as an additional potential benefit.
Don't get me wrong, I'm all for improving security when it's practical.
I am with you that the measures should have an appropriate cost/benefit ratio and I already alluded to potential pitfalls with the file access rights.
So in summary I would say: We should find ways to fix the test issues without requiring everything to migrate away from root, because that might be too heavy handed.
I think there are two different things here:
My comment was about the second. If your host account can run docker commands, then it is root equivalent. It is still nice to be able to skip the sudo commands, but there is no real security benefit.
As for running the services as non-privileged accounts that would really be a security improvement, but I don't think it is easy.
Most helpful comment
Thanks for the feedback @polarathene. As I said above
May main motivation was stated upfront:
This makes test development painful, as forgetting to run everything in
sudocan lead to non obvious errors. I just raised the security issues as an additional potential benefit.I am with you that the measures should have an appropriate cost/benefit ratio and I already alluded to potential pitfalls with the file access rights.
So in summary I would say: We should find ways to fix the test issues without requiring everything to migrate away from root, because that might be too heavy handed.