fix(services-restart): an LXC container's processes are left out (NetOrk/netork#2750)
driver / standard (pull_request) Failing after 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m23s
driver / test (3.13) (pull_request) Successful in 1m22s
driver / lowest (pull_request) Successful in 44s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m4s
CI / driver (pull_request) Failing after 3m0s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Failing after 17s
driver / lint (pull_request) Successful in 15s
driver / types (pull_request) Successful in 1m5s
driver / test (3.12) (pull_request) Successful in 1m23s
driver / test (3.13) (pull_request) Successful in 1m22s
driver / lowest (pull_request) Successful in 44s
driver / build (pull_request) Successful in 32s
driver / security (pull_request) Successful in 1m4s
CI / driver (pull_request) Failing after 3m0s
driver / publish (pull_request) Skipped
On a Proxmox node the /proc scan sees every container's processes: an LXC container updates itself, and its own systemd's units (lxc/<vmid>/ns/... .service) would read as the host's services needing a restart. They are left out like Docker's and Podman's: /lxc/<name>/ (Proxmox VE, cgroup v1) and /lxc.payload.<name>/ (LXC 4 and later). The monitor, lxc.monitor/<name>, runs the host's lxc-start and still counts.
This commit is contained in:
1 parent
5517464e1f
commit
67ffee4e9e
4 files changed
+44
-7
No files matched your search
+3
-1
@@ -18,7 +18,9 @@ recorded here; their history is the git log.
|
||||
`/proc/<pid>/maps` for executable mappings of deleted files under `/usr`, `/lib*`, `/bin`,
|
||||
`/sbin` or `/opt`, each process mapped to its service through `/proc/<pid>/cgroup` as the
|
||||
listening sockets do. A user's own systemd counts as `user@<uid>`, a container's process is
|
||||
left out, and a process in no service is listed under `processes`. A refused root gives
|
||||
left out (Docker, Podman, and LXC: `/lxc/<name>/`, Proxmox VE's `/lxc/<vmid>/ns/`, or
|
||||
`/lxc.payload.<name>/`; a container updates itself, and its own systemd's units are no
|
||||
services of the host), and a process in no service is listed under `processes`. A refused root gives
|
||||
no report and raises, never a clean reading. A driver supplies
|
||||
`_run_services_restart_command(command)`.
|
||||
- `parse_services_restart`, `SERVICES_RESTART_COMMAND`, `DELETED_CODE_PATTERN`, and the
|
||||
|
||||
@@ -214,7 +214,8 @@ finished until they restart. One fixed, read-only command, as root: `needs-resta
|
||||
where dnf-utils has it, else `needrestart -b -r l` (list only, whatever `needrestart.conf`
|
||||
says), else the processes whose `/proc/<pid>/maps` maps deleted code
|
||||
(`DELETED_CODE_PATTERN`), each named by the service its cgroup gives, as for the listening
|
||||
sockets. A driver supplies `_run_services_restart_command(command)`; the command arrives as
|
||||
sockets. A container's processes are left out, an LXC container's as well (a Proxmox node's
|
||||
containers update themselves). A driver supplies `_run_services_restart_command(command)`; the command arrives as
|
||||
one `sh -c` argument and reads no stdin. Without root there is no reading: one that saw only
|
||||
the login user's processes would read as clean.
|
||||
|
||||
|
||||
@@ -21,10 +21,11 @@ here once, and a driver only carries the command across.
|
||||
|
||||
**Units from cgroups.** For the ``/proc`` scan, ``/proc/<pid>/cgroup`` names the
|
||||
systemd service a process runs in, as for the listening sockets: a process of a
|
||||
user's own systemd is that user's manager (``user@1000``), one of a container is
|
||||
left out (the container runs its image's libraries, which no host update
|
||||
replaces), and one in no service -- a login session, systemd itself -- is listed
|
||||
as a process. The host's tools name services only, so ``processes`` stays empty
|
||||
user's own systemd is that user's manager (``user@1000``), one of a container --
|
||||
Docker, Podman, or LXC as on a Proxmox node -- is left out (the container runs its
|
||||
own libraries, which no host update replaces, and its own systemd's units are none
|
||||
of the host's services), and one in no service -- a login session, systemd itself --
|
||||
is listed as a process. The host's tools name services only, so ``processes`` stays empty
|
||||
for them.
|
||||
|
||||
**Root, or nothing.** Only root sees every process's memory. The script goes to
|
||||
@@ -84,6 +85,10 @@ _SERVICE_LINE = re.compile(r"^([\w:.@\\-]+)\.service$")
|
||||
_NEEDRESTART_SVC = re.compile(r"^NEEDRESTART-SVC:\s*(.+?)\s*$")
|
||||
#: A process of a user's own systemd: that user's manager is what restarts it.
|
||||
_USER_MANAGER = re.compile(r"/(user@\d+)\.service(?=/|$)")
|
||||
#: A process inside an LXC container: ``/lxc/<name>/`` (Proxmox VE, which nests the
|
||||
#: container's own cgroups under ``ns``; cgroup v1) or ``/lxc.payload.<name>/`` (LXC 4
|
||||
#: and later). Not ``/lxc.monitor/<name>``: ``lxc-start`` runs the host's binary.
|
||||
_LXC = re.compile(r"^/lxc(?:/|\.payload\.)[^/]+(?:/|$)")
|
||||
_SERVICE_SUFFIX = ".service"
|
||||
|
||||
|
||||
@@ -130,7 +135,7 @@ def _maps(sections: dict[str, list[str]]) -> tuple[list[str], list[RestartProces
|
||||
if not pid.isdigit():
|
||||
continue
|
||||
path = paths.get(int(pid))
|
||||
if _container(path):
|
||||
if _container(path) or _LXC.match(path or ""):
|
||||
continue
|
||||
unit = _process_unit(path)
|
||||
if unit:
|
||||
|
||||
@@ -115,6 +115,35 @@ class TestTheMapsScan:
|
||||
|
||||
assert reading == {"source": "maps", "units": [], "processes": []}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"cgroup",
|
||||
[
|
||||
# Proxmox VE: the container's own systemd, under lxc/<vmid>/ns.
|
||||
"0::/lxc/101/ns/system.slice/nginx.service",
|
||||
"0::/lxc/101/ns/init.scope",
|
||||
# LXC 4 and later by default.
|
||||
"0::/lxc.payload.web/system.slice/nginx.service",
|
||||
# cgroup v1, systemd's hierarchy.
|
||||
"12:name=systemd:/lxc/web/system.slice/nginx.service",
|
||||
],
|
||||
)
|
||||
def test_an_lxc_container_is_left_out(self, cgroup):
|
||||
"""A Proxmox node's containers update themselves: the host sees their processes'
|
||||
mappings, and their own systemd's units, which are no services of the host's."""
|
||||
cgroups = f"2100 {cgroup}\n"
|
||||
|
||||
reading = parse_services_restart(_wire(("maps", "2100 nginx\n"), ("cgroups", cgroups)))
|
||||
|
||||
assert reading == {"source": "maps", "units": [], "processes": []}
|
||||
|
||||
def test_an_lxc_monitor_is_the_hosts(self):
|
||||
"""``lxc-start`` runs the host's own binary, outside the container."""
|
||||
reading = parse_services_restart(
|
||||
_wire(("maps", "2090 lxc-start\n"), ("cgroups", "2090 0::/lxc.monitor/101\n"))
|
||||
)
|
||||
|
||||
assert reading["processes"] == [{"pid": 2090, "name": "lxc-start"}]
|
||||
|
||||
def test_a_process_gone_before_its_cgroup_was_read_has_no_unit(self):
|
||||
reading = parse_services_restart(_wire(("maps", "4242 cron\n"), ("cgroups", "")))
|
||||
|
||||
|
||||
Reference in new issue
Block a user