imsd: sign from a readable copy of the abuild key
Some checks failed
image / image (push) Failing after 2h3m26s

Run 49 died in section 3b: pmbootstrap's abuild-keygen runs inside the
chroot as its own user (uid 12345), so the key in config_abuild/ is 0600 to
that uid and the build user cannot read it; openssl dgst -sign exited 1 and
apk-resign.py swallowed its stderr. Take a private copy via sudo for the
duration of the re-sign, and make the script name an unreadable key and let
openssl's stderr through instead of hiding it.
This commit is contained in:
Jorijn van der Graaf 2026-09-02 17:21:30 +02:00
commit 877fe92a4b
2 changed files with 19 additions and 5 deletions

View file

@ -11,6 +11,7 @@ This is what abuild-sign does to the control segment when abuild packages.
""" """
import gzip import gzip
import io import io
import os
import subprocess import subprocess
import sys import sys
import tarfile import tarfile
@ -53,10 +54,17 @@ def main(path, privkey, pubname):
kind = name.split(".")[2] if name.startswith(".SIGN.") else "" kind = name.split(".")[2] if name.startswith(".SIGN.") else ""
if kind not in DIGEST: if kind not in DIGEST:
sys.exit(f"{path}: unexpected signature entry {name!r}") sys.exit(f"{path}: unexpected signature entry {name!r}")
if not os.access(privkey, os.R_OK):
sys.exit(f"{privkey}: not readable by uid {os.getuid()} (pmbootstrap's "
"abuild-keygen runs as the chroot user, uid 12345, and leaves "
"the key 0600 to it - sign from a readable copy)")
try:
sig = subprocess.run( sig = subprocess.run(
["openssl", "dgst", f"-{DIGEST[kind]}", "-sign", privkey], ["openssl", "dgst", f"-{DIGEST[kind]}", "-sign", privkey],
input=control, capture_output=True, check=True, input=control, stdout=subprocess.PIPE, check=True,
).stdout ).stdout
except subprocess.CalledProcessError as e:
sys.exit(f"openssl dgst -sign exited {e.returncode} signing {path}")
buf = io.BytesIO() buf = io.BytesIO()
with tarfile.open(fileobj=buf, mode="w", format=tarfile.USTAR_FORMAT) as tar: with tarfile.open(fileobj=buf, mode="w", format=tarfile.USTAR_FORMAT) as tar:
info = tarfile.TarInfo(f".SIGN.{kind}.{pubname}") info = tarfile.TarInfo(f".SIGN.{kind}.{pubname}")

View file

@ -268,9 +268,15 @@ if [ ! -f "$ABUILD_KEY" ]; then
echo "expected exactly one abuild key in $WORKDIR/config_abuild" >&2 echo "expected exactly one abuild key in $WORKDIR/config_abuild" >&2
exit 1 exit 1
fi fi
# abuild-keygen ran inside the chroot as pmbootstrap's user (uid 12345), so
# the key is 0600 to that uid and unreadable here (run 49 died on exactly
# this); sign from a private copy taken via sudo, then drop it.
KEYCOPY="$IMSD_DL/abuild-key.rsa"
sudo install -m 0600 -o "$(id -un)" "$ABUILD_KEY" "$KEYCOPY"
for _f in "$IMSD_DL"/*.apk; do for _f in "$IMSD_DL"/*.apk; do
python3 ./apk-resign.py "$_f" "$ABUILD_KEY" "$(basename "$ABUILD_KEY").pub" python3 ./apk-resign.py "$_f" "$KEYCOPY" "$(basename "$ABUILD_KEY").pub"
done done
rm -f "$KEYCOPY"
mkdir -p "$WORKDIR/packages/edge/aarch64" mkdir -p "$WORKDIR/packages/edge/aarch64"
mv "$IMSD_DL"/*.apk "$WORKDIR/packages/edge/aarch64/" mv "$IMSD_DL"/*.apk "$WORKDIR/packages/edge/aarch64/"
pmbootstrap index pmbootstrap index