When attempting to run Apache inside a systemd container that was started with systemd-nspawn --private-users=pick ...
(unlike --private-users=false
in this solution) I encounter this error:
Permission denied: AH00072: make_sock: could not bind to address ...:999
What puzzles me is that the container has been granted capability CAP_NET_BIND_SERVICE
(getpcaps 1
inside the container also confirms this), --capability=help
indicates that the capability is supported, and netcat -l 999 -s ...
(also inside the container) can apparently listen on the same port just fine.
What am I missing? Shouldn't the capability allow processes inside the container to open well-known ports on the host, no matter what their PIDs are?
UPDATE I made a mistake with the invocation of netcat
. The correct command line is netcat -vl -p 999 -s ...
and this now produces "Can't grab ...:999 with bind : Permission denied". So in fact neither Apache nor netcat can bind at this point, and this is not Apache-specific. Two more facts about the configuration: container is running as root
(mapped to non-root pid on host), iptables
on host are empty.
UPDATE So perhaps capability CAP_NET_BIND_SERVICE
simply cannot transcend user namespaces.
I have come to the conclusion that capability
CAP_NET_BIND_SERVICE
specifically and capabilities in general cannot transcend user namespaces. Fromuser_namespaces(7)
:From
network_namespaces(7)
:Since my case involves a binding to the host's primary IP address the relevant physical network device must presumably be governed by the kernel's root network namespace. The capability
CAP_NET_BIND_SERVICE
in my container's user namespace presumably has no bearing there since the root network namespace is not associated with that user namespace but with the kernel's root user namespace instead. So I am (presumably) out of luck here.