run the root check warn-only on hyperhive's own containers, per unit, not on the container@ template
This commit is contained in:
parent
c191975aab
commit
24afc89ab3
1 changed files with 707 additions and 172 deletions
|
|
@ -13,10 +13,10 @@
|
|||
# forwarder (nix/agent-modules/otel.nix) reads it, and the host can read it;
|
||||
# - a package installed into the user's nix profile is still there, and on
|
||||
# PATH, after a restart;
|
||||
# - a link planted at `root` in the root template refuses the next start through
|
||||
# the `ExecStartPre=` check in the `container@` template drop-in
|
||||
# (nix/host-modules/container-rootfs-check.nix), leaves the link's target
|
||||
# untouched, and the start goes through once the link is gone.
|
||||
# - a link planted at `root` in the template refuses the next start through
|
||||
# the limits drop-in's `ExecStartPre=` check (whose build has a GC root),
|
||||
# leaves the link's target untouched, and the start goes through once the
|
||||
# link is gone.
|
||||
#
|
||||
# The agent's journal forwarder itself (an OTLP push to the hive's collector) is
|
||||
# not booted here; the module-eval suite covers its wiring.
|
||||
|
|
@ -69,7 +69,6 @@ pkgs.testers.runNixOSTest {
|
|||
{
|
||||
imports = [
|
||||
hiveStubs
|
||||
../host-modules/container-rootfs-check.nix
|
||||
../host-modules/hive-priv.nix
|
||||
];
|
||||
virtualisation.memorySize = 2048;
|
||||
|
|
@ -234,10 +233,21 @@ pkgs.testers.runNixOSTest {
|
|||
|
||||
with subtest("a link planted in the root refuses the start and nothing is touched"):
|
||||
stop()
|
||||
# The pre-start check is a drop-in of the `container@` template, so the
|
||||
# unit carries it with no per-container drop-in written.
|
||||
unit = host.succeed(f"systemctl cat container@{MACHINE}")
|
||||
assert "bin/hive-priv check-rootfs %i\n" in unit, unit
|
||||
# What hive-c0re does besides WriteNspawnFlags: the limits drop-in,
|
||||
# which carries the pre-start check, and the runtime dir its condition
|
||||
# names.
|
||||
host.succeed(f"mkdir -p /run/hyperhive/agents/{AGENT}")
|
||||
for req in [
|
||||
{"op": "write_resource_limits", "container": MACHINE, "memory_max": "1G", "cpu_quota": "200%"},
|
||||
{"op": "daemon_reload"},
|
||||
]:
|
||||
out = host.succeed(f"echo '{json.dumps(req)}' | socat - UNIX-CONNECT:/run/hive/priv.sock")
|
||||
assert json.loads(out.strip().splitlines()[-1])["ok"] is True, out
|
||||
dropin = host.succeed(f"cat /run/systemd/system/container@{MACHINE}.service.d/hyperhive-limits.conf")
|
||||
assert "ExecStartPre=/nix/store/" in dropin and f"check-rootfs {MACHINE}\n" in dropin, dropin
|
||||
# The build the drop-in names is rooted against garbage collection.
|
||||
build = "/".join(dropin.split("ExecStartPre=")[1].split()[0].split("/")[:4])
|
||||
assert host.succeed(f"readlink /nix/var/nix/gcroots/hyperhive-check-rootfs/{MACHINE}").strip() == build, build
|
||||
|
||||
# `root` is a link to a directory outside the root, which the start
|
||||
# script would `chmod 0700` as host root.
|
||||
|
|
|
|||
Loading…
Reference in a new issue