5 Commits
Author SHA1 Message Date
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
w3cjandClaude Opus 5.5 00e5ea59f4 feat(cosign): the run, which makes and publishes each release CI hands over
devvm-cosign's run (Cosigner.Run), its command (cmd/devvm-cosign, Main)
and the maintainer's commands, devvm-cosign retry, ack and failed.

CI's token can only read the repo, so CI hands each build over as a
workflow artifact, and only the co-signer, and the maintainer by hand,
can make or publish a release. For each release CI handed over that it
hasn't published, oldest first, from the newest successful run of the
pinned release workflow for each tag, of this repo's own:

- its version is newer than the newest it signed, or one it signed, with
  the same SHA256SUMS; an older one is an alert, as a replay, until the
  maintainer acks it, unless it was published before the state began;
- CI's artifact is staged (stage/, which no build can reach) and
  checked: SHA256SUMS, CI's signature with CI's key and devvm-release
  <version>, and exactly the files it lists, each with its SHA-256; its
  files are deleted before the build and downloaded again after a match,
  so none of CI's bytes is on disk while a container could be live;
- a run builds once, so the podman service, which lives for the run,
  lives for one build, and anything that escaped a container is gone
  before the next build's host git and release.sh run; the next release
  or base waits for the next run;
- the build's finished files go in a folder of the state's src/, which
  release.sh copies to and the co-signer reads, where no container can
  swap a file or the folder;
- the tag's commit has to be the commit CI's run built, and the
  co-signer's own build has to match every file and SHA256SUMS; it
  renders the tap's formulas itself from the tag's template and the
  signed SHA256SUMS (formula.go, as release.sh's formula function does),
  and the build's own formulas have to be the same bytes, so neither
  builder's container decides what Homebrew installs. The formulas and
  the notes, the tag's CHANGELOG.md entry, are kept in kept/<v>/ with
  their SHA-256s in the state, and checked again before the tap;
- it signs, makes the draft itself, titled devvm <version> with the
  tag's notes, and uploads SHA256SUMS, both signatures and CI's files,
  each hashed as it's sent, keeping an asset only when its size and
  GitHub's digest are right and deleting any other;
- while the bridge lasts it waits for the old key's signature on the
  draft, failing each run so the maintainer hears of it, and downloading
  nothing again while it waits;
- it publishes only when the draft is exactly what it made, its tag,
  title and notes (but for line endings and the space at either end),
  and its assets by ID, size and digest, and the tag still names the tag
  object its rebuild checked; then checks the published release again,
  and finishes the tap.

Alerts and refusals:

- init records the highest release ID GitHub showed and the drafts there
  were then; IDs only go up, so any release published since that isn't a
  draft the co-signer made is an alert, whatever its tag or version, by
  <tag>#<ID>, so another release of an acked tag is alerted on again;
  each run also reads GitHub's latest release, wherever the list puts it.
- A published release that differs from what it checked, its own draft
  published without it seeing the answer that then doesn't check out,
  and a tap formula newer than any release it signed, by
  tap:<formula>@<version>, are alerts; the tap is updated only for a
  release it published and checked after.
- A rebuild that doesn't match is a refusal, which isn't downloaded or
  rebuilt again, even for CI's run again; devvm-cosign retry <tag> lets
  the next run rebuild it once more. Nothing retries on its own.
- Every run fails (exit 1) while an alert or refusal waits, until
  devvm-cosign ack or retry. A run records in last-failure.txt that it
  started, then what failed, or removes it when it succeeds; devvm-cosign failed, which the units' OnFailure=
  runs for any failure, a killed or timed-out run's or a config that
  won't load included, runs notify, the maintainer's command, with it on
  its stdin, a fixed environment and a minute of its own, whatever ended
  the run's context.

Bases go the same way, from the newest successful run of the base
workflow on main, made at the index's commit and never GitHub's latest.

Main makes the process non-dumpable (prctl PR_SET_DUMPABLE 0) before
anything else, so no process of its user can read its memory, where the
keys and token are, and reads the keys from systemd's credentials when
CREDENTIALS_DIRECTORY is set. A run empties the build folder's work/
and the state's stage/ and src/ in place, never making them again.

Tests, each fix reverted once to see it fail: TestPublishedBySomeoneElse
(a release published by someone else, whatever its tag or version, the
same tag again after an ack, a draft from before init published since,
and GitHub's latest past where the list stops; one from before the state
left alone), TestOneBuildPerRun (the build's files in the state, none of
CI's on disk during the build, and the next release left for the next
run), TestFormulas (a build's formula of
its own; a kept formula changed on disk), TestRenderFormula,
TestPrereleasePublished (a tap formula newer than any release signed),
TestDraftChangedBeforePublish (a swapped file, a retag, other notes),
TestTagMovedBeforePublish, TestAlertAfterPublish and
TestLostPublishChecked, TestMismatchSignsNothing (a failure every run,
and retry), TestReplayedOlderVersion (an alert, then acked),
TestNotify, TestLegacyBridge (a failure every run, with no download),
TestRunPagesReleases, TestInitPaged (init past ten pages of bases, which
fails with a page check that stops at its first unfinished entry),
TestRunsChecked, TestArtifactChecked, TestUploadChangedOnDisk,
TestBaseIndexChecked (a re-signed base on a 61-day snapshot),
TestBasePublishChecked, TestBasePublishedElsewhere (an expired base still
counts in checkBehind), TestWorkEmptiedInPlace, TestCommandLine (retry
and ack read no key file), and on Linux TestUndumpable.

A build that fails, rather than differs, is built again at the next
run, but the third failure in a row refuses it, with a report holding
the last failure (buildFailed), so a build that keeps failing no longer
takes every run's one build and holds up each newer release and base;
retry builds it again, and a build stopped with its run isn't counted.
Refusing rather than rotating past it keeps releases oldest first, as
versions only go up, and keeps the failure in front of the maintainer
through held and notify. buildRelease and buildBase are the build and
its comparison, apart from what's recorded. And GitHub's latest release
has to be the one init saw or one the co-signer published, not one of
its own older than another it published: anything else is an alert,
latest:<tag>#<ID> (staleLatest), as the install script's default
downloads it; so is the one init saw, once it's older than one the
co-signer published. The co-signer makes a release GitHub's latest only
when it's newer than every release it published, so publishing an older
release after a newer one, as when the old key signs the newer draft
first, never moves the latest back itself. And a release's run counts
only when a tag's push started it (PushEvent, which the structure
test's nameFree lets name "push"). Tests, each failing before its code:
TestFailingBuildRefused, TestBaseRefused's base that keeps failing,
TestLatestChecked, TestOlderReleaseNotLatest, TestRunsChecked's run by
hand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 21:36:37 -07:00
w3cjandClaude Opus 5.5 1bd598c791 feat(cosign): ReleaseBuild, the co-signer's own build of a tag
ReleaseBuild rebuilds a release with the co-signer's own devvm: a new
clone of its checkout at its pinned commit (checked clean), the tag and
main fetched into it, the tag's SSH signature checked against the pinned
signers (VerifyTag), the tag naming itself and its commit on main, then
the clone's release.sh --tag with those signers as git's
allowedSignersFile, so release.sh checks the tag again. Nothing of the
tag's runs on the host.

- The clone, its git config and allowed signers and release.sh's log go
  in Src, the state folder's src/, which no build's container can reach,
  as release.sh and git run from it on the host; only release.sh's
  TMPDIR, where its containers work, goes in Work, the build folder. A
  container that could write the clone could otherwise edit release.sh
  as bash reads it, or set gpg.ssh.program or a filter in its .git/config
  for git to run on the host. release.sh's download cache, which only it
  reads, on the host, goes in the state folder too, so nothing that
  escaped a container can plant a link for its next download.
- Build returns Built: the checked tag, its tag object's ID, and the tag
  commit's Homebrew
  formula template (packaging/homebrew/devvm.rb) and CHANGELOG.md, read
  with git before release.sh runs, so no build's container can change
  them. The co-signer renders the tap's formulas and the release's notes
  from them and the signed SHA256SUMS.
- The checkout is root's, so git reads it as the co-signer's user only
  with it named safe on its own command line: its worktree for git
  status, and its .git for a clone, whose upload-pack checks that path.
  A full run on Fedora under the units found the clone refused with the
  worktree alone; TestCheckoutNamedSafe holds both.
- git runs with no system or global config, no hooks or fsmonitor, no
  replace objects, files and HTTPS alone, an environment of its own and
  its output capped.
- The structure test's commandsFree is now keyed by the command, then the
  file, so build.go may run git and no other guarded command; its
  execSites and statusFree entries, and the owners table, say why.

Tests: TestReleaseBuild (the template and changelog read, then a stub
release.sh that deletes the clone's .git, as a build could, and says
where it ran: its script in Src and its TMPDIR in Work, which fails with
the clone in Work, reverted once to see it; the tag object), the
existing refusals (an unpinned signer, off main, a dirty or moved
checkout, a lightweight tag, a tag naming another, release.sh failing),
TestCheckoutNamedSafe, and TestRulesFail's "another command in a file
commandsFree lists for git", which fails with commandsFree keyed by file
alone (reverted once to see it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 21:36:37 -07:00
w3cjandClaude Opus 5.5 da68e5d67e feat(cosign): GitHub, CI's artifacts, the app's token, the config, the state and the lock
What devvm-cosign reads and writes, below its run:

- github.go, actions.go: every GitHub call goes through Client: releases
  listed, read one, by its tag, a draft made, an upload streamed from a
  file with the SHA-256 of the bytes it sent, a delete, a publish, the
  tap's contents; and the Actions API's runs of a workflow file, a run's
  artifacts by name and an artifact's zip, which redirects to storage
  that never gets the token. CI's token can only read the repo, so CI
  hands its build over this way, and only the co-signer makes and
  publishes releases.
- Lists are read a page at a time until a page holds only entries the
  caller is done with, newest first as GitHub lists them, so years of
  releases and bases never stop a run; ten pages it isn't done with are
  an error, never a list cut short. Every entry of a page is asked about
  (every), never stopping at the first that isn't done, so a caller that
  counts what it's asked, as init does, sees the whole page.
- TagRef: what a tag names now, so a release is published only while
  its tag names the tag object the rebuild checked; Latest: GitHub's
  latest release, which /releases/latest/download/ serves.
- artifact.go: an artifact downloaded into the co-signer's stage folder,
  capped, checked against GitHub's digest, and unzipped with nothing but
  a flat list of regular files, each named as a manifest names a file,
  stored or deflated, written new (O_EXCL), each no larger than its
  header says, within the artifact's bounds, and hashed as written.
- app.go: the GitHub App's installation token (RS256 JWT), now asking
  for actions: read beside contents: write, on the two repos alone.
- config.go: release_workflow and [base]'s workflow and
  max_snapshot_days; notify, the maintainer's command for a failed run;
  build_dir, the folder the builds' containers write, apart from
  state_dir, which they can't reach, neither in the other; ReadConfig,
  without the keys, for retry and ack; and the key
  files read from systemd's credentials folder ($CREDENTIALS_DIRECTORY)
  by their own names, where systemd's system manager makes them root's,
  mode 0440, with an ACL for the service's user, so there only others'
  bits are refused. A kind with no keys at all, as before the release
  keys are made, is refused by name, pointing at github-setup.md's
  step 1, so the co-signer doesn't start without them.
- state.go: a ledger for each kind: what it signed, the drafts it made,
  what it published, each refusal with how often it was retried, each
  alert with how often it was acked, and the CI runs it signed; releases
  also record the SHA-256 of each file kept for the tap and each tag
  object checked. The state's watermark, the highest release ID GitHub
  showed at init, and the drafts there were then, and the alerts on what
  isn't one of its own: a release someone else published since, by
  <tag>#<ID>, and a tap formula it didn't write. A save is refused when
  it drops or changes an entry or counts one back, and
  writeWhole now syncs the folder after the rename, so a crash can't
  lose the record of a version made before its signature is uploaded.
- lock_unix.go: one run at a time, unchanged.
- forbidigo's exclusions now name their files: the web for github.go and
  app.go, Flock for lock_unix.go, so a second client or lock elsewhere in
  the package still fails the lint.

Tests: the fake GitHub serves workflow runs and artifacts and makes
drafts; TestUnzip (a folder, a path, a parent, a dot file, a link, a file
twice, too many, a size that lies, not a zip, a file already there),
TestFetchArtifact, TestClientReleasesAndRuns, TestReleasesPaged (1,100
settled releases read in two pages), TestLedger, TestStateNeverBackwards
(drafts, publishes, kept files, alerts and refusals counted back),
TestConfigCredentials, TestConfigRefused (the build folder in the state
folder or the reverse). Reverted once each to see the test fail: the
paging's stop (TestReleasesPaged), the credentials folder
(TestConfigCredentials), the lint's scope (an http.Client in another
file fails forbidigo). The folder's fsync was checked with strace on
Fedora: openat of the folder and fsync right after the rename.

The state also counts each manifest's failed builds in a row
(Refusal.Failed, Ledger.failed): the third, maxBuildFailures, refuses it
as a mismatch does, with its cause (Why), and the count alone may go
back, as a lower one only builds more. And it records GitHub's latest
release at init (InitLatest), which a save may never change.
TestStateNeverBackwards covers both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 21:36:37 -07:00
w3cjandClaude Opus 5.5 5ad326e13c feat(cosign): the co-signer's parsers of outside input, and their fuzz targets
The first of devvm-cosign's code, the parts that read what CI and GitHub
send, so they can be reviewed apart:

- sshsig.go: git's SSH tag signatures (OpenSSH's SSHSIG over the tag
  object's payload, namespace git, Ed25519 alone), checked against the
  tag signers the co-signer's own config pins (VerifyTag, ParseSigner,
  AllowedSigners); the payload split at the last armor header, as git's
  parse_signed_buffer does, and a tag naming itself and a commit.
- manifest.go: SHA256SUMS (ParseSums), base-index.json (ParseIndex),
  each with its files and the trusted comment's subject, and release
  versions as release.sh orders them.
  - A base's index is refused when its Ubuntu snapshot is more than
    maxAge old (the config's max_snapshot_days, 60 by default) or ahead
    of now, whether or not it's rebuilt: the co-signer re-signs an
    unchanged base with a new serial and expiry, so the expiry alone
    can't keep users off an old base, and a stolen CI base key could
    otherwise keep them on one snapshot for as long as it signs.
  - The expiry is the last day the index is taken, in UTC, as the
    field's comment says: refused from the start of the next day.
  - Neither manifest may list a manifest's or a signature's name
    (SHA256SUMS, base-index.json, *.minisig), so a listed file can never
    stand in for the co-signer's signature.
  - indexSubject reads an index's subject whatever its times, so a base
    the co-signer signed counts in checkBehind however long ago it
    expired.
- Fuzz targets: FuzzVerifyTag, FuzzParseSums, FuzzParseIndex.
- Guards: depguard's cosign rule (the standard library, BurntSushi/toml
  and internal/minisign alone); the layers "only cmd/devvm-cosign runs
  the co-signer" and "the co-signer imports only internal/minisign";
  signatureFree's internal/cosign/sshsig.go, another project's format,
  and the owners table regenerated.

Tests: TestParseIndex (a 60-day snapshot taken, 61 days, ahead, bad or
none refused; expiring today taken, yesterday refused), TestIndexSubject,
and the existing parsers' tables. Each fix was reverted once to see its
test fail: the snapshot bound (TestParseIndex, TestBaseIndexChecked) and
the expiry's day (TestParseIndex).

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