-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Caddy: Added NET_BIND_SERVICE note #2620
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
base: master
Are you sure you want to change the base?
Caddy: Added NET_BIND_SERVICE note #2620
Conversation
d4bfda3
to
b198010
Compare
cc (see also moby/moby#41030, which adjusted |
We added that in 2023 @tianon, it was necessary for certain users who wanted to run the container as non-root, I think. Added in caddyserver/caddy-docker@b650917, issue for context: caddyserver/caddy-docker#104 (comment) I don't really understand all the nuances here, maybe you could clarify with that context in mind 🤔 |
At that time, I don't think this change had made its way into the common Kubernetes runtimes, and I believe that's changed now, but worth confirming. In other words, for the majority of use cases in containers now, "privileged ports" shouldn't be a thing, and any port should be usable regardless of the UID the container is running as (and that's safe due to the inherent isolation that is a network namespace). In other words, I don't think |
To illustrate further, with just Docker: $ docker run -it --rm --user 1000:1000 --cap-drop NET_BIND_SERVICE --name test "$(docker build -q - <<<$'FROM caddy\nRUN setcap cap_net_bind_service=-ep /usr/bin/caddy')"
2025/09/02 21:26:58.562 INFO maxprocs: Leaving GOMAXPROCS=16: CPU quota undefined
2025/09/02 21:26:58.562 INFO GOMEMLIMIT is updated {"package": "github.com/KimMachineGun/automemlimit/memlimit", "GOMEMLIMIT": 60335323545, "previous": 9223372036854775807}
2025/09/02 21:26:58.562 INFO using config from file {"file": "/etc/caddy/Caddyfile"}
2025/09/02 21:26:58.563 INFO adapted config to JSON {"adapter": "caddyfile"}
2025/09/02 21:26:58.563 INFO admin admin endpoint started {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2025/09/02 21:26:58.564 WARN http.auto_https server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "srv0", "http_port": 80}
2025/09/02 21:26:58.564 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0xc0006d6400"}
2025/09/02 21:26:58.564 WARN http HTTP/2 skipped because it requires TLS {"network": "tcp", "addr": ":80"}
2025/09/02 21:26:58.564 WARN http HTTP/3 skipped because it requires TLS {"network": "tcp", "addr": ":80"}
2025/09/02 21:26:58.564 INFO http.log server running {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2025/09/02 21:26:58.564 ERROR unable to autosave config {"file": "/config/caddy/autosave.json", "error": "open /config/caddy/autosave.json: permission denied"}
2025/09/02 21:26:58.564 INFO serving initial configuration
2025/09/02 21:26:58.564 WARN tls unable to get instance ID; storage clean stamps will be incomplete {"error": "open /data/caddy/instance.uuid: permission denied"}
2025/09/02 21:26:58.564 ERROR tls could not clean default/global storage {"error": "unable to acquire storage_clean lock: creating lock file: open /data/caddy/locks/storage_clean.lock: no such file or directory"}
2025/09/02 21:26:58.564 INFO tls finished cleaning storage units (listening just fine on port 80, even when started as user 1000:1000, and the capability in question explicitly dropped) |
I see, good to know. We still have issues with non-root though, namely FYI @abjugard, you had done the patch for setcap, do you have any objection to us reverting that, now that k8s should have caught up? |
@francislavoie My understanding is:
What is confusing as a user is that you need to set the capability even when you're not using an privileged port. |
Argh, what a mess 🙈 |
I think even I agree with @tianon that it makes sense to reconsider including But with many people still running older runtimes that would be a breaking change, so I don't expect this to happen (quickly). Sidenote: |
If the ports exposed is changed from 80/443 to higher numbers I don't see a reason for calling |
Issue
The Caddy image needs the
NET_BIND_SERVICE
capability. There is no explanation on why and how to avoid it.Especially in Kubernetes it is common to drop all capabilities and to use non privileged ports. Here the default behavior is confusing.
Changes
Added explanation on why the capability is required by default and how to change it.
Included the error message to make it searchable.