nspawn: systemd-networkd stopped working in containers without `-U` in 242 · Issue #12313 · systemd/systemd
I have the same issue: Volatile= conflicts with -U, and so i cannot run networkd in my containers with volatile=overlay (things like passwd do not work in this scenario either by the way)
yuwata
changed the title
systemd-networkd stopped working in containers without
nspawn: systemd-networkd stopped working in containers without -U in 242-U in 242
@yuwata This seems to work for my vanilla containers. However for ones that I have a .nspawn file I still get ConditionCapability=CAP_NET_ADMIN was not met, even if said file is empty. IOW:
# rm /etc/systemd/nspawn/<machine>.nspawn succeeds, but then
# touch /etc/systemd/nspawn/<machine>.nspawn fails.
This is with --settings=override.
So with --settings=override all command-line arguments are ignored? The man page says:
If this option is set to override, the file is searched, read and used the
same way, however, the order of precedence is reversed: settings read from
the .nspawn file will take precedence over the corresponding command line
options, if both are specified.
So I would think that an empty .nspawn file would have no effect, since it isn't overriding anything.
I have a similar regression that I bisected to a3fc6b5. Let me know if I should open a new issue, but I suspect the cause and resolution will be the same. My case is using machinectl start with some settings in /etc/systemd/nspawn/*.nspawn, but no network-related ones -- I'm relying on the default network options of the systemd-nspawn@.service template for those. I get the exact same issue with systemd-networkd inside the container complaining about CAP_NET_ADMIN.
The problem, AFAICT, is that the logic in the aforementioned commit looks only at the file being parsed to decide whether CAP_NET_ADMIN is needed or not. That was fine when it was only being added, as code elsewhere added it when command line arguments required it. But now that the file-settings logic is also removing the capability, it will be erroneously removed when there are command-line options implying private-network but nothing in the config file that does so. In support of this, my case can be worked around by adding a [Network] section with Private=yes to my .nspawn file.
Workaround for the default configuration of the systemd-nspawn@.service units is to add VirtualEthernet=yes to the [Network] section of the corresponding nspawn files.
@yuwata I'd like to retain CAP_NET_ADMIN for my nspawn container while at the same time having VirtualEthernet=no. According to the man page this should be simply done by adding Capability=CAP_NET_ADMIN to the [Exec] section of the .nspawn file. With the current systemd-242 this does not work. There is no net_admin when verifying via pscap.
i added my bridge config to each /etc/systemd/nspawn/*.nspawn file:
[Network]
VirtualEthernet=yes
Bridge=br0
this gives the CAP_NET_ADMIN to the containers. specifying the same in the ExecStart command-line-options /etc/systemd/system/systemd-nspawn@.service doesn't do anything anymore.
I don't know if this is a regression or not, but the report is somewhat confusing. Despite what the OP says, the behaviour is unrelated to the -U flag - the problem appears with as well as without -U. Maybe it's a regression^2... Anyway, please change the title to something better to make the issue easier to find.
To summarize the behaviour that has been observed in the comments above (you can add -U with no change in behaviour):
-
systemd-nspawn --network-veth --settings=override -bD containerand/etc/systemd/nspawn/container.nspawndoes not exist – works as expected -
systemd-nspawn --network-veth --settings=override -bD containerand/etc/systemd/nspawn/container.nspawnexists, but is empty – thesystemd-networkd.servicedoes not start in the container due toConditionCapability=CAP_NET_ADMIN was not met, thehost0interface in the container remains unmanaged -
systemd-nspawn --network-veth --settings=override -bD containerand/etc/systemd/nspawn/container.nspawncontains:[Network] VirtualEthernet=yes– works as expected
Now, consider another case:
-
systemd-nspawn --network-veth --settings=override -bD containerand/etc/systemd/nspawn/container.nspawncontains:– the result is that
systemd-networkd.servicestarts fine in the container, but the virtual Ethernet link was not created! (the container interfacehost0and host interfaceve-containerwere not created)
Why does passing Private=yes in the .nspawn file and --network-veth on the command line discard the creation of the virtual Ethernet link?
This was tested with systemd 246.2 and Arch Linux (both host and container).
For info, the bug is still present in Systemd 247 (NixOS 21.05).
This workaround still works too (#12313 (comment))