Daan De Meyer [Thu, 13 Feb 2025 09:14:32 +0000 (10:14 +0100)]
Force ssh to use bash to run the ProxyCommand
We only have bash installed in the tools tree and by default ssh
will try to use the user's shell to execute the proxy command which
might not be available so force it use bash.
Daan De Meyer [Wed, 12 Feb 2025 09:49:59 +0000 (10:49 +0100)]
Require delimiting extra options for invoked commands with '--'
This is one of the biggest footguns when using mkosi so let's break
compat and fix it. Any options that should be passed to the command
invoked by mkosi when using various verbs should be delimited from
regular options now using '--'.
Daan De Meyer [Tue, 11 Feb 2025 14:58:38 +0000 (15:58 +0100)]
run: Simplify spawn()
Let's reduce the nesting by stopping usage of Popen() as a context
manager. It's __exit__() method doesn't handle anything important that
we don't already handle ourselves. Let's also only handle
FileNotFoundError when spawning the process but not after yielding.
Finally, get rid of the failed() nested function as it only has one
remaining caller.
Daan De Meyer [Tue, 11 Feb 2025 14:48:29 +0000 (15:48 +0100)]
mkosi-sandbox: Implement --pack-fds
This allows us to move the file descriptor packing logic from spawn()
to mkosi-sandbox. The main advantage here is that we can pass file
descriptors now without necessarily packing them together, which we now
only do for systemd-journal-remote which requires it.
Luca Boccassi [Tue, 11 Feb 2025 13:19:15 +0000 (13:19 +0000)]
partition: do not return TBD as roothash
When a verity partition is skipped/deferred (eg: second run for ESP
partitioning) the JSON output will list the roothash as 'TBD' which
is obviously not valid, so skip it in that case
Daan De Meyer [Mon, 10 Feb 2025 20:24:37 +0000 (21:24 +0100)]
Make VM registration work unprivileged
Since systemd 257, it's possible for unprivileged users to register
VMs with systemd-machined (gated behind polkit). So let's not require
root privileges to register virtual machines with systemd-machined, but
only do it as an unprivileged user if registration is explicitly requested
to avoid the polkit prompt.
To avoid having to detect which systemd version the system is running,
we skip errors on varlink registration for now when running unprivileged.
https://github.com/systemd/systemd/pull/36344 will allow us to detect if
the machined varlink interface can be accessed as an unprivileged user or
not.
Daan De Meyer [Tue, 11 Feb 2025 09:54:13 +0000 (10:54 +0100)]
sandbox: Replace --exec-fd with --suspend
Let's change our synchronization mechanism from a file descriptor
to use SIGSTOP instead. This is both simpler and gives us a two way
synchronization mechanism. We can wait in the parent for the initialization
to complete just like before by waiting for the process to go into the
stopped state. But we can also have the subprocess wait indefinitely
until the parent tells it to continue by sending the SIGCONT signal. We make
use of this to register the qemu VM with systemd-machined before actually
starting the qemu process itself.
Daan De Meyer [Tue, 11 Feb 2025 09:29:37 +0000 (10:29 +0100)]
Drop foreground process logic
Let's stop messing around with process groups in favor of handling
terminal signals properly ourselves. We had to use process groups in
the past because we still used subprocess.run() which meant that by
the time we had a chance to handle KeyboardInterrupt(), the subprocess
would have already been SIGKILLed by subprocess.run(). Now that we don't
use subprocess.run() anymore, we can catch KeyboardInterrupt() at the
right time and forward it to the child process.
For the mkosi process itself, we have to modify the signal handlers
slightly to make sure we only raise the KeyboardInterrupt() exception
once, as when we're running a forked subprocess, both the parent process
and the forked subprocess will receive SIGINT if Ctrl+C is entered on the
terminal, and the parent process will forward the SIGINT to the child process,
which is already handling its own SIGINT, causing KeyboardInterrupt() to get
raised twice if we don't add an extra check to the signal handler to make sure
it only gets raised once.
Luca Boccassi [Tue, 28 Jan 2025 16:22:43 +0000 (16:22 +0000)]
Add support for SplitArtifacts=pcrs
When building a UKI emit a JSON blob containing all the PCR
policy blobs, so that it can be signed offline. A single JSON
file is written out, even if multiple profiles are used, as
ukify can be used to reattach a single blob and will ensure
the right signature is applied to the right PE .pcrsig section
in case of multiple profiles.
Rigth now, firmware added to the image is determined as a dependency of any
added kernel modules. However, a common use case is that a user may need to
force certain firmware to be included or excluded regardless of that dependency.
Daan De Meyer [Fri, 7 Feb 2025 09:08:09 +0000 (10:08 +0100)]
Check MinimumVersion= during config parsing
We fail on unknown settings, so currently if the mkosi version is too
old, we fail during config parsing before we ever get to check if the
current version is older than the minimum version.
Let's fix this by checking the minimum version during config parsing
itself. This means it can't be overridden later on anymore with a lower
version during config parsing but I doubt this will ever happen in the
first place.
Daan De Meyer [Thu, 6 Feb 2025 13:40:36 +0000 (14:40 +0100)]
tree: Don't copy xattrs to overlayfs if security.selinux is one
Trying to copy the selinux xattrs to a directory in an overlayfs
filesystem will fail with "Operation not supported". There's no way
to instruct cp to not copy or ignore failures to copy selinux xattrs
so let's instead not try to copy xattrs at all when copying to directories
in overlayfs filesystems and security.selinux is in the list of xattrs.
Daan De Meyer [Thu, 6 Feb 2025 11:05:05 +0000 (12:05 +0100)]
rpm: Fix root locations for GPG searching
We should always look in the tools tree for /usr/share/distribution-gpg-keys,
regardless of the value of ToolsTreeCertificates= since the setting has no
impact on which /usr/share/distribution-gpg-keys directory we end up using.
We should look in the host or tools tree for /etc/pki/rpm-gpg, based on the
value of ToolsTreeCertificates=, not in the sandbox tree, because the /etc/pki
directory from the host or tools tree will always be used and mounted over the
directory from the sandbox tree, so there's no point in looking for rpm gpg keys
in the sandbox tree at all.
Daan De Meyer [Thu, 6 Feb 2025 09:54:45 +0000 (10:54 +0100)]
fedora: Try to load N+1 key from distribution-gpg-keys as well
Fetching the rawhide keys from the distribution-gpg-keys github
repository faces the same problem that we have when using the locally
installed distribution-gpg-keys, the rawhide symlink might not have
been updated yet at branching time, so apply the same solution and
try to load the N+1 key as well.
Martin Hundebøll [Tue, 28 Jan 2025 20:35:26 +0000 (21:35 +0100)]
Support unsigned verity backed extension/portable images
Building an unsigned extension image with verity hashes provides data
integrity without needing a certificate on the target machine.
Note that systemd-dissect and systemd-sysext doesn't automatically
use the verity data has partition for validation. Both tools enables
validation if the user.verity.roothash xattr is set for the image.
For systemd-dissect, one can use the --root-hash option to enable the
validation.
The root hash can be obtained by concatenating the partition uuid's for
the root and the root-verity partitions.
Daan De Meyer [Tue, 28 Jan 2025 19:47:30 +0000 (20:47 +0100)]
Don't call have_cache() in reuse_cache()
By the time reuse_cache() is called, we've already cleaned up old
cached images if needed, so just check if they still exist and reuse
them if they do.
Daan De Meyer [Tue, 28 Jan 2025 19:18:36 +0000 (20:18 +0100)]
Replace check_uid with a "tools" image check in have_cache()
We have access to the config object in have_cache() and this argument
is specifically intended to be used whenever we pass the default tools
tree to have_cache(), so let's just do the check based on config.image
in have_cache() itself.
Martin Hundebøll [Mon, 27 Jan 2025 14:45:01 +0000 (15:45 +0100)]
Fix verity signature check in case keys are configured
The repart json output includes the architecture in the partiton type
string, so the same must be included when checking for a verity
signature partition.
Daan De Meyer [Mon, 27 Jan 2025 14:05:45 +0000 (15:05 +0100)]
mkosi-tools: Drop fish and zsh
These are a bit too exquisite to have in the default tools tree and
we don't start a shell in mkosi-sandbox by default anymore, so let's
stick to just having bash in the default tools tree.
zypper allows to use the `$releasever` variable in repo URLs (see zypper(8) man
page). When mkosi uses zypper repos from the host instead of the default ones,
this variable needs to be replaced with the host's `VERSION_ID`, otherwise repo
URLs are incomplete.
Daan De Meyer [Mon, 27 Jan 2025 10:10:13 +0000 (11:10 +0100)]
Log command line for abnormal signals
If we're not killed by SIGINT or SIGTERM, let's log the command line
as in this scenario it's very likely the process we were running crashed
with SIGABRT or SIGSEGV.
Daan De Meyer [Sat, 25 Jan 2025 21:28:21 +0000 (22:28 +0100)]
mkosi-initrd: Add two more modules
Three more generic modules that are needed in the initrd.
- mxm-wmi is a standard for switchable laptop graphics
- usb-storage is obviously for USB storage devices
- partport (https://docs.kernel.org/admin-guide/parport.html)
seems generic enough that we should include it in the initrd.