Files
systemd/units/systemd-sysext-initrd.service
Adrian Reber 600fcc6dcb dissect,nspawn,sysext: enable TPM2 unlocking of DDIs, document it
Set DISSECT_IMAGE_TPM2_UNLOCK where unlocking an image's LUKS partitions
via the local TPM2 is wanted and the caller is trusted:

 * systemd-dissect, an admin tool operating on an image the invoking user
   can read anyway;
 * systemd-nspawn --image=, which already prompts for a passphrase
   interactivly, so TPM2 first and passphrase second is the natural
   order;
 * systemd-sysext/systemd-confext, which decrypt without any passphrase,
   so extension images sealed to the host can be activated without user
   interaction.

For sysext/confext setting the flag at merge time is not enough: before
merging, the extension-release metadata is read via image_read_metadata()
in discover-image.c, which uses its own flag set and would already fail
with -ENOKEY on an encrypted image. Give it an extra_flags parameter and
pass the flag from there, too; the other callers (machined, portabled)
pass 0 and keep their behaviour.

Two units need adjusting for this to work when started by the service
manager: systemd-nspawn@.service has DevicePolicy=closed, so allow
/dev/tpmrm0 there, and the sysext/confext services are not ordered
against the TPM2 device showing up, so order them after tpm2.target
like the pcr* services. The initrd variants cannot be ordered the same
way: they run before local-fs-pre.target, while the software TPM fallback
only becomes available after the early ESP mount, which is ordered after
local-fs-pre.target, so a static After=tpm2.target would be an ordering
cycle with systemd.tpm2_software_fallback=1. Hence systemd-tpm2-generator
adds the ordering as a drop-in instead, unless the fallback is in use.
That drop-in also orders them after systemd-pcrphase-initrd.service:
nothing else guarantees the "enter-initrd" phase has been measured into
PCR 11 before the initrd extension units merge their images (the barrier's
Before=systemd-sysext.service is a leftover from when that unit was also
used in the initrd), so tokens bound to a signed PCR 11 policy or a
pcrlock policy would race the measurement.

Deliberately not enabled for now: RootImage=/ExtensionImages=/MountImages=
in units, portabled and gpt-auto. For those an unconditional default is
probably not wanted but a per-unit or per-image switch, which is left for
a follow-up. systemd-mountfsd, which unprivileged systemd-dissect and
systemd-nspawn delegate to, keeps its own flag set and does not honour
the flag, hence TPM2 unlocking is only available when running privileged;
the man pages say so.

Document the behaviour and $SYSTEMD_DISSECT_TPM2_UNLOCK= in the dissect,
nspawn and sysext man pages and in docs/ENVIRONMENT.md.
2026-10-13 11:05:48 +00:00

40 lines
1.5 KiB
Desktop File

# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Merge System Extension Images into /usr/ and /opt/ of the initrd
Documentation=man:systemd-sysext-initrd.service(8)
ConditionCapability=CAP_SYS_ADMIN
ConditionDirectoryNotEmpty=|/etc/extensions
ConditionDirectoryNotEmpty=|/run/extensions
ConditionDirectoryNotEmpty=|/var/lib/extensions
ConditionDirectoryNotEmpty=|/.extra/sysext
ConditionDirectoryNotEmpty=|/.extra/global_sysext
ConditionPathExists=/etc/initrd-release
ConditionKernelCommandLine=!rd.systemd.sysext=0
DefaultDependencies=no
After=systemd-confext-initrd.service
# Extension images might be LUKS encrypted and sealed to the local TPM2, but ordering after tpm2.target here
# would be a cycle with the software TPM fallback, hence systemd-tpm2-generator adds it where possible
Before=local-fs-pre.target cryptsetup-pre.target systemd-tmpfiles-setup.service
Wants=local-fs-pre.target cryptsetup-pre.target
Conflicts=initrd-switch-root.target
Before=initrd-switch-root.target
Wants=modprobe@loop.service modprobe@dm_mod.service
After=modprobe@loop.service modprobe@dm_mod.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=systemd-sysext refresh
ExecReload=systemd-sysext refresh
ExecStop=systemd-sysext unmerge