mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
The signing design's first phase. The same tag, built by two builders, now gives byte-identical archives, source tarball, install.sh, SHA256SUMS and formulas. - scripts/release.sh builds every file but the signature in one container, release_image (Debian's buildpack-deps:trixie-scm, pinned by its index's digest), under podman or Docker (DEVVM_RELEASE_RUNTIME), on this machine's processor. The image and the code that runs in the build's container (_build) are the built commit's copies, so a tag builds the same from any checkout; a commit whose release.sh pins no release_image is refused. Everything outside the build's container is the checkout's: the tag's checks, the downloads, the modules' container, the checks on what the build wrote, and the signature. - The build has no network (--network none). The Go modules come first, in a container of their own, the only one with the network, which runs only the checkout's code: its release_image, its release.sh _modules and the Go its mise.lock pins, given only the commit's go.mod and go.sum, read-only, and downloading from proxy.golang.org alone (GOVCS=*:off, GOWORK=off). The checkout's Go rather than the commit's, so a commit can't pick an old Go with a known flaw for the step with the network, and rather than refusing a commit whose Go is older than the checkout's, which would refuse every old tag once mise.lock moves on, though rebuilding old tags is what --tag is for; go.sum pins the module files, so the bytes don't depend on which Go downloaded them. A commit whose go.mod needs a newer Go than the checkout's is refused before anything runs. Every module path the commit's go.mod names is looked up on Google's proxy and checksum database, which the docs say. The build reads the modules read-only as a GOPROXY's files (file:///mod). - Every container runs with --cap-drop ALL, --security-opt no-new-privileges, --pids-limit 8192, --memory 8g and --entrypoint bash, so a setuid file in the commit's image gives no privileges under a rootful runtime, root in it can't chown, a fork bomb or a runaway allocation stops at the container's limits, and the image's entrypoint never runs; Go and GoReleaser are unpacked with tar --no-same-owner. Both runtimes take both limits; rootless podman applies them on cgroups v2 with the pids and memory controllers delegated, as systemd does, and CI's runner needs the same. A full build peaked at 330 processes and 1.8 GiB under Docker Desktop on 10 CPUs. Neither runtime can bound a bind mount's disk use, so the docs say that a running build can fill the temp folder's disk until the time limit. - Each container is named for its run (devvm-release-<the temp folder's suffix>-<n>), so no other run's container, even one left over, has the name, and it's removed (rm -f, then its client ended, then rm -f again): after two hours (DEVVM_RELEASE_TIMEOUT seconds) by a watchdog, and as soon as release.sh stops early. The client runs in the background, so Ctrl+C (INT), a closed terminal (HUP) and kill (TERM) run release.sh's traps at once, which exit through the EXIT trap that removes the container; in the foreground, bash would wait for the client, and the client for the container's PID 1, bash, which ignores them. After kill -9, the watchdog, which outlives release.sh and ignores INT and HUP, removes the container and the temp folder. - Go and GoReleaser are the built commit's mise.lock downloads for linux-arm64 or linux-x64, kept in ~/.cache/devvm-release by SHA-256 and checked before each use, as is the modules' Go from the checkout's mise.lock. A URL has to start with https://dl.google.com/go/ or GoReleaser's releases/download/, can't hold .. or %, which curl decodes (so %2e%2e can't be ..), and goes to curl as --url's value (a lock URL of -K<file> was curl options, run on the host); file:// only from the folder that DEVVM_RELEASE_TEST_FILE_URLS names, which only the tests set, and only when it exists and isn't /. curl: HTTPS redirects only, 30 s to connect, 15 minutes, 1 GiB. A lock with two entries for a tool, or two downloads for the platform, is refused. - The build's repository is new (git init --template=), holding only the commit and, for a tag, the tag, fetched into a pack: no other branches, tags or objects of the maintainer's, no hardlinked files the container could write, and origin set to devvm's GitHub URL, which GoReleaser needs and nothing fetches. Go stamps the binary from the tags it finds, so it finds only the release's. - The container runs as root under a rootless runtime and as you under a rootful one, from the runtime's info (podman's Host.Security.Rootless, Docker's security options), never its name; a runtime that doesn't answer stops the build. Inside: umask 022, TZ=UTC, LC_ALL=C.UTF-8, GOTOOLCHAIN=local, -mod=readonly, no git config but safe.directory, and Go's caches in a container-local folder (Docker Desktop's share lost files that parallel module downloads renamed). - The build writes its files to /out, a mount of its own that it can't swap for a link. Before anything is copied, signed or kept, the folder has to be the one release.sh made, not a link, and everything in it a file or a folder, never a link, yours, and neither setuid, setgid, sticky nor world-writable, and 2 GiB at most, counted as read (sparse files whole) and read no further. The files are then copied to dist/, never moved, as yours with mode 0755 or 0644. minisign signs outside, after the containers are gone. - release.sh --commit COMMIT builds any commit as --head does, with its VERSION; release.sh --tag TAG builds a tag as its release, with its checks, unsigned, to compare with a published SHA256SUMS. An unsigned build never replaces a dist/ that holds SHA256SUMS.minisig, and a build signed with a test key never replaces one whose SHA256SUMS verifies with the checkout's packaging/minisign.pub, the release key. - .goreleaser.yaml: builds_info and every file's info set owner and group root, mode 0755/0644 and the commit's time. - scripts/repro-check.sh [COMMIT | TAG] builds twice with the checkout's release.sh, so no commit's code runs on the host directly. Build 2 fetches from a repository with a stray tag, v0.0.0-stray, at the commit, and runs under Docker where build 1 runs under podman when both are installed (root against your user); every platform archive's files have to be root's with mode 0755 or 0644 (tar -tv). A build that leaves no release fails, whatever its exit status. CI's repro job runs it under the runner's podman and Docker, with a 45-minute limit. The docs say that building a commit runs its code, in a container only as isolated as the runtime keeps it, so an outside commit is built only with the maintainer's go-ahead, and that rebuilding an old tag needs proxy.golang.org to still serve its modules. - scripts/bump.sh release-image moves the container's digest, the SHA-256 of the index it fetched, after checking the index lists linux/amd64 and linux/arm64; TestBumpCoversPins finds the pin. - Tests: release_head.txtar, publish.txtar and the new repro_check.txtar run the scripts through podman and docker stubs and a mise.lock of file:// tarballs. New cases: -K, http://, another host, .. and a percent-encoded .. in a lock URL refused before curl runs, file:// refused without the switch, with it set to 1, to a folder that doesn't exist, to / and from another folder, curl's bounds, two go entries, the build's repository's tags, refs, objects, hardlinks and origin, a stray tag kept out, the image and build code taken from the commit, a commit with no release_image, each runtime's user (rootless and rootful podman and Docker, podman behind docker, no answer), both containers' run lines (security options, limits, entrypoint, --network none, mounts), each container's name its run's (the stub checks it against the run's temp folder), the modules' container getting only go.mod, go.sum, Go and the checkout's release.sh, in the checkout's image, with the checkout's Go, a go.mod newer than the checkout's Go refused before any container, and the build reading its modules; refused output: a link in it, the output folder swapped for a link, a mode 4755, 2755 or 0666 file, a mode 1755 or 0777 folder, a sparse file a byte over 2 GiB (a file of another user's needs root to test, which the test says); a mode 0600 file copied as 0644; a build past DEVVM_RELEASE_TIMEOUT removed by name; release.sh sent INT, HUP and TERM mid-build, ending within 10 s through its trap, and kill -9, each leaving no container, process or temp folder; an unsigned --head and --tag refused over a signed dist/, and a test-key build over a release-key one; --commit never running the commit's host code, --tag's unsigned build matching the signed SHA256SUMS, and repro-check catching a build that records its user, archives that aren't root's, and a release.sh that builds nothing; bump.txtar covers the platform check. Each fails with its fix taken out, which was checked for every fix of the third review: the name, the limits, the test-key refusal, %, the folder's existence and /, the size cap, setgid, sticky, the signal traps, the EXIT trap's removal, the watchdog's removal after kill -9, the client in the background (in the foreground, INT took 60 s), the checkout's Go and the Go version check. Proof, with a throwaway commit whose _build probes its container and leaves a mode 4755 copy of bash and a mode 0666 file in /out, built by this release.sh under Docker Desktop on an arm64 Mac, and under rootful Docker and rootless podman on x86_64 Fedora: every build ran with CapEff and CapBnd 0, NoNewPrivs 1 and no network, couldn't write /mod or rename /out, and was refused before anything was kept; rootful Docker refused its chown to root. The same image under the old run line, on Fedora's rootful Docker: CapBnd a80425fb, NoNewPrivs 0, and proxy.golang.org reachable. Real builds of this commit, stopped 20 s into the build's container: under Docker Desktop, INT, TERM and HUP ended release.sh within 3 s (exit 130, 143, 129) with no container left at once, and kill -9 left the container running for the watchdog, which had removed it and the temp folder 5 s later. The same on Fedora under rootless podman (INT, kill -9, TERM, HUP) and rootful Docker (INT, kill -9). Afterwards no devvm-release container or temp folder was left on either machine. repro-check on this commit, a prerelease (no devvm.rb), agreed on all eight files on the Mac (Docker Desktop, both builds) and on Fedora (rootless podman as root, then rootful Docker as cj), and the two machines' printouts were the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
201 lines
8.5 KiB
Plaintext
201 lines
8.5 KiB
Plaintext
# scripts/repro-check.sh: two builds of a commit or a tag by this
|
|
# checkout's release.sh, compared, in a throwaway repo with a goreleaser
|
|
# that writes the same small dist/ each time (unless told to record what
|
|
# a real one would leak), a mise.lock of file:// tarballs, and a podman
|
|
# and a docker that run the container's command here. The system's
|
|
# commands, not the stubs (ssh-keygen's): git signs with ssh-keygen.
|
|
[!exec:git] skip
|
|
env GIT_CONFIG_NOSYSTEM=1
|
|
env PATH=$WORK/bin:/usr/bin:/bin
|
|
env DEVVM_RELEASE_TEST_FILE_URLS=$WORK/tools
|
|
env XDG_CACHE_HOME=$WORK/cache
|
|
cp bin/podman bin/docker
|
|
chmod 755 bin/goreleaser
|
|
chmod 755 bin/podman
|
|
chmod 755 bin/docker
|
|
exec bash repo.sh
|
|
|
|
# HEAD, twice: the second build under Docker, as you, where the first ran
|
|
# under podman, as root, and from a repository with a stray tag, and the
|
|
# two agree, every archive's files root's.
|
|
exec repo/scripts/repro-check.sh
|
|
stdout '^==> build 1: under podman as 0:0, from this repository$'
|
|
stdout '^==> build 2: under docker as \d+:\d+, from one with a stray tag, v0\.0\.0-stray, at the commit$'
|
|
! stdout 'same user'
|
|
stdout '^[0-9a-f]{64} devvm-1\.2\.3-linux-arm64\.tar\.gz$'
|
|
stdout '^[0-9a-f]{64} SHA256SUMS$'
|
|
stdout '^==> both builds of HEAD \([0-9a-f]{40}\) made the same bytes$'
|
|
! stdout DIFFERS
|
|
|
|
# A build that records the user it ran as, as GoReleaser does without the
|
|
# archives' owner set: the two differ.
|
|
env GR_RECORD=user
|
|
! exec repo/scripts/repro-check.sh
|
|
stdout ' devvm-1\.2\.3-linux-arm64\.tar\.gz DIFFERS: build 2 made [0-9a-f]{64}$'
|
|
stderr '^repro-check: the two builds differ$'
|
|
|
|
# Archives whose files are the user's on disk, not root's: refused, though
|
|
# both builds ran as the same user here and agree.
|
|
env GR_RECORD=disk
|
|
env DEVVM_RELEASE_RUNTIME=docker
|
|
! exec repo/scripts/repro-check.sh
|
|
stdout '^\(both ran as the same user'
|
|
! stdout DIFFERS
|
|
stdout '^ devvm-1\.2\.3-linux-arm64\.tar\.gz, build 1: not root''s with mode 0755 or 0644: '
|
|
stderr '^repro-check: an archive holds a file that isn''t root''s with mode 0755 or 0644$'
|
|
env GR_RECORD=
|
|
env DEVVM_RELEASE_RUNTIME=
|
|
|
|
# A release.sh that ends without building but exits 0, as macOS's bash
|
|
# 3.2 can after a syntax error: refused.
|
|
exec bash -c 'printf ''#!/bin/bash\nexit 0\n'' > repo/scripts/release.sh'
|
|
! exec repo/scripts/repro-check.sh
|
|
stderr '^repro-check: build 1 made no release: its log is above$'
|
|
exec git -C repo checkout -q scripts/release.sh
|
|
|
|
# Another commit is built by this checkout's release.sh, never its own:
|
|
# HEAD~1's would touch outside here, outside its container.
|
|
exec bash outside.sh
|
|
exec repo/scripts/repro-check.sh HEAD~1
|
|
stdout '^==> both builds of HEAD~1 \([0-9a-f]{40}\) made the same bytes$'
|
|
! exists outside
|
|
|
|
# A tag builds as its release does, with its checks, unsigned.
|
|
exec bash tag.sh
|
|
exec repo/scripts/repro-check.sh v1.2.3
|
|
stdout '^==> both builds of v1\.2\.3 \([0-9a-f]{40}\) made the same bytes$'
|
|
grep 'GORELEASER_CURRENT_TAG=v1\.2\.3$' log
|
|
|
|
! exec repo/scripts/repro-check.sh HEAD v1.2.3
|
|
stderr '^repro-check: too many arguments'
|
|
! exec repo/scripts/repro-check.sh no-such-commit
|
|
stderr '^repro-check: no commit no-such-commit$'
|
|
|
|
-- repo.sh --
|
|
# A repo with release.sh and repro-check.sh, the formula, an install.sh to
|
|
# fill in, VERSION 1.2.3, the release key's public key, a release signer,
|
|
# a key git trusts, and a mise.lock pinning a Go and this test's
|
|
# goreleaser (tools.sh).
|
|
set -eu
|
|
mkdir -p repo/scripts repo/packaging/homebrew keys
|
|
cp "$DEVVM_REPO/scripts/release.sh" "$DEVVM_REPO/scripts/repro-check.sh" repo/scripts/
|
|
cp "$DEVVM_REPO/packaging/homebrew/devvm.rb" repo/packaging/homebrew/
|
|
echo 1.2.3 > repo/VERSION
|
|
printf 'module example.com/x\n\ngo 1.22\n' > repo/go.mod
|
|
printf '#!/bin/sh\nrelease_version=""\nminisign_key=""\n' > repo/install.sh
|
|
printf 'untrusted comment: a test key\nRWQtestkeytestkeytestkeytestkeytestkeytestkeytestkey\n' > repo/packaging/minisign.pub
|
|
ssh-keygen -q -t ed25519 -N '' -C good -f keys/good
|
|
printf 'e@e %s\n' "$(cat keys/good.pub)" > keys/allowed
|
|
ssh-keygen -lf keys/good.pub | awk '{ print $2 }' > repo/packaging/release-signer
|
|
bash tools.sh > repo/mise.lock
|
|
git -C repo init -q
|
|
git -C repo config user.email e@e
|
|
git -C repo config user.name e
|
|
git -C repo config gpg.format ssh
|
|
git -C repo config gpg.ssh.allowedSignersFile "$PWD/keys/allowed"
|
|
git -C repo add -A
|
|
git -C repo commit -qm r
|
|
-- tag.sh --
|
|
# The tag v1.2.3 at HEAD, signed with the release signer's key.
|
|
git -C repo -c user.signingkey="$PWD/keys/good" tag -s v1.2.3 -m v1.2.3
|
|
-- outside.sh --
|
|
# HEAD~1: a release.sh that touches outside when it runs outside its
|
|
# container; HEAD: back to HEAD~2.
|
|
set -eu
|
|
awk '{ print } /^root=/ { print "touch \"$WORK/outside\"" }' repo/scripts/release.sh > rs
|
|
cat rs > repo/scripts/release.sh
|
|
git -C repo commit -qam outside
|
|
git -C repo revert --no-edit HEAD >/dev/null
|
|
-- tools.sh --
|
|
# A mise.lock's go and goreleaser, for both Linux processors: tarballs of a
|
|
# go that does nothing and of bin/goreleaser, by file URL and SHA-256.
|
|
set -eu
|
|
mkdir -p tools/go/bin
|
|
printf '#!/bin/sh\n' > tools/go/bin/go
|
|
chmod 755 tools/go/bin/go
|
|
tar -czf tools/go.tar.gz -C tools go
|
|
tar -czf tools/goreleaser.tar.gz -C bin goreleaser
|
|
for t in go goreleaser; do
|
|
sum=$({ sha256sum "tools/$t.tar.gz" 2>/dev/null || shasum -a 256 "tools/$t.tar.gz"; } | cut -c1-64)
|
|
printf '[[tools.%s]]\nversion = "1.30.0"\n\n' "$t"
|
|
for p in linux-arm64 linux-x64; do
|
|
printf '[tools.%s."platforms.%s"]\nchecksum = "sha256:%s"\nurl = "file://%s"\n\n' "$t" "$p" "$sum" "$PWD/tools/$t.tar.gz"
|
|
done
|
|
done
|
|
-- bin/podman --
|
|
#!/bin/bash
|
|
# A container runtime, here: rootless podman, or rootful Docker when it's
|
|
# called docker. --version says which, and info whether it's rootless. run
|
|
# runs --entrypoint, then the command, with each -v's container folder
|
|
# replaced by its host folder, in -w's folder, with each -e's variable set
|
|
# and RT_USER set to --user's.
|
|
set -eu
|
|
podman=true
|
|
[[ ${0##*/} != docker ]] || podman=false
|
|
case $1 in
|
|
--version)
|
|
if $podman; then echo 'podman version 5.6.0'; else echo 'Docker version 28.5.1, build e180ab8'; fi
|
|
exit 0 ;;
|
|
info)
|
|
if $podman; then echo true; else echo '["name=seccomp,profile=builtin"]'; fi
|
|
exit 0 ;;
|
|
run) ;;
|
|
*) echo "runtime: no fake for $*" >&2; exit 1 ;;
|
|
esac
|
|
shift
|
|
from=() to=() dir= entry=()
|
|
while [[ $1 == -* ]]; do
|
|
case $1 in
|
|
--rm) shift ;;
|
|
--platform | --name | --security-opt | --cap-drop | --pids-limit | --memory | --network) shift 2 ;;
|
|
--entrypoint) entry=("$2"); shift 2 ;;
|
|
--user) export RT_USER=$2; shift 2 ;;
|
|
-v) IFS=: read -r h c _ <<<"$2"; from+=("$c"); to+=("$h"); shift 2 ;;
|
|
-w) dir=$2; shift 2 ;;
|
|
-e) export "${2?}"; shift 2 ;;
|
|
*) echo "runtime: no fake for $1" >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
shift
|
|
set -- ${entry[@]+"${entry[@]}"} "$@"
|
|
map() {
|
|
local a=$1 i
|
|
for i in "${!from[@]}"; do [[ $a != "${from[i]}"* ]] || a=${to[i]}${a#"${from[i]}"}; done
|
|
printf '%s' "$a"
|
|
}
|
|
args=()
|
|
for a in "$@"; do args+=("$(map "$a")"); done
|
|
cd "$(map "$dir")"
|
|
exec "${args[@]}"
|
|
-- bin/goreleaser --
|
|
#!/bin/bash
|
|
# Logs its call, and writes a dist/ like GoReleaser's, the same each time:
|
|
# each system's and processor's build, a script printing $DEVVM_VERSION, an
|
|
# archive for each holding it and its repository's tags, with root's files
|
|
# and fixed times, the source tarball and SHA256SUMS. With GR_RECORD=user,
|
|
# each archive holds the user the container ran as too; with
|
|
# GR_RECORD=disk, its files are the user's on disk, not root's.
|
|
set -eu
|
|
echo "$* GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG:-}" >> "$WORK/log"
|
|
# GNU tar's options, or bsdtar's, which also leaves out macOS's metadata.
|
|
if tar --version 2>/dev/null | grep -q GNU; then own=() root=(--owner=root:0 --group=root:0)
|
|
else own=(--no-xattrs --no-acls --no-fflags --no-mac-metadata) root=(--uid 0 --gid 0 --uname root --gname root); fi
|
|
[[ ${GR_RECORD:-} == disk ]] || own+=("${root[@]}")
|
|
rm -rf dist
|
|
for os in darwin linux; do
|
|
for a in arm64 amd64; do
|
|
d=dist/x/devvm-$DEVVM_VERSION-$os-$a
|
|
mkdir -p "dist/devvm_${os}_$a" "$d"
|
|
printf '#!/bin/sh\necho %s\n' "$DEVVM_VERSION" > "dist/devvm_${os}_$a/devvm"
|
|
chmod 755 "dist/devvm_${os}_$a/devvm"
|
|
cp "dist/devvm_${os}_$a/devvm" "$d/devvm"
|
|
git tag -l > "$d/tags"
|
|
[[ ${GR_RECORD:-} != user ]] || echo "$RT_USER" > "$d/user"
|
|
touch -t 202601010000 "$d"/* "$d"
|
|
tar -cf - ${own[@]+"${own[@]}"} -C dist/x "devvm-$DEVVM_VERSION-$os-$a" | gzip -n > "dist/devvm-$DEVVM_VERSION-$os-$a.tar.gz"
|
|
done
|
|
done
|
|
rm -rf dist/x
|
|
git archive --prefix="devvm-$DEVVM_VERSION/" HEAD | gzip -n > "dist/devvm-$DEVVM_VERSION.tar.gz"
|
|
(cd dist && { sha256sum devvm-*.tar.gz 2>/dev/null || shasum -a 256 devvm-*.tar.gz; } > SHA256SUMS)
|