mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
A first build of base gave back each package it downloaded with apt's
entry for it, and the host took the build VM's word that each entry was
apt's: anything with root in that VM before apt.sh end could record a
package with a made-up entry, which every later build of the key
replayed. Now the build also hands back the InRelease files and package
lists apt used, and the host checks them itself before it keeps
anything:
- each InRelease is clearsigned by Ubuntu's archive key, pinned in
assets/layers/ubuntu-archive.gpg ("Ubuntu Archive Automatic Signing
Key (2018)", F6ECB3762474EDA9D21B7022871920D1991BC93C, from
keyserver.ubuntu.com by fingerprint, checked against the Ubuntu
security team's list), and one of 26.04's suites;
- each package list has the SHA-256 and size a verified InRelease gives
one of its Packages lists;
- each recorded .deb's SHA-256 is in one of those lists, as the package,
version, architecture and size apt's entry says, and the set keeps
the archive's own entry.
- internal/ubuntu/pgp.go verifies clearsigned messages (RFC 4880's
cleartext signatures: text signatures, dash-escaping, trailing
whitespace, nothing before or after); archive.go's VerifyRelease and
Release.Lists read a verified InRelease (ArchiveKeyring).
- assets/layers/apt.sh: record copies apt's *_InRelease and *_Packages
lists to out/<n>.InRelease and out/<n>.Packages; base's build keeps
lists uncompressed (Acquire::GzipIndexes "false").
- internal/build: take accepts the lists (an InRelease at most 4 MiB and
all of them 32 MiB, a list 512 MiB with lines of 1 MiB and entries of
4 MiB, all lists 2 GiB, no name twice), signedEntries and
archiveEntry check them; cache carries devvm's own files for the key.
- Tests: Ubuntu's real resolute-updates InRelease verified, and refused
when changed, framed differently or signed by another key; clearsigned
parsing (dashes, CR LF, trailing whitespace, a binary signature
refused); InRelease fields; a recording refused for a forged
InRelease, a list no InRelease gives, a .deb no signed list has,
another package's entry, missing lists, a list or an InRelease twice,
a line over 1 MiB; a good set kept
with the archive's entry (gpg-made fixtures in
internal/build/testdata/archive); apt.sh's record giving back the
lists.
- Docs: images.md's Base's packages, design.md's trust note (the
recording VM's made-up packages closed), settings.md's mirror
section, maintaining.md's archive key.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
130 lines
4.6 KiB
Plaintext
130 lines
4.6 KiB
Plaintext
# Functions in base.sh and apt.sh, run on their own with stand-ins for what
|
|
# they call in the VM (fn.sh, below).
|
|
|
|
# mirrored: each archive of a sources file gets a mirror list of the mirror
|
|
# set, then that archive, the rest of the file as it was.
|
|
mkdir pk/in
|
|
cp mirrors pk/in/mirrors
|
|
exec bash -c 'source fn.sh; layer_fn apt mirrored; dir=$PWD/pk; mirrored ubuntu.sources out.sources'
|
|
exec sh -c 'sed "s|$WORK|WORK|g" out.sources'
|
|
cmp stdout mirrored.sources
|
|
cmp pk/mirrors-1 want-mirrors-1
|
|
cmp pk/mirrors-2 want-mirrors-2
|
|
cmp ubuntu.sources ubuntu.sources.orig
|
|
|
|
# record: each package downloaded goes to out/<sha256>.deb, with apt's entry
|
|
# for that version with that SHA-256 (not another's) in out/Packages, and
|
|
# each InRelease and package list apt has to out/<n>.InRelease or
|
|
# out/<n>.Packages, its other lists left out.
|
|
mkdir archives lists
|
|
cp git.deb archives/git_1_arm64.deb
|
|
cp inrelease lists/mirror_dists_resolute_InRelease
|
|
cp packages lists/mirror_dists_resolute_main_binary-arm64_Packages
|
|
cp packages lists/mirror_dists_resolute_main_i18n_Translation-en
|
|
exec bash -c 'set -euo pipefail; source fn.sh; layer_fn apt record; dpkg_deb_stub; dir=$PWD/pk archives=$PWD/archives lists=$PWD/lists; record'
|
|
exists pk/out/aaaa.deb
|
|
! exists archives/git_1_arm64.deb
|
|
cmp pk/out/Packages want-packages
|
|
cmp pk/out/1.InRelease inrelease
|
|
cmp pk/out/2.Packages packages
|
|
exec sh -c 'LC_ALL=C ls pk/out'
|
|
cmp stdout want-out
|
|
|
|
# One apt's lists don't have with that SHA-256 fails it.
|
|
cp git.deb archives/git_1_arm64.deb
|
|
env WRONG=1
|
|
! exec bash -c 'set -euo pipefail; source fn.sh; layer_fn apt record; dpkg_deb_stub; dir=$PWD/pk archives=$PWD/archives lists=$PWD/lists; record'
|
|
stderr 'apt''s lists have no git 1 \(arm64\)'
|
|
env WRONG=
|
|
|
|
# installed: only the packages that are installed, and no failure for
|
|
# unknown ones.
|
|
exec bash -c 'set -eo pipefail; source fn.sh; layer_fn base installed; dpkg_stub; installed snapd fwupd rsyslog nope'
|
|
cmp stdout installed
|
|
|
|
-- fn.sh --
|
|
# layer_fn SCRIPT NAME: define NAME from assets/layers/SCRIPT.sh (the scripts run
|
|
# top to bottom when sourced).
|
|
layer_fn() { eval "$(awk -v f="$2() " 'index($0, f) == 1 { on = 1 } on { print } on && /^}/ { exit }' "$DEVVM_REPO/assets/layers/$1.sh")"; }
|
|
# dpkg-deb reads git.deb's fields; sha256sum gives aaaa; apt-cache has two
|
|
# entries for the version, one with that SHA-256 (unless $WRONG).
|
|
dpkg_deb_stub() {
|
|
dpkg-deb() { case $3 in Package) echo git ;; Version) echo 1 ;; Architecture) echo arm64 ;; esac; }
|
|
sha256sum() { echo "aaaa $1"; }
|
|
apt-cache() {
|
|
printf 'Package: git\nVersion: 1\nSHA256: bbbb\n\n'
|
|
if [[ -z ${WRONG:-} ]]; then printf 'Package: git\nVersion: 1\nSHA256: aaaa\nDescription: git\n more\n\n'; fi
|
|
}
|
|
}
|
|
# dpkg-query lists what it knows and fails for the rest, like the real one.
|
|
dpkg_stub() {
|
|
dpkg-query() {
|
|
printf 'installed snapd\nnot-installed fwupd\nconfig-files rsyslog\n'
|
|
echo "dpkg-query: no packages found matching nope" >&2; return 1
|
|
}
|
|
}
|
|
-- mirrors --
|
|
https://mirror.example/ubuntu-ports
|
|
-- ubuntu.sources --
|
|
Types: deb
|
|
URIs: http://ports.ubuntu.com/ubuntu-ports/
|
|
Suites: resolute resolute-updates resolute-backports
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
|
|
Types: deb
|
|
URIs: http://security.ubuntu.com/ubuntu/
|
|
Suites: resolute-security
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
-- ubuntu.sources.orig --
|
|
Types: deb
|
|
URIs: http://ports.ubuntu.com/ubuntu-ports/
|
|
Suites: resolute resolute-updates resolute-backports
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
|
|
Types: deb
|
|
URIs: http://security.ubuntu.com/ubuntu/
|
|
Suites: resolute-security
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
-- mirrored.sources --
|
|
Types: deb
|
|
URIs: mirror+file:WORK/pk/mirrors-1
|
|
Suites: resolute resolute-updates resolute-backports
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
|
|
Types: deb
|
|
URIs: mirror+file:WORK/pk/mirrors-2
|
|
Suites: resolute-security
|
|
Components: main restricted universe multiverse
|
|
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
|
-- want-mirrors-1 --
|
|
https://mirror.example/ubuntu-ports
|
|
http://ports.ubuntu.com/ubuntu-ports/
|
|
-- want-mirrors-2 --
|
|
https://mirror.example/ubuntu-ports
|
|
http://security.ubuntu.com/ubuntu/
|
|
-- git.deb --
|
|
not really a package
|
|
-- want-packages --
|
|
Package: git
|
|
Version: 1
|
|
SHA256: aaaa
|
|
Description: git
|
|
more
|
|
|
|
-- inrelease --
|
|
an InRelease
|
|
-- packages --
|
|
a package list
|
|
-- want-out --
|
|
1.InRelease
|
|
2.Packages
|
|
Packages
|
|
aaaa.deb
|
|
-- installed --
|
|
snapd
|