libvirt/src/remote
Laine Stump 0756415f14 systemd: start libvirtd after firewalld/iptables services
When a system has enabled the iptables/ip6tables services rather than
firewalld, there is no explicit ordering of the start of those
services vs. libvirtd. This creates a problem when libvirtd.service is
started before ip[6]tables, as the latter, when it finally is started,
will remove all of the iptables rules that had previously been added
by libvirt, including the custom chains where libvirt's rules are
kept. This results in an error message similar to the following when a
user subsequently tries to start a new libvirt network:

 "Error while activating network: Call to virNetworkCreate failed:
 internal error: Failed to apply firewall rules
 /usr/sbin/ip6tables -w --table filter --insert LIBVIRT_FWO \
   --in-interface virbr2 --jump REJECT:
 ip6tables: No chain/target/match by that name."

(Prior to logging this error, it also would have caused failure to
forward (or block) traffic in some cases, e.g. for guests on a NATed
network, since libvirt's rules to forward/block had all been deleted
and libvirt didn't know about it, so it couldn't fix the problem)

When this happens, the problem can be remedied by simply restarting
libvirtd.service (which has the side-effect of reloading all
libvirt-generated firewall rules)

Instead, we can just explicitly stating in the libvirtd.service file
that libvirtd.service should start after ip6tables.service and
ip6tables.service, eliminating the race condition that leads to the
error.

There is also nothing (that I can see) in the systemd .service files
to guarantee that firewalld.service will be started (if enabled) prior
to libvirtd.service. The same error scenario given above would occur
if libvirtd.service started before firewalld.service.  Even before
that, though libvirtd would have detected that firewalld.service was
disabled, and then turn off all firewalld support. So, for example,
firewalld's libvirt zone wouldn't be used, and most likely traffic
from guests would therefore be blocked (all with no external
indication of the source of the problem other than a debug-level log
when libvirtd was started saying that firewalld wasn't in use); also
libvirtd wouldn't notice when firewalld reloaded its rules (which also
simultaneously deletes all of libvirt's rules).

I'm not aware of any reports that have been traced back to
libvirtd.service starting before firewalld.service, but have seen that
error reported multiple times, and also don't see an existing
dependency that would guarantee firewalld.service starts before
libvirtd.service, so it's possible it's been happening and we just
haven't gotten to the bottom of it.

This patch adds an After= line to the libvirtd.service file for each
of iptables.service, ip6tables.service, and firewalld.servicee, which
should guarantee that libvirtd.service isn't started until systemd has
started whichever of the others is enabled.

This race was diagnosed, and patch proposed, by Jason Montleon in
https://bugzilla.redhat.com/1723698 . At the time (April 2019) danpb
agreed with him that this change to libvirtd.service was a reasonable
thing to do, but I guess everyone thought someone else was going to
post a patch, so in the end nobody did.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-05-05 20:16:02 -04:00
..
libvirtd-admin.socket.in systemd: honour $runstatedir in socket unit files 2019-08-27 10:23:05 +01:00
libvirtd-ro.socket.in systemd: honour $runstatedir in socket unit files 2019-08-27 10:23:05 +01:00
libvirtd-tcp.socket.in remote: conditionalize systemd socket unit files 2019-08-09 14:06:31 +01:00
libvirtd-tls.socket.in remote: conditionalize systemd socket unit files 2019-08-09 14:06:31 +01:00
libvirtd.aug.in build: don't hardcode /etc in the config related files 2019-08-09 14:06:31 +01:00
libvirtd.conf.in src: switch from fnmatch to g_pattern_match_simple 2020-01-03 15:42:13 +00:00
libvirtd.confd configure: Provide OpenRC scripts for sub-daemons 2019-12-16 10:11:22 +01:00
libvirtd.init.in remote: Drop KRB5_KTNAME override 2020-04-03 11:51:00 +02:00
libvirtd.libxl.logrotate.in logging: ensure virtlogd rollover takes priority over logrotate 2019-07-12 12:44:59 +01:00
libvirtd.logrotate.in daemon: move logrotate files to src/remote/ 2018-02-22 12:26:57 +00:00
libvirtd.lxc.logrotate.in logging: ensure virtlogd rollover takes priority over logrotate 2019-07-12 12:44:59 +01:00
libvirtd.policy Do not generate polkit rules file 2018-03-14 12:46:26 +01:00
libvirtd.qemu.logrotate.in logging: ensure virtlogd rollover takes priority over logrotate 2019-07-12 12:44:59 +01:00
libvirtd.rules daemon: move misc libvirtd policy files to src/remote/ 2018-02-22 12:26:50 +00:00
libvirtd.sasl remote: Drop KRB5_KTNAME override 2020-04-03 11:51:00 +02:00
libvirtd.service.in systemd: start libvirtd after firewalld/iptables services 2020-05-05 20:16:02 -04:00
libvirtd.socket.in systemd: honour $runstatedir in socket unit files 2019-08-27 10:23:05 +01:00
libvirtd.sysconf remote: Drop KRB5_KTNAME override 2020-04-03 11:51:00 +02:00
libvirtd.sysctl daemon: move misc libvirtd policy files to src/remote/ 2018-02-22 12:26:50 +00:00
lxc_protocol.x Remove all Author(s): lines from source file headers 2018-12-13 16:08:38 +00:00
Makefile.inc.am systemd: Add sysconf files for all daemons 2020-04-03 11:50:47 +02:00
qemu_protocol.x src: convert all code to use virsocket.h 2020-01-29 14:51:40 +00:00
remote_daemon_config.c src: Fix boolean assignment 2020-05-05 13:08:57 +02:00
remote_daemon_config.h remote: conditionalize IP socket usage in libvirtd daemon 2019-08-09 14:06:31 +01:00
remote_daemon_dispatch.c remote: fix driver name check for libxl driver 2020-05-05 15:57:02 +01:00
remote_daemon_dispatch.h src/remote: use #pragma once in headers 2019-06-19 17:12:30 +02:00
remote_daemon_stream.c remote_daemon_stream: Hold an extra reference to stream in daemonStreamFilter 2019-11-29 15:00:15 +01:00
remote_daemon_stream.h src/remote: use #pragma once in headers 2019-06-19 17:12:30 +02:00
remote_daemon.c src: Fix boolean assignment 2020-05-05 13:08:57 +02:00
remote_daemon.h remote: open secondary drivers via remote driver if needed 2019-08-09 14:06:31 +01:00
remote_driver.c src: Fix boolean assignment 2020-05-05 13:08:57 +02:00
remote_driver.h remote: enable connecting to the per-driver daemons 2019-08-09 14:06:31 +01:00
remote_protocol.x rpc: gendispatch: trim Flags from the return struct name 2020-02-05 17:12:59 +01:00
test_libvirtd.aug.in systemd: honour $runstatedir in socket unit files 2019-08-27 10:23:05 +01:00
virt-guest-shutdown.target.in daemon: move init system files into src/remote/ 2018-02-22 12:21:21 +00:00
virtproxyd.confd configure: Provide OpenRC scripts for sub-daemons 2019-12-16 10:11:22 +01:00
virtproxyd.init.in remote: Drop KRB5_KTNAME override 2020-04-03 11:51:00 +02:00
virtproxyd.service.in systemd: Move timeout from service files to sysconf files 2020-04-03 11:50:50 +02:00
virtproxyd.sysconf systemd: Move timeout from service files to sysconf files 2020-04-03 11:50:50 +02:00