feat: root adds the ssh keys, mkosi ssh for the test VM

The setup no longer asks for an ssh key. Root logs in on the console and
adds keys for claude and root to /var/lib/agent. Root may log in with
ssh, and its home is a tmpfs that is wiped at every boot. The test VM
uses mkosi ssh instead of a forwarded port, so the agent.ssh-key
credential is gone.

Also mount /var with noatime, move STYLE.md into AGENTS.md and rewrite
comments to start with the name of what they describe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-19 19:10:54 +01:00
1 parent 8aeb448936
commit db8fb0d5a4
15 files changed
+218 -180

No files matched your search

+3 -4
View File
@@ -15,8 +15,8 @@ on:
push: push:
branches: [main] branches: [main]
schedule: schedule:
- cron: "0 2 * * 0" # weekly (Sunday), picks up package updates - cron: "0 2 * * 0"
workflow_dispatch: # run by hand, e.g. for a CVE workflow_dispatch:
jobs: jobs:
os: os:
@@ -38,8 +38,7 @@ jobs:
- name: Compress - name: Compress
working-directory: mkosi.output working-directory: mkosi.output
run: | run: |
zstd -q --rm -T0 -9 agent_*.root-*.raw zstd -q --rm -9 agent_*.root-*.raw
# -m 16 -W: compress on several cores instead of one
qemu-img convert -c -m 16 -W -O qcow2 "$(basename agent_*.efi .efi).raw" agent.qcow2 qemu-img convert -c -m 16 -W -O qcow2 "$(basename agent_*.efi .efi).raw" agent.qcow2
sha256sum agent_*.efi agent_*.root-*.raw.zst > SHA256SUMS sha256sum agent_*.efi agent_*.root-*.raw.zst > SHA256SUMS
- name: Sign - name: Sign
+64 -29
View File
@@ -1,43 +1,78 @@
# Agent notes # Agent notes
How to build and test this image as a coding agent. Follow [STYLE.md](STYLE.md) for every change. How to build and test this image as a coding agent. Follow [Style](#style) for
every change.
## Container ## Style
`mkosi vm` needs systemd on the host. A dev container has none, so run mkosi in a podman container that: - Keep it simple. Prefer fewer files, fewer lines and the defaults. Delete what
isn't needed.
- Divide code and config into parts (files, directories, config sections) that
each stand on their own: reading one alone tells you what it does and why.
- Each fact lives in one place. Elsewhere, refer to it by path instead of
repeating it.
- Write plain English in short sentences.
- boots systemd (`--systemd=always`, with `/sbin/init` as its command) ### File header
- is privileged and has `/dev/kvm`
- has `mkosi qemu-kvm-core edk2-ovmf systemd-repart openssh-clients` and `$(mkosi dependencies)` installed
- mounts the repository, such as at `/repo`
Then run mkosi with `podman exec <container> mkosi ...`. Every file that allows comments starts with a header. It goes after the
shebang, if there is one:
podman resolves host paths on the host, not in the dev container, so `~` and the scratchpad don't exist there. Mount paths inside the repository instead, such as `./mkosi.output/...`, which is ignored by git.
## Test VM
The `[Runtime]` section of `mkosi.conf` sets up the test VM. It boots a throwaway copy (`Ephemeral=yes`), so every boot is a first boot. The setup takes its answers from credentials: root's password is `test`, and the `claude` user gets the keys in `~/.ssh/*.pub` of whoever runs mkosi (`mkosi.credentials/agent.ssh-key`).
- If the container has no `~/.ssh`, make a throwaway key in `mkosi.output/test-ssh/` and mount it at `/root/.ssh`.
- `mkosi vm` needs a terminal. Without one, run it with `podman exec -d -t` and send its output to a file.
- ssh runs inside the container, which forwards port 2222 to the VM: `podman exec <container> ssh -p 2222 claude@localhost`. Pass `-F /dev/null` if ssh rejects the mounted config because of its owner.
- For root, run `su -` over ssh.
## Image version
`mkosi.version` prints the build time, so every mkosi run has a new version. `mkosi vm` then looks for an image that was never built and fails with "has not been built yet". Either rebuild with `mkosi -f vm`, or boot an existing build by pinning its version:
```sh ```sh
mkosi --image-version 202611171816 vm # the version in mkosi.output/agent_<version>.raw #!/bin/sh
# Image version
#
# Prints the build time in UTC (YYYYMMDDhhmm). Every build gets a higher
# version than the one before, which is how systemd-sysupdate tells that an
# update is newer.
``` ```
Pinning saves a full rebuild when only testing. - Line 1 is a title: a few words, in sentence case, with no full stop.
- Then a line with only the comment character.
- Then what the file does and why, naming the files it works with by path.
## Boot time Files that can't hold comments (JSON, `subuid`, `machine-id`) are explained in
the file that uses them.
Measure it over ssh with `systemd-analyze`, `systemd-analyze blame` and `systemd-analyze critical-chain`. In `blame`, the `.device` units only show when udev announced the device, not time spent, so filter them out. ### Comments
The test VM always does a first boot (setup, growfs, enrolling the Secure Boot keys). To measure a normal boot, reboot it with `systemctl reboot` as root: the throwaway copy lasts until qemu exits. Compare a few boots, since timings vary. - Explain why, not what. Leave out comments that only repeat the code. Try to
write clean code instead of many comments.
- Put a comment right above the line or block it is about.
- Write full sentences that start with the name of what they describe:
`# PackageCacheDirectory keeps downloaded packages between builds.` or
`# cred prints the credential agent.<name>, and fails if it isn't passed.`
- Wrap comments at 80 columns.
To see what systemd waits for, boot with debug logging without a rebuild: `mkosi --kernel-command-line-extra=systemd.log_level=debug vm`. ## Testing
`mkosi vm` boots the image in qemu and needs systemd on the host. Without it,
run mkosi in a privileged podman container that boots systemd:
```sh
podman build -t mkosi-vm - <<'END'
FROM registry.fedoraproject.org/fedora:45
RUN dnf install -y mkosi qemu-kvm-core edk2-ovmf systemd-repart \
openssh-clients socat && \
dnf install -y $(mkosi dependencies)
CMD ["/sbin/init"]
END
podman run -d --name mkosi --privileged --systemd=always -v <repo>:/repo \
-w /repo mkosi-vm
podman exec mkosi mkosi genkey # once, if there is no mkosi.key
podman exec -d -t mkosi sh -c 'mkosi -f vm > mkosi.output/vm.log 2>&1'
podman exec mkosi mkosi ssh -- systemctl --failed
```
podman resolves paths on the host, so `<repo>` is the repository's path there.
`mkosi vm` needs a terminal, hence `-d -t`; its console goes to the log.
`mkosi ssh` runs a command as root, once the VM has booted. For the user
`claude`, run `su - claude -c '<command>'`.
`mkosi.version` gives every run a new version, so `mkosi vm` without `-f` fails
with "has not been built yet". To boot an existing build without a rebuild, pin
its version (from `mkosi.output/agent_<version>.raw`):
```sh
mkosi --image-version 202611171816 vm
```
+25 -21
View File
@@ -1,24 +1,28 @@
# agent-mkosi # agent-mkosi
A VM that runs [Claude Code](https://claude.com/claude-code) in the background. It is a minimal Fedora image built with [mkosi](https://github.com/systemd/mkosi). You control Claude from claude.ai/code or the Claude app (Remote Control), or log in with ssh. A VM that runs [Claude Code](https://claude.com/claude-code) in the background.
It is a minimal Fedora image built with
[mkosi](https://github.com/systemd/mkosi). You control Claude from
claude.ai/code or the Claude app (Remote Control), or log in with ssh.
- **Resets at reboot:** Claude's home, `/tmp` and all containers are wiped at every boot. Only the setup answers and Claude's login survive (`/var/lib/agent`). - **Resets at reboot:** the homes of Claude and root, `/tmp` and all containers
- **Read-only OS:** the root filesystem is read-only, so Claude can't change the OS. All state lives on `/var`. are wiped at every boot. Only the setup answers, the ssh keys and Claude's
- **Tools in containers:** Claude runs as the user `claude`, without root, and runs its toolchains in containers with podman. The host has only git, ssh and basic command-line tools. login survive (`/var/lib/agent`).
- **Self-updating:** the `os` rebuilds weekly and updates with systemd-sysupdate. - **Read-only OS:** the root filesystem is read-only, so Claude can't change
the OS. All state lives on `/var`.
- **Tools in containers:** Claude runs as the user `claude`, without root, and
runs its toolchains in containers with podman. The host has only git, ssh and
basic command-line tools.
- **Self-updating:** the `os` rebuilds weekly and updates with
systemd-sysupdate.
## Install ## Install
Download [the disk image](https://git.plabble.org/api/packages/Job79/generic/agent/latest/agent.qcow2), resize it to the disk size you want and boot it with UEFI in Secure Boot setup mode. The console asks for a root password, a hostname and an ssh public key for the user `claude`. Download [the disk image](https://git.plabble.org/api/packages/Job79/generic/agent/latest/agent.qcow2),
resize it to the disk size you want and boot it with UEFI. At first boot, the
Then log Claude in once: console asks for a root password and a hostname. Then log in as root, add an
ssh key for the user `claude` and run Claude once to sign in. The VM then shows
```sh up in claude.ai/code and the Claude app under its hostname.
ssh claude@<vm>
claude # trust the folder, then /login with your Claude account
```
The VM then shows up in claude.ai/code and the Claude app under its hostname.
## Development ## Development
@@ -27,13 +31,13 @@ mkosi genkey # local test only, CI uses the SECUREBOOT_KEY secret
mkosi build mkosi build
``` ```
`mkosi.output/` then holds the disk image (`agent_<version>.raw`) and the UKI and root partitions that make up an update. `mkosi.output/` then holds the disk image (`agent_<version>.raw`) and the UKI
and root partitions that make up an update.
To build and boot a test VM (needs `qemu-kvm-core edk2-ovmf`): To build and boot a test VM (needs `qemu-kvm-core edk2-ovmf openssh-clients
socat`):
```sh ```sh
mkosi -f vm # log in as root, password test mkosi -f vm # opens its console: log in as root, password root
ssh -p 2222 claude@localhost # with your own key mkosi ssh # in another terminal: ssh in as root
``` ```
[AGENTS.md](AGENTS.md) has the details, such as testing from a dev container.
-30
View File
@@ -1,30 +0,0 @@
# Style guide
- Keep it simple. Prefer fewer files, fewer lines and the defaults. Delete what isn't needed.
- Each fact lives in one place. Elsewhere, refer to it by path instead of repeating it.
- Write plain English in short sentences.
## File header
Every file that allows comments starts with a header. It goes after the shebang, if there is one:
```sh
#!/bin/sh
# Image version
#
# Prints the build time in UTC (YYYYMMDDhhmm). Every build gets a higher version than the one
# before, which is how systemd-sysupdate tells that an update is newer.
```
- Line 1 is a title: a few words, in sentence case, with no full stop.
- Then a line with only the comment character.
- Then what the file does and why, naming the files it works with by path.
Files that can't hold comments (JSON, `subuid`, `machine-id`) are explained in the file that uses
them or in the README.
## Comments
- Explain why, not what. Leave out comments that only repeat the code.
- Put a comment right above the line or block it is about.
- Wrap comments at 80 columns.
+62 -53
View File
@@ -5,6 +5,9 @@
# Claude Code package repository. The root filesystem, /etc included, is # Claude Code package repository. The root filesystem, /etc included, is
# read-only and replaced whole by updates. All state lives on /var. Claude # read-only and replaced whole by updates. All state lives on /var. Claude
# can't change the OS, so it runs its tools in containers. # can't change the OS, so it runs its tools in containers.
# mkosi.extra/etc/claude-code/ sets Claude Code up for that:
# managed-settings.json lets it run without permission prompts, and CLAUDE.md
# tells it about this machine.
[Distribution] [Distribution]
Distribution=fedora Distribution=fedora
@@ -15,30 +18,34 @@ Format=disk
ImageId=agent ImageId=agent
OutputDirectory=mkosi.output OutputDirectory=mkosi.output
SplitArtifacts=uki,partitions SplitArtifacts=uki,partitions
# Lists the packages and versions in the image, to tell which builds a CVE # ManifestFormat lists the packages and versions in the image, to tell which
# affects. .gitea/workflows/os.yml publishes it with the image. # builds a CVE affects. .gitea/workflows/os.yml publishes it with the image.
ManifestFormat=json ManifestFormat=json
[Build] [Build]
# Keeps downloaded packages between builds, also when mkosi runs in a # PackageCacheDirectory keeps downloaded packages between builds, also when
# throwaway container (AGENTS.md). dnf still installs the newest versions. # mkosi runs in a throwaway container (AGENTS.md). dnf still installs the
# newest versions.
PackageCacheDirectory=mkosi.pkgcache PackageCacheDirectory=mkosi.pkgcache
[Content] [Content]
Bootable=yes Bootable=yes
Bootloader=systemd-boot Bootloader=systemd-boot
# - kernel-core no drivers or firmware beyond what VMs need # Packages is systemd with its network services, plus:
# - systemd-container systemd-pull, which systemd-sysupdate downloads by # - kernel-core has no drivers or firmware beyond what VMs need.
# - gnupg2 checks the signature of updates # - systemd-container has systemd-pull, which systemd-sysupdate downloads with.
# - util-linux, shadow-utils console login, setup, newuidmap for rootless podman # - gnupg2 checks the signature of updates.
# - systemd-pam login sessions: Claude's user manager and its # - systemd-boot-unsigned is the boot loader, which mkosi signs.
# D-Bus, which rootless podman needs # - util-linux and shadow-utils give the console login, the setup and
# - openssh-server ssh login for the user (keys only) # newuidmap for rootless podman.
# - zram-generator-defaults compressed swap in RAM # - systemd-pam gives login sessions: Claude's user manager and its D-Bus,
# - podman, podman-docker containers for Claude's toolchains (also as docker) # which rootless podman needs.
# - claude-code from mkosi.sandbox/etc/yum.repos.d # - openssh-server lets you log in with ssh keys.
# - git-core, openssh-clients Claude Code uses git and pushes over ssh # - zram-generator-defaults sets up compressed swap in RAM.
# - the rest basic command-line tools Claude uses on the host # - podman and podman-docker run Claude's toolchains in containers.
# - claude-code comes from mkosi.sandbox/etc/yum.repos.d.
# - git-core and openssh-clients let Claude Code use git and push over ssh.
# - The rest are basic command-line tools Claude uses on the host.
Packages= Packages=
kernel-core kernel-core
systemd systemd
@@ -70,17 +77,18 @@ Packages=
iproute iproute
WithDocs=no WithDocs=no
Locale=C.UTF-8 Locale=C.UTF-8
# Name UKIs the way systemd-sysupdate names the ones it installs. # UnifiedKernelImageFormat names UKIs the way systemd-sysupdate names the ones
# it installs.
UnifiedKernelImageFormat=%i_%v UnifiedKernelImageFormat=%i_%v
# - console= show the console on screen and on the serial port # KernelCommandLine sets:
# - systemd.machine_id= take the machine ID from the VM's firmware; # - console= shows the console on the screen and on the serial port.
# mkosi.extra/etc/machine-id is empty, so no boot # - systemd.machine_id=firmware takes the machine ID from the VM's firmware.
# counts as the first # mkosi.extra/etc/machine-id is empty, so no boot counts as the first.
# - systemd.firstboot=no agent-setup asks its own questions # - systemd.firstboot=no leaves the questions to agent-setup.
# - SYSTEMD_DEFAULT_MOUNT_ systemd handles mount changes at most 5 times per # - SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST lets systemd handle more mount
# RATE_LIMIT_BURST= second and holds back mounts once it hits that. At # changes per second. At the default of 5, it holds back mounts at boot and
# boot that delays / and /var by up to a second each. # delays / and /var by up to a second each. The kernel passes it to systemd
# The kernel passes this to systemd as environment. # as environment.
KernelCommandLine= KernelCommandLine=
console=tty0 console=tty0
console=ttyS0,115200n8 console=ttyS0,115200n8
@@ -88,7 +96,8 @@ KernelCommandLine=
systemd.machine_id=firmware systemd.machine_id=firmware
systemd.firstboot=no systemd.firstboot=no
SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST=50 SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST=50
# The initrd only needs to find and mount the disks of a VM. # KernelInitrdModules are the modules the initrd needs to find and mount the
# disks of a VM.
KernelInitrdModules= KernelInitrdModules=
virtio_blk virtio_blk
virtio_scsi virtio_scsi
@@ -97,10 +106,10 @@ KernelInitrdModules=
dm-verity dm-verity
erofs erofs
ext4 ext4
# All modules but the hardware drivers, then the drivers a VM needs (disks, # KernelModules keeps all modules but the hardware drivers, then the drivers a
# network, screen) and those of rootless podman's networks (pasta). The last # VM needs (disks, network, screen) and those of rootless podman's networks
# matching line wins. Keyboard, USB and a basic screen are built into the # (pasta). The last matching line wins. Keyboard, USB and a basic screen are
# kernel. # built into the kernel.
KernelModules= KernelModules=
/* /*
-/drivers/* -/drivers/*
@@ -116,16 +125,16 @@ KernelModules=
virtio-gpu virtio-gpu
veth veth
tun tun
# - System.map only for debugging the kernel # RemoveFiles drops what the image doesn't use:
# - udev hwdb hardware names and quirks, nothing a VM needs # - System.map is only for debugging the kernel.
# - homed, userdbd, unused services # - The udev hwdb holds hardware names and quirks, nothing a VM needs.
# nsresourced # - homed, userdbd and nsresourced are unused services.
# - sshd-keygen sshd uses one host key, kept on /var # - sshd-keygen would write host keys to the read-only /etc. sshd uses one host
# (mkosi.extra/etc/ssh/sshd_config.d) # key on /var instead (mkosi.extra/etc/ssh/sshd_config.d).
# - /afs mount point for the AFS network filesystem # - /afs is the mount point for the AFS network filesystem.
# - /buildroot dnf's lock file, left by mkosi: it passes dnf5 # - /buildroot holds dnf's lock file, left by mkosi: it passes dnf5
# persistdir=/buildroot/var/lib/dnf and dnf5 puts # persistdir=/buildroot/var/lib/dnf and dnf5 puts the install root in front
# the install root in front of it again # of it again.
RemoveFiles= RemoveFiles=
/usr/lib/modules/*/System.map /usr/lib/modules/*/System.map
/usr/lib/udev/hwdb.bin /usr/lib/udev/hwdb.bin
@@ -138,25 +147,25 @@ RemoveFiles=
/buildroot /buildroot
[Validation] [Validation]
# Sign systemd-boot and the UKI for Secure Boot, and put our keys on the ESP. # SecureBoot signs systemd-boot and the UKI, and puts our keys on the ESP.
# systemd-boot enrolls them at first boot if the firmware is in setup mode (no # systemd-boot enrolls them at first boot if the firmware is in setup mode (no
# keys enrolled; in Proxmox, an EFI disk without pre-enrolled keys). # keys enrolled; in Proxmox, an EFI disk without pre-enrolled keys). mkosi.key
# mkosi.key is the SECUREBOOT_KEY secret, which .gitea/workflows/os.yml writes. # is the SECUREBOOT_KEY secret, which .gitea/workflows/os.yml writes.
SecureBoot=yes SecureBoot=yes
SecureBootKey=mkosi.key SecureBootKey=mkosi.key
SecureBootCertificate=mkosi.crt SecureBootCertificate=mkosi.crt
[Runtime] [Runtime]
# For testing with mkosi vm. It does the setup itself (the agent.* credentials, # Runtime sets up the test VM of mkosi vm (AGENTS.md). Ephemeral boots a copy,
# mkosi.extra/usr/libexec/agent-setup). Its console is hvc0, which the UKI # so test runs don't change the built image. Credentials answer the setup
# doesn't use: with Secure Boot, systemd-stub ignores the console= mkosi # (mkosi.extra/usr/libexec/agent-setup). mkosi ssh logs in as root with
# passes. So the serial port joins that console, and replaces mkosi's network # mkosi.key, which mkosi also authorizes for root in the VM.
# to forward ssh to port 2222. Ephemeral boots a copy, so test runs don't
# change the built image.
Ephemeral=yes Ephemeral=yes
CPUs=4 CPUs=4
RAM=8G RAM=8G
RuntimeSize=40G RuntimeSize=40G
RuntimeNetwork=none # QemuArgs joins the serial port to the console mkosi vm shows (hvc0). The UKI
QemuArgs=-serial chardev:console -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22 # doesn't use hvc0: with Secure Boot, systemd-stub ignores the console= mkosi
Credentials=agent.password=test agent.hostname=agent-test mkosi.credentials/ # passes.
QemuArgs=-serial chardev:console
Credentials=agent.password=root agent.hostname=agent-test
-6
View File
@@ -1,6 +0,0 @@
#!/bin/sh
# SSH key for mkosi vm
#
# mkosi vm runs this and passes what it prints as the credential agent.ssh-key
# (mkosi.conf), so you can ssh into the test VM with your own keys.
cat ~/.ssh/*.pub 2>/dev/null || true
+8 -2
View File
@@ -1,5 +1,11 @@
# Mounts # Mounts
# #
# /var is the only partition on disk that is written (mkosi.repart/30-var.conf). # /var is the only partition on disk that is written (mkosi.repart/30-var.conf).
# x-systemd.growfs grows its filesystem to fill the partition at boot. # x-systemd.growfs grows its filesystem to fill the partition at boot. noatime
PARTLABEL=var /var ext4 x-systemd.growfs 0 2 # skips the write that the default (relatime) makes at the first read of a file
# each day. Images that podman unpacks are full of such files; nothing here uses
# access times.
PARTLABEL=var /var ext4 noatime,x-systemd.growfs 0 2
# /root is in memory, so root has a writable home that is wiped at every boot.
# Root's ssh key lives on /var (mkosi.extra/etc/ssh/sshd_config.d).
tmpfs /root tmpfs mode=0700 0 0
@@ -1,11 +1,22 @@
# ssh login # ssh login
# #
# Only the user claude may log in, only with the key asked at setup. The host # Login is with keys only, for root and the user claude. Neither has a key
# key lives on /var (agent-boot makes it), so it stays the same across reboots. # until root adds one (README.md). The first value wins, and this file sorts
# The first value wins, and this file sorts before Fedora's 50-redhat.conf. # before Fedora's 50-redhat.conf.
# HostKey lives on /var (agent-boot makes it), so it stays the same across
# reboots.
HostKey /var/lib/agent/ssh_host_ed25519_key HostKey /var/lib/agent/ssh_host_ed25519_key
AuthorizedKeysFile /var/lib/agent/authorized_keys
AllowUsers claude
PermitRootLogin no
PasswordAuthentication no PasswordAuthentication no
KbdInteractiveAuthentication no KbdInteractiveAuthentication no
# AuthorizedKeysFile of the user claude is owned by root, so Claude can't add
# keys.
Match User claude
AuthorizedKeysFile /var/lib/agent/authorized_keys
# AuthorizedKeysFile of root is on /var, because its home is wiped at every
# boot (/etc/fstab). It also reads the default file, which the
# ssh.authorized_keys.root credential fills, such as for mkosi ssh.
Match User root
AuthorizedKeysFile /var/lib/agent/root_authorized_keys .ssh/authorized_keys
@@ -10,5 +10,6 @@ Kind=!*
DHCP=yes DHCP=yes
[DHCPv4] [DHCPv4]
# The hostname is the one asked at setup (agent-boot), not the DHCP server's. # UseHostname=no keeps the hostname asked at setup (agent-boot) instead of the
# DHCP server's.
UseHostname=no UseHostname=no
@@ -6,8 +6,8 @@
enable systemd-networkd.service enable systemd-networkd.service
enable systemd-resolved.service enable systemd-resolved.service
enable sshd.service enable sshd.service
# Fedora disables the login on the screen (tty1, and tty2-6 through its # getty@.service is the login on the screen, which Fedora disables (tty1, and
# autovt@ alias). # tty2-6 through its autovt@ alias).
enable getty@.service enable getty@.service
enable agent-setup@.service tty1 ttyS0 enable agent-setup@.service tty1 ttyS0
enable etc-shadow.mount enable etc-shadow.mount
@@ -15,8 +15,8 @@ enable agent-boot.service
enable claude-remote.path enable claude-remote.path
enable systemd-sysupdate-update.timer enable systemd-sysupdate-update.timer
enable systemd-sysupdate-reboot.timer enable systemd-sysupdate-reboot.timer
# Fedora enables these, but they do nothing here: no PAM or crypto changes on a # These services do nothing here, but Fedora enables them: no PAM or crypto
# read-only /etc, and no system or config extensions. # changes on a read-only /etc, and no system or config extensions.
disable authselect-apply-changes.service disable authselect-apply-changes.service
disable fips-crypto-policy-overlay.service disable fips-crypto-policy-overlay.service
disable systemd-sysext.service disable systemd-sysext.service
@@ -18,7 +18,7 @@ StandardOutput=tty
TTYPath=/dev/%I TTYPath=/dev/%I
TTYReset=yes TTYReset=yes
TTYVHangup=yes TTYVHangup=yes
# Being stopped by the other console is not a failure. # SuccessExitStatus counts being stopped by the other console as success.
SuccessExitStatus=SIGTERM SuccessExitStatus=SIGTERM
[Install] [Install]
@@ -11,7 +11,8 @@ After=network-online.target user@1000.service agent-boot.service
[Service] [Service]
User=claude User=claude
WorkingDirectory=~ WorkingDirectory=~
Environment=CLAUDE_CONFIG_DIR=/var/lib/agent/claude XDG_RUNTIME_DIR=/run/user/1000 EnvironmentFile=/etc/environment
Environment=XDG_RUNTIME_DIR=/run/user/1000
ExecStart=/usr/bin/claude remote-control --name %H ExecStart=/usr/bin/claude remote-control --name %H
Restart=always Restart=always
RestartSec=10s RestartSec=10s
+6 -5
View File
@@ -3,13 +3,14 @@
# What survives a reboot and what doesn't. Claude can only write to the wiped # What survives a reboot and what doesn't. Claude can only write to the wiped
# directories, /tmp and its own config. # directories, /tmp and its own config.
# Kept: the setup answers, the ssh host key and Claude's login. agent-boot # /var/lib/agent keeps the setup answers, the ssh keys and Claude's login.
# wipes the rest of Claude's config. # agent-boot wipes the rest of Claude's config.
d /var/lib/agent 0755 root root - d /var/lib/agent 0755 root root -
d /var/lib/agent/claude 0700 claude claude - d /var/lib/agent/claude 0700 claude claude -
# Wiped at every boot (D): Claude's home, with its podman storage, and # D wipes Claude's home, with its podman storage, and temporary files at every
# temporary files. # boot.
D /var/home/claude 0700 claude claude - D /var/home/claude 0700 claude claude -
D /var/tmp 1777 root root - D /var/tmp 1777 root root -
# Start Claude's user manager at boot, for rootless podman and its own services. # linger starts Claude's user manager at boot, for rootless podman and its own
# services.
f /var/lib/systemd/linger/claude f /var/lib/systemd/linger/claude
+22 -15
View File
@@ -1,24 +1,25 @@
#!/bin/bash #!/bin/bash
# First-boot setup # First-boot setup
# #
# Asks for the root password, the hostname and the ssh key of the user claude # Asks for the root password and the hostname (agent-setup@.service). /etc is
# (agent-setup@.service). /etc is read-only, so the answers go to # read-only, so the answers go to /var/lib/agent. The password goes into a
# /var/lib/agent. The password goes into a shadow file there, which # shadow file there, which etc-shadow.mount puts over /etc/shadow. agent-boot
# etc-shadow.mount puts over /etc/shadow. agent-boot applies the rest at every # applies the rest at every boot. Root adds the ssh keys afterwards
# boot. # (README.md).
# #
# With the credential agent.password, it asks nothing and takes the answers # With the credential agent.password, it asks nothing and takes the answers
# from the credentials agent.password, agent.hostname and agent.ssh-key. mkosi # from the credentials agent.password and agent.hostname. mkosi vm passes them
# vm passes them (mkosi.conf). # (mkosi.conf).
set -euo pipefail set -euo pipefail
# cred prints the credential agent.<name>, and fails if it isn't passed.
cred() { cat "${CREDENTIALS_DIRECTORY:-/nonexistent}/agent.$1" 2>/dev/null; } cred() { cat "${CREDENTIALS_DIRECTORY:-/nonexistent}/agent.$1" 2>/dev/null; }
if pw=$(cred password); then if pw=$(cred password); then
# Both consoles run this script. Only one may do the setup. # flock lets only one of the two consoles do the setup.
exec 9>/run/agent-setup.lock exec 9>/run/agent-setup.lock
flock -n 9 || exit 0 flock -n 9 || exit 0
name=$(cred hostname) || true name=$(cred hostname) || true
key=$(cred ssh-key) || true
else else
echo "== Agent setup ==" echo "== Agent setup =="
while :; do while :; do
@@ -28,18 +29,24 @@ else
echo "Passwords do not match, try again." echo "Passwords do not match, try again."
done done
read -rp "Hostname [agent]: " name read -rp "Hostname [agent]: " name
read -rp "SSH public key for the user claude: " key
fi fi
install -d -m 0700 /var/lib/agent/etc install -d -m 0700 /var/lib/agent/etc
# etc-shadow.mount is stopped first: an interrupted setup may have started it,
# and then cp would copy the shadow file onto itself.
systemctl stop etc-shadow.mount
cp /etc/passwd /etc/shadow /var/lib/agent/etc/ cp /etc/passwd /etc/shadow /var/lib/agent/etc/
echo "root:$pw" | chpasswd --prefix /var/lib/agent echo "root:$pw" | chpasswd --prefix /var/lib/agent
systemctl start etc-shadow.mount systemctl start etc-shadow.mount
[[ -n $key ]] && install -m 0644 /dev/stdin /var/lib/agent/authorized_keys <<<"$key" # hostname is written last: its presence marks the setup as done.
# Written last: its presence marks the setup as done.
echo "${name:-agent}" > /var/lib/agent/hostname echo "${name:-agent}" > /var/lib/agent/hostname
systemctl start agent-boot.service sshd.service systemctl start agent-boot.service sshd.service
echo "Done. Log in with ssh claude@<this VM>, run claude and log in with your account." cat <<'EOF'
echo "Remote Control then starts by itself." Done. Log in as root and add your ssh key for the user claude to
# Stop the setup on the other console, which then shows its login. /var/lib/agent/authorized_keys (for root: root_authorized_keys there). Then
log in with ssh claude@<this VM>, run claude and log in with your account.
Remote Control then starts by itself.
EOF
# systemctl stop ends the setup on the other console, which then shows its
# login.
systemctl --no-block stop "agent-setup@*.service" systemctl --no-block stop "agent-setup@*.service"
+2 -2
View File
@@ -14,6 +14,6 @@ Verity=data
VerityMatchKey=root VerityMatchKey=root
SizeMinBytes=1G SizeMinBytes=1G
SizeMaxBytes=1G SizeMaxBytes=1G
# roothash= finds the root by its partition UUID, so the file name holds it # SplitName holds the partition UUID (%U): roothash= finds the root by it, and
# and updates keep it (@u in mkosi.extra/usr/lib/sysupdate.d). # updates keep it (@u in mkosi.extra/usr/lib/sysupdate.d).
SplitName=%t.%U SplitName=%t.%U