The image now holds only the ESP and a verity-protected /usr (A/B). At first boot, systemd-repart in the initrd makes the root filesystem: btrfs, encrypted with a TPM key sealed to the signed PCR 11 policy, with /var as its own subvolume. A TPM is required. systemd.image_policy= accepts only an encrypted root and a verity-checked /usr, and FactoryReset=yes lets factory-reset.target wipe it. /etc is writable but nearly empty: mkosi.finalize keeps the build's /etc in /usr/share/factory/etc and systemd-tmpfiles links it in at boot. That removes etc-shadow.mount, the host key on /var, fstab and /var/lib/agent. /var now survives reboots. systemd-firstboot replaces agent-setup: it asks for the root password on the screen and offers a recovery key. Machines are named agent-???? from the kernel command line. The user is now agent, with its home in /home/agent and ssh keys in the default places. sshd.path starts sshd only once root or agent has a key. The test VM needs swtpm. The package cache moves to a podman volume (AGENTS.md). No existing VMs can update to this layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.6 KiB
Bash
Executable File
43 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Factory /etc
|
|
#
|
|
# The image ships only /usr (mkosi.repart), so this keeps the /etc that the
|
|
# packages and mkosi.extra/etc made in /usr/share/factory/etc. It writes
|
|
# /usr/lib/tmpfiles.d/factory-etc.conf, with which systemd-tmpfiles links each
|
|
# entry into the writable, empty /etc at boot. Updates to /usr then take
|
|
# effect in /etc too. /etc itself holds only what the machine writes: passwd,
|
|
# shadow, group, hostname, machine-id and the ssh host keys.
|
|
set -eu
|
|
|
|
factory=$BUILDROOT/usr/share/factory/etc
|
|
cp -a --no-target-directory --update=none "$BUILDROOT/etc" "$factory"
|
|
|
|
# skip holds what /etc keeps for itself, and what other tmpfiles.d files
|
|
# already set up, such as /etc/os-release.
|
|
skip=$(printf '%s\n' passwd group shadow gshadow hostname machine-id ssh
|
|
sed -n 's|^[^#][^ ]* */etc/\([^/ ]*\).*|\1|p' "$BUILDROOT"/usr/lib/tmpfiles.d/*.conf)
|
|
|
|
# link prints the tmpfiles line for /etc/$1. Some entries are copied instead:
|
|
# a symlink, because a relative one would point somewhere else from the
|
|
# factory, and subuid and subgid, because shadow-utils won't read them through
|
|
# a link.
|
|
link() {
|
|
case "$1" in
|
|
subuid|subgid) echo "C /etc/$1" ;;
|
|
*) if [ -L "$factory/$1" ]; then echo "C /etc/$1"; else echo "L /etc/$1"; fi ;;
|
|
esac
|
|
}
|
|
|
|
{
|
|
echo "# Generated by mkosi.finalize."
|
|
for f in $(ls -A "$factory"); do
|
|
case "$f" in *-|.*) continue ;; esac
|
|
echo "$skip" | grep -qxF "$f" || link "$f"
|
|
done
|
|
# /etc/ssh is a directory of its own, because sshd-keygen writes the host
|
|
# keys there.
|
|
echo "d /etc/ssh 0755"
|
|
for f in $(ls -A "$factory/ssh"); do link "ssh/$f"; done
|
|
} > "$BUILDROOT/usr/lib/tmpfiles.d/factory-etc.conf"
|
|
|