-
Notifications
You must be signed in to change notification settings - Fork 77
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
Run as non-root inside container #104
Comments
Hi @hoshsadiq - my apologies for replying so late (been vacationing and otherwise distracted)! We actually originally did run as non-root by default, but simplicity we decided to drop that (see #24, and also #103 for some other related discussion). If your It's also worth noting that Finally, it's worth considering why you want to run as non-root. What attack vectors are you trying to avoid? Container escape vulnerabilities are pretty much the only real risk, but anyone running a modern Docker version is immune to many of them. It's also worth considering user namespace remapping as a mitigation. In my experience the main reason for running as non-root is to pass compliance checks - not a bad reason, but it's also worth recognizing that non-compliance does not automatically equal decreased security (and vice-versa). I will leave this open to discuss possibilities, but I think the starting point is probably to just provide some better documentation around running as non-root. |
Hi, In the company I work for, I am not allowed to run any docker container as root. It would be nice to use the Caddy in the same way: |
@hairyhenderson sorry, I had forgotten about this issue.
I'm aware of this. I didn't see an option to run caddy on a non-standard port, hence why I used setpcap. Maybe I was blind and/or I misunderstood. If you could let me know what that option is I'll gladly update my image.
While this is true, it's worth noting that Caddy does not have an option to delegate workers (I'm presuming requests run in go routines so that wouldn't even make sense). It is also impossible to run it as a non-root user using docker's (and docker-compose's) user arguments because the volumes
Definitely agree with this. I'm using caddy for a personal project, but I think running as non-root is a no-brainer for me considering it's such a trivial task that gives a lot with little effort. Though this is a personal preference, and isn't entirely based on any specific threat model, rather it's more of a precautionary issue. I think even if Caddy doesn't change the default, that would totally be okay, but making it easier for individual to run caddy in non-root mode, in my opinion is a must. As it stands, that is as simple as |
@hoshsadiq thanks for following up!
That's really just a matter of configuration. In the So a config like this should work for you (warning, I didn't have time to test this):
Then when you run the container, just map the ports appropriately: $ docker run -d -p 80:8080 -p 443:8443 ...
Sure, but that's if you want to use The reason I used So, if you choose to configure Caddy to use different data/config directories (which you'll have to if you're running as non-root), you'll need to make sure you use persisted volumes. Hope this helps! I'm definitely going to add some of this to the docs for the image on DockerHub, since most of this is definitely non-intuitive for people new to Caddy v2 😅 |
The process should not have write access to the config. More about not running as root here: #24 (comment) |
https://caddyserver.com/docs/conventions#configuration-directory Don't worry, Caddy never writes to your Caddyfile (unless you use the |
To clarify, the running config is stored in memory, so it would only be lost lost if the process or container was terminated. (Which, of course, happens all the time.) You're right, but I just wanted to make that distinction. |
Sorry for the late reply - again.
Aah, that is fair. I did not think of this, I'll use that. Also thanks for the config options for running on non-standard port, I don't know why, but I just did not find the options prior to you mentioning it. I'm more than happy for this issue to be closed as my issue is resolved, however, I think it's still worth changing the default container to being back run as a non-root user. Considering root inside a container is root outside a container (for docker anyway), this can be destructive if Caddy is compromised. Security should not be compromised on such a level for a little convenience. This should be okay once rootless becomes the norm, but currently the majority users, and production workloads are still running Docker, where all containers are root-full. Anyway, if there is no wiggle room, feel free to close this issue. I suppose if that's the case, documentation is key. |
Would it be an acceptable compromise for the official image to additionally install I've provided a pull-request which mitigates this issue, by making it possible to at least use the image with a different PID, given the user configures it in a compatible manner. |
Ah, yeah good idea @abjugard, that seems like a good approach. |
…g their own images to do it securely Mitigates caddyserver#104
…g their own images to do it securely Mitigates caddyserver#104
…g their own images to do it securely Mitigates caddyserver#104
…g their own images to do it securely Mitigates caddyserver#104
…g their own images to do it securely Mitigates caddyserver#104
…g their own images to do it securely Mitigates caddyserver#104
…g their own images to do it securely Mitigates caddyserver#104
Fixed in #274 - this'll be available in the next Caddy release |
Sorry for reviving a closed issue here but it seems there are capabilities to run this as non-root but although docs were called out in the issue description, I can't seem to find any docs related to how we can run this image as non-root Could you point me at the right location for the docs and I think it will help to have them linked here in the OG issue Appreciate the help! |
@julsemaan In general, to run a container as non-root, you just pass Some images (e.g., LinuxServer.io images) use environment variables like |
FWIW, once containerd 2.0 is out k8s and others that leverage that dependency are likely to adopt the same default that Docker has had for a while where the need for the setcap will be unnecessary: kubernetes/kubernetes#102612 (comment) That said, I do not like the
Just to clear up these two statements. Root in the container is not equivalent to root outside of the container. Yes they both share the same UID/GID, but the root user in the container is run in a namespace, there is isolation going on there, reduced capabilities is a good example of that. Regarding the statement about compromising security for convenience, that's technically what you get with As the linked comment of mine notes, the I ended up here looking for why/when the For reference it was part of the 2.6.3 release onwards (would be nicer if the repo actually used git tags for releases since the commit would also be associated to the eventual tagged release). |
Would be nice to have caddy run as a non-root user inside the container. This is especially useful for rootfull containers (e.g. Docker), where the uid=0 inside the container is the same as uid=0 outside. Additionally, since the
/data
dir and the/config
have been specified as aVOLUME
, others are unable to extend the container and change the ownership of those directories. I'm currently using the below Dockerfile to run caddy as a non-root user. I've changed it slightly to suit my needs but much of it should be re-usable for this repo.One thing worth considering is that this might be not be an easy upgrade for many, indeed, it may be that we'd need a temporary stop gap that runs the container as root, changes ownership of files/folders, then drops privileges. Then after perhaps a couple of versions, this stop gap can be replaced fully with a non-root user without going through the trouble of dropping privileges.
The text was updated successfully, but these errors were encountered: