finish: sign the aux set's catalogue

Tools signs the aux repository's catalogue only in a packages step run
with the key; its sign-packages re-signs the packages set's catalogue but
not the aux set's. Build runs without the key, so the aux catalogue stayed
unsigned and gwmirror verify rejected it. finish now unpacks the aux set,
signs its catalogue with pkg repo and repacks it before tools signs the set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jeremy Karst 2026-11-22 17:34:56 -05:00
parent 1d27c40b84
commit 90dd8bb200
3 changed files with 94 additions and 1 deletions

View file

@ -303,7 +303,11 @@ release/vm.sh pull-out 14.3 26.1 # -> /scratch/mono-opnsense/out/26.1
**`finish`:**
1. Checks the key against `keys/fingerprints/trusted`.
2. Signs base, kernel, packages and aux. Signing the packages set regenerates
the catalogue, so it includes `mono-gateway`.
the catalogue, so it includes `mono-gateway`. Tools does not do the same
for the aux set: it signs the aux catalogue only in a packages step run
with the key. So `finish` first unpacks the aux set, signs its catalogue
with `pkg repo` and repacks it. `gwmirror verify` found the aux catalogue
unsigned on 2026-11-22.
3. Builds the 5 GB ZFS eMMC image (`mk-image.sh`). On a cross-building
host the xtools set is moved aside first, because tools would otherwise
overlay amd64 toolchain files onto the image.

View file

@ -531,6 +531,26 @@ scan_image()
rm -f "${_bad}"
}
# sign_aux_repo SET: sign the catalogue of the aux repository in SET (KEYDIR has the
# key). Tools signs it only in a packages step run with the key; its sign-packages
# signs the packages set's catalogue again, but not the aux set's, which build
# leaves unsigned. The set's own signature comes after, from tools' sign-aux.
sign_aux_repo()
{
[ -f "${1}" ] || return 0
step "signing the catalogue of $(basename "${1}")"
_dir=$(mktemp -d /tmp/gwaux.XXXXXX)
if ! tar -C "${_dir}" -xpf "${1}" ||
! pkg repo "${_dir}/" signing_command: /usr/tools/scripts/pkg_sign.sh \
"${KEYDIR}/repo.pub" "${KEYDIR}/repo.key"; then
rm -rf "${_dir}"
die "cannot sign the catalogue of ${1}"
fi
tar -C "${_dir}" -cf "${1}.new" .
mv "${1}.new" "${1}"
rm -rf "${_dir}"
}
finish()
{
args "${1:-}" "${2:-}"
@ -545,6 +565,7 @@ finish()
ls "${SETS}/${_set}-${VERSION}-aarch64"*.t* > /dev/null || die "no ${_set} set; run build first"
done
sign_aux_repo "${SETS}/aux-${VERSION}-aarch64.tar"
step "signing sets"
# shellcheck disable=SC2086
${TOOLS} ${SIGNED} sign-base,kernel,packages,aux

View file

@ -1300,5 +1300,73 @@ class ExitTrapTest(unittest.TestCase):
self.assertIn("build.sh build SERIES VERSION", r.stderr)
class SignAuxRepoTest(unittest.TestCase):
"""build.sh's sign_aux_repo: the aux set's catalogue signed with KEYDIR's key."""
def setUp(self):
self.tmp = tempfile.mkdtemp(prefix="gw-aux-")
self.addCleanup(shutil.rmtree, self.tmp)
self.fx = Fixture(self.tmp)
self.work = os.path.join(self.tmp, "work")
os.makedirs(self.work)
src = os.path.join(self.tmp, "src")
os.makedirs(os.path.join(src, "All"))
for name, data in (("All/rust-1.96.0.pkg", "rust"), ("packagesite.pkg", "unsigned"), (".abi_hint", "abi")):
with open(os.path.join(src, name), "w") as f:
f.write(data)
self.set = os.path.join(self.tmp, "aux-26.1.11-aarch64.tar")
subprocess.run(["tar", "-C", src, "-cf", self.set, "."], check=True)
# pkg repo DIR signing_command: CMD...: a catalogue naming its signing command
self.fx.make_fake("pkg", """[ "$1" = repo ] || exit 1
[ -z "${FAKE_PKG_FAIL:-}" ] || exit 1
dir=$2; shift 2
echo "signed by: $*" > "$dir/packagesite.pkg\"""")
self.func = (build_function("die") +
build_function("sign_aux_repo", [("/tmp/gwaux", f"{self.work}/gwaux")]))
def sign(self, set_=None, **env):
e = {"PATH": f"{self.fx.bin}:/usr/bin:/bin", "FAKE_LOG": self.fx.log, "KEYDIR": "/root/gwkey"}
e.update(env)
r = subprocess.run(["sh", "-c", 'set -eu; step() { echo ">>> $*"; }\n' + self.func + '\nsign_aux_repo "$1"',
"sh", set_ or self.set], env=e, capture_output=True, text=True)
self.assertEqual(os.listdir(self.work), [])
return r
def member(self, name):
return subprocess.run(["tar", "-xOf", self.set, name], capture_output=True, text=True, check=True).stdout
def test_catalogue_signed(self):
r = self.sign()
self.assertEqual(r.returncode, 0, r.stderr)
self.assertEqual(self.member("./packagesite.pkg"),
"signed by: signing_command: /usr/tools/scripts/pkg_sign.sh "
"/root/gwkey/repo.pub /root/gwkey/repo.key\n")
self.assertEqual(self.member("./All/rust-1.96.0.pkg"), "rust")
self.assertEqual(self.member("./.abi_hint"), "abi")
self.assertFalse(os.path.exists(self.set + ".new"))
def test_without_aux_set(self):
r = self.sign(set_=os.path.join(self.tmp, "none.tar"))
self.assertEqual((r.returncode, r.stdout), (0, ""))
self.assertEqual(self.fx.calls(), [])
def test_signing_failure_keeps_the_set(self):
with open(self.set, "rb") as f:
before = f.read()
r = self.sign(FAKE_PKG_FAIL="1")
self.assertNotEqual(r.returncode, 0)
self.assertIn("build.sh: cannot sign the catalogue of", r.stderr)
with open(self.set, "rb") as f:
self.assertEqual(f.read(), before)
def test_broken_set(self):
with open(self.set, "wb") as f:
f.write(b"not a tar")
r = self.sign()
self.assertNotEqual(r.returncode, 0)
self.assertIn("cannot sign the catalogue", r.stderr)
self.assertEqual(self.fx.calls(), [])
if __name__ == "__main__":
unittest.main()