`vhost-device-vsock`[1] is a custom implementation of AF_VSOCK, but the
application on the host-side uses a UNIX domain-socket. This gives us
the following nice properties:
* We don't need to do `--arg sandbox-paths /dev/vhost-vsock` anymore for
debugging builds within the sandbox. That means, untrusted users can
also debug these kinds of tests now.
* This prevents CID conflicts on the host-side, i.e. there's no need for
using `sshBackdoor.vsockOffset` for tests anymore.
A big shout-out goes to Allison Karlitskaya, the developer of test.thing[2]
who talked about this approach to do AF_VSOCK on All Systems Go 2025.
This patch requires systemd 258[3] because this contains `vhost-mux` in
its SSH config which is needed to connect to the VMs from now on.
To not blow up the patches even more, this only uses AF_VSOCK for the
debugger. A potential follow-up for the future would be a removal of the
current `backdoor.service` and replace it entirely by this
functionality.
The internal implementation tries to be consistent with how VLANs and
machines are handled, i.e. the processes are started when the Driver's
context is entered and cleaned up in __exit__().
I decided to push the process management and creation of sockets for
vhost-device-vsock into its own class, that's an implementation detail
and not a concern for the test-driver. In fact, `vhost-device-vsock` is
something we can drop once QEMU implements native support for using
AF_UNIX on the host-side[4]. `VsockPair` is its own class since
returning e.g. a triple of `(Path, Path, Int)` would be ambiguous in
what is the guest and what the host path (and frankly, I found it hard
to distinguish the two when reading the docs of `vhost-device-vsock`
initially).
Finally, now that we can do the SSH backdoor without adding additional
devices to the sandbox, I figured, it's time to write a test-case for
it.
[1] https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-vsock/README.md
[2] https://codeberg.org/lis/test.thing
[3] https://github.com/NixOS/nixpkgs/pull/427968
[4] https://gitlab.com/qemu-project/qemu/-/issues/2095
The context manager's purpose is to allocate its resources in `__enter__` and
release them again in `__exit__`.
Right now, the approach is merely a hack since we allocate everything in
the constructor, but use the context-manager protocol as way to reliably
terminate everything.
This isn't a functional change, but merely a correctness change by using
the methods the way they were intended.
This option configures a memfd backend for the VM's memory with the size
of `virtualisation.memorySize` and uses that as default memory backend.
This is required for e.g. vhost-device-vsock.
The motivation for making this an option is that I decided to enable
this by default for all NixOS tests to avoid changing essential QEMU
options based on whether or not debugging is enabled. However, there
should be an easy way to turn it off which is what this option provides.
configure looks for CUPS via pkg-config first and only falls back to
cups-config. With strictDeps the build-platform cups-config leaks
build-platform -I/-L flags into the cross build (ld warns about
"skipping incompatible libcups.so" and only links because the cc-wrapper
adds the host cups via NIX_LDFLAGS). The cross-aware pkg-config wrapper
picks up the host cups.pc directly, so cups no longer needs to be a
native input.