Files
w3cjandClaude Opus 5.5 e85e85d075 build(cosign): the units, install.sh and the co-signer's docs
- [email protected], a template: devvm-cosign@run for the timer, and
  @check and @init for setting up. The keys are root's, mode 0600, and
  reach the service only as systemd's credentials (LoadCredential=), in
  a folder of its own while it runs; the base's key comes from a drop-in,
  devvm-cosign-base.conf, which install.sh installs once there is one, as
  a credential that isn't there fails the service. Its processes are in
  a PID namespace of their own (PrivatePIDs=), and any failure starts
  devvm-cosign-failed.service (OnFailure=).
- devvm-cosign-podman.service, where a process that escapes a build's
  container lands: a PID namespace of its own, so no other process's
  /proc/<pid>/root; the config, the keys, every service's credentials and
  the whole state folder inaccessible; its HOME, with podman's config and
  storage, and its only writable folder, the build folder,
  /var/lib/devvm-cosign-build; StopWhenUnneeded=, so it runs only while
  a run needs it; each start deletes the whole build folder, podman's
  config first, then its images and containers (podman system reset),
  then the rest, so nothing a build left, a link or a config pointing
  podman at another runtime, reaches the next; and OnFailure=, as a run
  whose podman fails to start doesn't fail itself.
- devvm-cosign-failed.service runs devvm-cosign failed, which tells the
  maintainer through the config's notify command, reading no key.
- devvm-cosign.timer starts devvm-cosign@run hourly.
- install.sh: 65536 subordinate IDs from the first multiple of 65536
  above every range another user has in /etc/subuid or /etc/subgid, so
  no two users' containers share an ID; the state folder and the build
  folder, with the folders the units need; the config readable by the
  co-signer's group, for retry and ack; the old devvm-cosign.service
  removed.
- Docs: contributing/cosigner.md for the new flow: what CI hands over,
  what a run does (the old step 8 split into the draft, the publish and
  the check after), refusals and alerts, retry, ack and notify through
  OnFailure (HTTPS, not a local sendmail, under NoNewPrivileges), the
  base's snapshot bound and why, its files, the config's new keys and
  the credentials' names and modes, the setup with the Go the tag's
  mise.lock pins (mise exec), the units, what a build's container can
  reach and what's still shared (the user and the machine: an escape can
  slow or change the build it's in, which then doesn't match, and use
  the network while that run lasts; a kernel escape gets past it all),
  the GitHub App's Actions: read and the tap ruleset's bypass, that the
  units name the folders, and moving machines by copying
  /var/lib/devvm-cosign but stage/, src/ and cache/. maintaining.md's
  Release keys say who publishes, as it is; structure.md's package row;
  the 0.2.0 page and the changelog line.

Validated on Fedora 43 (SELinux enforcing, podman 5.6, systemd 258), in
a throwaway Lima VM: install.sh, then check, init and a run under these
units with rootless podman, against the fake GitHub over TLS with a
throwaway v9.9.9 and throwaway keys. CI's build was release.sh --tag
under rootless podman, handed over as an artifact; the co-signer cloned
its root-owned checkout, rebuilt, matched, signed, made the release,
published it and wrote both formulas, the same bytes as CI's build's.
Both signatures verified with minisign, every file with SHA256SUMS, the
podman unit stopped after the run, and a second run did nothing. During
the build, from the podman service's namespaces as the co-signer's
user: only the build's own processes were there, so release.sh's and
the run's /proc/<pid>/root weren't; the state folder, the clone
release.sh ran from and CI's staged files were refused; and only the
build folder was writable; only SHA256SUMS and CI's signature were
staged; and the build's finished files and the download cache were in
the state folder. A second start of the podman service reset the last
build's images and containers and left an empty build folder. A run
failed with GitHub gone started devvm-cosign-failed, whose notify got
the recorded failure, and a podman start that failed started it too. The first
runs found three things the fake can't, fixed in the earlier commits:
podman needs ~/.config, which install.sh now makes; system credentials
are mode 0440 with an ACL; and the clone needs the checkout's .git named
safe.

The podman service's first ExecStartPre deletes the co-signer's user's
/dev/shm/libpod* files, podman's locks, which outlive the service and no
folder it empties holds (TestPodmanUnitStartsClean). cosigner.md also
covers a build that keeps failing and GitHub's latest release.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 21:36:37 -07:00

76 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
# Install devvm's co-signer on this Linux machine, as root:
# packaging/cosign/install.sh BINARY
# BINARY is devvm-cosign, built from the release tag you checked (go build -trimpath -o devvm-cosign
# ./cmd/devvm-cosign). It installs it as /usr/local/bin/devvm-cosign, makes the user devvm-cosign
# (with subordinate IDs for rootless podman), its folders /etc/devvm-cosign, /var/lib/devvm-cosign
# and /var/lib/devvm-cosign-build, and the systemd units beside this script, then says what's left: the
# config, the keys, devvm's checkout, the first state and the timer. It installs no package and
# starts nothing. Running it again replaces the binary and the units and keeps everything else.
# docs/content/docs/contributing/cosigner.md is the whole setup.
set -euo pipefail
die() { echo "install: $*" >&2; exit 1; }
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
user=devvm-cosign state=/var/lib/devvm-cosign build=/var/lib/devvm-cosign-build etc=/etc/devvm-cosign
case ${1:-} in
-h | --help) awk 'NR > 1 && !/^#/ { exit } NR > 1 { sub(/^# ?/, ""); print }' "$0"; exit 0 ;;
esac
[[ $# == 1 ]] || die "usage: packaging/cosign/install.sh BINARY"
bin=$1
[[ -f $bin && -x $bin ]] || die "$bin isn't an executable file"
[[ $(uname -s) == Linux ]] || die "the co-signer runs on Linux"
((EUID == 0)) || die "run it as root (sudo), as it makes a user and installs systemd units"
command -v systemctl >/dev/null || die "needs systemd"
# What the co-signer runs, which this script never installs.
missing=()
for c in git bash curl ssh-keygen podman; do command -v "$c" >/dev/null || missing+=("$c"); done
((${#missing[@]} == 0)) || die "install ${missing[*]} first (dnf install or apt install)"
# arm64's base builds under qemu-user on any other machine: binfmt's handler, registered once.
if [[ $(uname -m) != aarch64 && ! -e /proc/sys/fs/binfmt_misc/qemu-aarch64 ]]; then
echo "install: no qemu-aarch64 handler in binfmt_misc: the co-signer rebuilds releases without it, but bases need it (see the setup page)" >&2
fi
if ! id "$user" >/dev/null 2>&1; then
useradd --system --user-group --home-dir "$state" --no-create-home --shell /usr/sbin/nologin "$user"
fi
# Rootless podman maps the container's users to subordinate IDs of the user's own: 65536 of them,
# from the first multiple of 65536 above every range another user has in /etc/subuid or
# /etc/subgid, so no two users' containers share an ID.
if ! grep -q "^$user:" /etc/subuid || ! grep -q "^$user:" /etc/subgid; then
from=$(cat /etc/subuid /etc/subgid 2>/dev/null |
awk -F: -v u="$user" '$1 != u && $2 ~ /^[0-9]+$/ && $3 ~ /^[0-9]+$/ && $2 + $3 > end { end = $2 + $3 }
END { end = end < 100000 ? 100000 : end; print int((end + 65535) / 65536) * 65536 }')
grep -q "^$user:" /etc/subuid || usermod --add-subuids "$from-$((from + 65535))" "$user"
grep -q "^$user:" /etc/subgid || usermod --add-subgids "$from-$((from + 65535))" "$user"
fi
# The config is readable by the co-signer's user, for devvm-cosign retry and ack; the keys in it
# are root's alone, and reach the service as systemd's credentials.
install -d -m 0750 -o root -g "$user" "$etc"
# The state folder, which no build's container can reach, and the build folder, all the containers
# and the podman service write: its HOME, with podman's config and storage.
install -d -m 0700 -o "$user" -g "$user" "$state" "$state/src" "$state/stage" "$state/cache" "$build" "$build/work" \
"$build/.config" "$build/.local" "$build/.local/share" "$build/.local/share/containers"
install -m 0755 -o root -g root "$bin" /usr/local/bin/devvm-cosign
rm -f /etc/systemd/system/devvm-cosign.service
for u in [email protected] devvm-cosign.timer devvm-cosign-podman.service devvm-cosign-failed.service; do
install -m 0644 -o root -g root "$here/$u" "/etc/systemd/system/$u"
done
if [[ -f $etc/base.key ]]; then
install -d -m 0755 /etc/systemd/system/[email protected]
install -m 0644 -o root -g root "$here/devvm-cosign-base.conf" /etc/systemd/system/[email protected]/base.conf
fi
systemctl daemon-reload
cat <<EOF
Installed /usr/local/bin/devvm-cosign and its units. What's left, as the setup page says:
1. $etc/config.toml (root's, group $user, mode 0640), and its key files, root's, mode 0600;
with a base key, run this script again to load it
2. devvm's checkout at the release tag you checked, where the config says
3. systemctl start devvm-cosign@check devvm-cosign@init, and read what they did with
journalctl -u devvm-cosign@check -u devvm-cosign@init
4. systemctl enable --now devvm-cosign.timer
EOF