Files
w3cjandClaude Opus 5.5 e93f29333a feat(ubuntu): pin the newest signed cloud image at base's first build
devvm's files keep only Ubuntu's release (26.04) and its cloud image key.
The first build of base on a machine pins the newest dated release whose
SHA256SUMS carry a valid signature from that key and list an image for the
host (state.UbuntuPin, images/ubuntu.json), and every later build uses the
pin without looking anything up. devvm rebuild base pins the newest again.
The pin is in base's recipe, so base's key hashes it.

The signature is checked in Go (internal/ubuntu/pgp.go: OpenPGP v4 RSA
signatures with SHA-256/384/512, the standard library's crypto), so no
gpgv is needed and a host without one is no longer unchecked.

- backend.Images gains PinOrigin (backend.Pin: PinFirst, PinNewest,
  PinOlder); internal/build pins before it keys a build, and says what it
  pinned (origin_pinned).
- Lima: Origin and createFromUbuntu read the pin; PinOrigin finds the
  newest with ubuntu.Finder (Newest, Release) under images/locks/ubuntu; a
  --from conversion pins only when nothing is.
- Messages: ubuntu_unreachable and no_ubuntu_release; ubuntu_unsigned and
  ubuntu_checksum_unpinned are gone.
- e2e pins its own release (DEVVM_UBUNTU_RELEASE, a test override;
  scripts/bump.sh e2e-ubuntu moves it); bump.sh's apt moves the package
  snapshot alone. The gpgv stub is gone.
- Tests: the verifier against Ubuntu's real signature and a test key
  (damaged keys and signatures, packet and subpacket lengths, armor),
  Newest/Release, PinOrigin, the pin record, and the key covering the pin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 11:27:25 -07:00

50 lines
1.6 KiB
Go

package state
import (
"errors"
"io/fs"
"os"
"strings"
"testing"
"time"
)
// The pinned cloud image reads back as written; none pinned is
// fs.ErrNotExist; a pin whose fields aren't a pin's is neither written nor
// read, as they go into base's key and Lima's config.
func TestUbuntuPin(t *testing.T) {
d := testDirs(t)
if _, err := ReadUbuntuPin(d); !errors.Is(err, fs.ErrNotExist) {
t.Fatalf("none pinned: %v", err)
}
want := UbuntuPin{
Release: "release-20261016", File: "ubuntu-26.04-server-cloudimg-arm64.img",
Digest: "sha256:" + strings.Repeat("a", 64), Pinned: time.Date(2026, 11, 4, 10, 0, 0, 0, time.UTC),
}
if err := WriteUbuntuPin(d, want); err != nil {
t.Fatal(err)
}
if got, err := ReadUbuntuPin(d); err != nil || got != want {
t.Errorf("got %+v, %v; want %+v", got, err, want)
}
for name, change := range map[string]func(*UbuntuPin){
"a release that isn't dated": func(p *UbuntuPin) { p.Release = "current" },
"a path for a file": func(p *UbuntuPin) { p.File = "../ubuntu-26.04-server-cloudimg-arm64.img" },
"a digest with more": func(p *UbuntuPin) { p.Digest += `"}]` },
} {
p := want
change(&p)
var corrupt *CorruptError
if err := WriteUbuntuPin(d, p); !errors.As(err, &corrupt) {
t.Errorf("%s: written, %v", name, err)
}
data := `{"release": "` + p.Release + `", "file": "` + p.File + `", "digest": "sha256:x"}`
if err := os.WriteFile(d.UbuntuPin(), []byte(data), 0o600); err != nil {
t.Fatal(err)
}
if _, err := ReadUbuntuPin(d); !errors.As(err, &corrupt) {
t.Errorf("%s: read, %v", name, err)
}
}
}