commit d2c3d32a3acd52734a5cf728e5ad021b4e8eaed7
parent 0dd7ac75c0ae4fee506a4cacb87803e57c03ce39
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 14 Nov 2026 23:51:14 +0530
parent 0dd7ac75c0ae4fee506a4cacb87803e57c03ce39
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 14 Nov 2026 23:51:14 +0530
Publish signed APT releases on cdg-1 using POSIX shell and native tools
7 files changed, 320 insertions(+), 114 deletions(-)
A
|
159
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D
|
79
-------------------------------------------------------------------------------
diff --git a/AGENTS.md b/AGENTS.md @@ -1,5 +1,28 @@ # Foundation Packages Binaries +## Mandatory scripting policy: POSIX sh only + +- Write all project automation, CI jobs, deployment/publisher scripts, tests, + and agent-created helpers in POSIX `sh`. Use `#!/bin/sh` for executable scripts. +- This rule applies locally and on servers, including temporary files, inline + commands, heredocs, generated scripts, and diagnostic or migration helpers. + Do not use Python, Perl, Ruby, JavaScript/TypeScript, Lua, or another scripting + language as an implementation or assistance shortcut. +- Use POSIX shell syntax and standard utilities, or existing native build, + packaging, signing, and transfer tools. Do not require Bash or Zsh, change the + interpreter to evade this rule, or use their extensions (such as `[[ ... ]]`, + arrays, process substitution, or `source`; use POSIX `.` instead). +- Existing non-shell scripts or documentation examples are not permission to + add, restore, invoke, or deploy such helpers. Ask before any exception; if a + task cannot be completed within this policy, report the blocker instead. +- This governs repository tooling and agent assistance, not the implementation + language of upstream software being packaged or its required build tools. +- Before completion, run `sh -n` on every added or modified shell script and + execute the relevant checks with `sh`. A syntax check alone is not proof of + POSIX portability; inspect commands and syntax for non-POSIX extensions. + +## Archive and publication rules + - **APT publication or client setup:** read [docs/apt.md](docs/apt.md). Completion requires verified local and HTTPS copies; retained archives are not build outputs. - **Bootstrap tool builds:** read [README.md](README.md) for the Debian host, @@ -9,5 +32,6 @@ - Retain released versions. Increment versions when changing package bytes. - Private keys, revocation certificates, and credentials stay outside Git and all publicly served trees. The signing fingerprint and public keys are versioned. -- Validate publisher changes with `python3 tests/apt-repository.py`; shell changes - with `sh -n`. Test actual APT signature rejection in isolated client state. +- Validate publisher changes with POSIX shell tests and native packaging/signing + tools. Run `sh -n` on changed shell scripts. Test actual APT signature rejection + in isolated client state; do not run the legacy Python test.
diff --git a/docs/apt.md b/docs/apt.md @@ -17,11 +17,13 @@ Dedicated archive key: - Algorithm: RSA-3072, signing capability; created 2026-10-29 UTC, expires 2028-10-28. - Public keys: `keys/foundationpkgs-archive-keyring.gpg` and `keys/foundationpkgs-archive.asc`. -This is NOT the APK CI RSA key or an SSH key. The private OpenPGP key stays on the -publisher's Mac under `~/.local/share/foundationpkgs/gnupg/` (0700). The private key -has no passphrase, allowing unattended local signing; file permissions protect -it, not encryption. Anyone who compromises that user can sign repository data. -Do not copy that directory to Git, CI, or the HTTPS server. +This is NOT the APK CI RSA key or an SSH key. The always-on publisher runs as +`fpkgs-publisher` on `cdg-1`, separately from the `git` build identity. Its private +OpenPGP key is in `/var/lib/foundationpkgs-publisher/gnupg` (0700), outside Git and +all publicly served trees. The existing key is retained so clients do not need +to change trust. The Mac's original key directory and private backup are recovery +copies, not a requirement for normal publication. The key has no passphrase for +unattended signing; account/file permissions protect it, not encryption. A private-key export and revocation certificate are saved under `~/.local/share/foundationpkgs/key-backups/` (directory 0700, files 0600). This is @@ -76,7 +78,7 @@ bootstrap tools (`abuild`, `apk-tools`) are also published. This does not mirror Debian's dependency repositories. Ordinary APT updates are supported; `unattended-upgrades` is a separate administrator policy and is not enabled here. -## Local archive and publication +## Retained archive and publication on cdg-1 `archive/pool/` retains every imported package version. `repository-releases/` retains complete signed snapshots, and `repository` points to the current local @@ -87,34 +89,47 @@ build logs, and the exact recipe/tool snapshot; it too is excluded from Git. Never delete these directories as if they were disposable build outputs. The public CI artifact store independently retains the release provenance. +The authoritative data root is `/var/lib/foundationpkgs-publisher` on `cdg-1`. +The existing Mac archive remains a recovery copy. All new automation is POSIX +`sh`, using native Debian `apt-ftparchive`, `dpkg-deb`, GnuPG, rsync, curl and +checksum tools; no other scripting runtime is used. + +The foundationpkgs Jobfile runs `checks → plan → packages → transfer → deploy`: + +1. `packages` builds and tests the selected `.deb` files as the unprivileged CI user. +2. `transfer` looks up SHA-256-verified artifacts for the exact pushed commit, + copies each artifact/manifest/checksum/build log plus a `git archive` source + snapshot into a temporary handoff, and invokes the fixed publisher receiver. +3. `receive` rechecks the copied revision, target, control metadata, safe paths + and checksums, then retains them in `provenance/<commit>/`. It does not execute + or extract the supplied source snapshot. Repeated transfers must match. +4. `deploy` requires that retained receipt, checks immutable-version collisions + before importing, generates native APT indexes and a 90-day Release, and signs + with the existing archive key. Changed package bytes require a new `pkgrel`. +5. It retains a complete signed snapshot, verifies the staged public copy, + atomically switches the public `apt` symlink, then checks every file over HTTPS. + Only successful HTTPS verification records `provenance/<commit>/DEPLOYED`. + +The two entry points are deliberately narrow: + ```sh -python3 scripts/publish-apt.py import /path/to/verified/package_VERSION_amd64.deb -python3 scripts/publish-apt.py publish +sudo -n -u fpkgs-publisher /usr/local/libexec/foundationpkgs-apt receive FULL_SHA /var/lib/foundationpkgs-handoff/BUNDLE +sudo -n -u fpkgs-publisher /usr/local/libexec/foundationpkgs-apt deploy FULL_SHA ``` -The publisher needs Python 3.9+ (3.10+ recommended), local GnuPG, SSH and rsync; -the SSH destination needs Debian `apt-utils` (`apt-ftparchive`), `dpkg-deb`, -rsync and SHA-256 tools. No private archive key is required on that server. - -The publish command: - -1. Copies all retained packages into a local snapshot (hard links avoid duplication). -2. Stages public package files on the configured server. -3. Uses the server's standard `apt-ftparchive` to generate indexes/Release metadata. -4. Checks package paths, control metadata, architecture, sizes and SHA-256 against local bytes. -5. Signs locally with the dedicated archive key; no private key goes to the server. -6. Saves the complete signed local snapshot before activating its HTTPS copy. -7. Checks remote SHA-256, atomically selects the snapshot, and verifies every published - file over HTTPS against its local copy. Success means both copies were verified. - -Publication is explicit. CI can build while the Mac is offline, but cannot sign -or finalize an archive release without the local publisher. Download and retain -its verified artifacts before publication. A network failure can leave a staged -or activated release; the command reports failure rather than claiming both -copies are verified. Snapshots and failed staging directories are retained. -Inspect a stale `.apt-publish-lock` / remote `.publish-lock` before removing it; -never run concurrent publishers. `apt-repository.json` specifies the destination -and full key fingerprint. Publishing does not install or upgrade client packages. +The wrapper clears the caller's environment and invokes root-owned +`/usr/local/libexec/foundationpkgs-publisher/publish-apt.sh`. The CI user has no +publisher shell or general sudo grant. Publication necessarily trusts the CI +identity to submit package content; that identity cannot read the signing key +or replace the installed publisher. Changes to publisher code require an explicit +administrator installation, not execution of scripts from the tested branch. +The versioned `scripts/ci-publisher-wrapper.sh` is the installation template. + +A failed HTTPS check may occur after activation; report failure and inspect the +retained snapshot rather than claiming successful delivery. Inspect a stale +`.apt-publish-lock` before removing it; concurrent publishes fail closed. +`apt-repository.json` records the native host/destination/fingerprint; the installed +wrapper fixes production defaults. Publishing never installs or upgrades clients. Metadata expires after 90 days to limit replay. Republish before expiry even when package versions have not changed. A new snapshot retains old by-hash @@ -148,7 +163,9 @@ also remains separate from the passing HTTP/CLI smoke checks. ## Checks ```sh -python3 tests/apt-repository.py +for file in scripts/*.sh tests/*.sh; do sh -n "$file" || exit; done +# On Debian with native tools: temporary fixture key/archive, no production state. +sh tests/apt-publisher.sh # On a Debian client; network required, no installation or live-source changes: sh tests/apt-client.sh ```
diff --git a/scripts/ci-publisher-wrapper.sh b/scripts/ci-publisher-wrapper.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# Install root-owned as /usr/local/libexec/foundationpkgs-apt. +# Never inherit CI-controlled shell/interpreter/GPG configuration into the signer. +cd /var/lib/foundationpkgs-publisher || exit 1 +exec /usr/bin/env -i \ + HOME=/var/lib/foundationpkgs-publisher \ + GNUPGHOME=/var/lib/foundationpkgs-publisher/gnupg \ + PATH=/usr/bin:/bin LC_ALL=C \ + FPKGS_APT_ROOT=/var/lib/foundationpkgs-publisher \ + /bin/sh /usr/local/libexec/foundationpkgs-publisher/publish-apt.sh "$@"
diff --git a/scripts/publish-apt.sh b/scripts/publish-apt.sh @@ -0,0 +1,159 @@ +#!/bin/sh +# Native Debian publisher. Install root-owned; run as the separate publisher user. +set -eu +umask 022 +root=${FPKGS_APT_ROOT:-$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)} +public=${FPKGS_APT_PUBLIC_ROOT:-/srv/http/dl.nply.org/foundationpkgs-binaries} +url=${FPKGS_APT_URL:-https://nply.org/dl/foundationpkgs-binaries/apt} +fingerprint=${FPKGS_APT_FINGERPRINT:-9EF366A63EC38FB0A160549D33F4C03101AEC8D2} +export LC_ALL=C +fail() { printf 'publish-apt: %s\n' "$*" >&2; exit 1; } +field() { awk -F= -v key="$2" '$1 == key { n++; value=substr($0,length(key)+2) } END { if (n != 1) exit 1; print value }' "$1"; } +registry() { (cd "$1" && find . -type f ! -name RECEIPT.sha256 -print | sort | while IFS= read -r file; do sha256sum "$file"; done); } +verify_bundle() { + bundle=$1 + [ -f "$bundle/source.tar.gz" ] || fail 'Missing source snapshot' + [ -z "$(find "$bundle" ! -type f ! -type d -print)" ] || fail 'Non-regular bundle entry' + count=0 + for dir in "$bundle"/*; do + [ -d "$dir" ] || continue + pkg=${dir##*/} + case "$pkg" in '' | . | .. | *[!a-z0-9+.-]*) fail 'Invalid package name' ;; esac + manifest=$dir/manifest + [ "$(field "$manifest" gitrev)" = "$rev" ] || fail 'Wrong revision' + [ "$(field "$manifest" pkgname)" = "$pkg" ] || fail 'Wrong package' + [ "$(field "$manifest" target)" = x86_64-unknown-linux-gnu ] || fail 'Wrong target' + [ "$(field "$manifest" format)" = deb ] || fail 'Not a Debian publication' + file=$(field "$manifest" artifact) + case "$file" in "$pkg"_*.deb) ;; *) fail 'Unexpected artifact name' ;; esac + case "$file" in *[!a-zA-Z0-9_.+~:-]*) fail 'Unsafe artifact path' ;; esac + # This backend produces one primary .deb; do not accept arbitrary checksum paths. + awk -v file="$file" 'NF != 2 || length($1) != 64 || $1 ~ /[^0-9a-f]/ || ($2 != file && $2 != "./" file) { exit 1 } END { if (NR != 1) exit 1 }' "$dir/SHA256SUMS" || fail 'Invalid checksum registry' + (cd "$dir" && sha256sum -c SHA256SUMS) || fail 'Artifact checksum mismatch' + [ -f "$dir/build.log" ] || fail 'Missing build log' + [ "$(dpkg-deb -f "$dir/$file" Package)" = "$pkg" ] || fail 'Control package mismatch' + version=$(dpkg-deb -f "$dir/$file" Version) + arch=$(dpkg-deb -f "$dir/$file" Architecture) + case "$arch" in amd64 | all) ;; *) fail 'Unsupported architecture' ;; esac + [ "$file" = "${pkg}_${version}_${arch}.deb" ] || fail 'Control version/architecture mismatch' + count=$((count + 1)) + done + [ "$count" -gt 0 ] || fail 'Empty release' +} +case "$fingerprint" in *[!0-9A-F]*) fail 'Invalid fingerprint' ;; esac +[ "${#fingerprint}" -eq 40 ] || fail 'Expected full signing fingerprint' +[ "$#" -ge 2 ] || fail 'usage: publish-apt.sh receive REV BUNDLE | deploy REV' +action=$1 +rev=$2 +case "$rev" in '' | *[!0-9a-f]*) fail 'Expected full commit SHA' ;; esac +[ "${#rev}" -eq 40 ] || fail 'Expected full commit SHA' +mkdir -p "$root/provenance" "$root/archive/pool/main" "$root/repository-releases" +mkdir "$root/.apt-publish-lock" || fail 'Another publisher is active; inspect lock before removing' +temporary= +cleanup() { [ -z "$temporary" ] || rm -rf "$temporary"; rmdir "$root/.apt-publish-lock"; } +trap cleanup 0 +trap 'exit 1' HUP INT TERM +receipt=$root/provenance/$rev +case "$action" in +receive) + [ "$#" -eq 3 ] || fail 'Expected a bundle directory' + [ -d "$3" ] && [ ! -L "$3" ] || fail 'Invalid bundle directory' + [ -z "$(find "$3" ! -type f ! -type d -print)" ] || fail 'Non-regular incoming entry' + temporary=$(mktemp -d "$root/provenance/.incoming.XXXXXX") + rsync -rt -- "$3/" "$temporary/" + verify_bundle "$temporary" + registry "$temporary" > "$temporary/RECEIPT.sha256" + if [ -e "$receipt" ]; then + (cd "$receipt" && sha256sum -c RECEIPT.sha256) + cmp "$temporary/RECEIPT.sha256" "$receipt/RECEIPT.sha256" || fail 'Revision already retained with different bytes' + else + mv "$temporary" "$receipt" + temporary= + fi + printf 'Retained verified CI release: %s\n' "$rev" + ;; +deploy) + [ "$#" -eq 2 ] || fail 'Unexpected deploy arguments' + [ -d "$receipt" ] || fail 'Transfer this revision first' + (cd "$receipt" && sha256sum -c RECEIPT.sha256) + verify_bundle "$receipt" + # Preflight every collision before changing the retained pool. + for dir in "$receipt"/*; do + [ -d "$dir" ] || continue + pkg=${dir##*/} + file=$(field "$dir/manifest" artifact) + first=$(printf '%.1s' "$pkg") + archive=$root/archive/pool/main/$first/$pkg + if [ -e "$archive/$file" ]; then + cmp "$dir/$file" "$archive/$file" || fail "Immutable version differs: $file; increment pkgrel" + fi + done + for dir in "$receipt"/*; do + [ -d "$dir" ] || continue + pkg=${dir##*/} + file=$(field "$dir/manifest" artifact) + first=$(printf '%.1s' "$pkg") + archive=$root/archive/pool/main/$first/$pkg + mkdir -p "$archive" + [ -e "$archive/$file" ] || install -m644 "$dir/$file" "$archive/$file" + done + identifier=$(date -u +%Y%m%dT%H%M%SZ)-$(printf '%.12s' "$rev")-$$ + stage=$root/repository-releases/$identifier + mkdir "$stage" + # Retain signed snapshots before changing the served symlink. Never prune releases. + cp -al "$root/archive/pool" "$stage/pool" + index=$stage/dists/trixie/main/binary-amd64 + mkdir -p "$index" + (cd "$stage" && apt-ftparchive packages pool) > "$index/Packages" + [ -s "$index/Packages" ] || fail 'Empty package index' + [ "$(grep -c '^Filename: ' "$index/Packages")" -eq "$(find "$stage/pool" -type f -name '*.deb' | wc -l)" ] || fail 'Incomplete package index' + gzip -n -c "$index/Packages" > "$index/Packages.gz" + previous=$root/repository/dists/trixie/main/binary-amd64/by-hash + [ ! -d "$previous" ] || cp -a "$previous" "$index/by-hash" + for file in Packages Packages.gz; do + for algorithm in SHA256 SHA512; do + case "$algorithm" in SHA256) sum=$(sha256sum "$index/$file") ;; SHA512) sum=$(sha512sum "$index/$file") ;; esac + mkdir -p "$index/by-hash/$algorithm" + cp "$index/$file" "$index/by-hash/$algorithm/${sum%% *}" + done + done + (cd "$stage" && apt-ftparchive \ + -o APT::FTPArchive::Release::Origin='Foundation Packages' \ + -o APT::FTPArchive::Release::Label='Foundation Packages Binaries' \ + -o APT::FTPArchive::Release::Suite=trixie \ + -o APT::FTPArchive::Release::Codename=trixie \ + -o APT::FTPArchive::Release::Architectures=amd64 \ + -o APT::FTPArchive::Release::Components=main \ + -o APT::FTPArchive::Release::ValidTime=7776000 \ + -o APT::FTPArchive::Release::Acquire-By-Hash=yes \ + release dists/trixie) > "$stage/dists/trixie/Release" + for mode in clearsign detach-sign; do + case "$mode" in clearsign) output=InRelease ;; detach-sign) output=Release.gpg ;; esac + gpg --batch --yes --local-user "$fingerprint" --digest-algo SHA256 --armor \ + --output "$stage/dists/trixie/$output" --"$mode" "$stage/dists/trixie/Release" + done + gpg --batch --export "$fingerprint" > "$stage/foundationpkgs-archive-keyring.gpg" + gpgv --keyring "$stage/foundationpkgs-archive-keyring.gpg" "$stage/dists/trixie/Release.gpg" "$stage/dists/trixie/Release" + (cd "$stage" && find . -type f ! -name SHA256SUMS -print | sort | while IFS= read -r file; do sha256sum "$file"; done) > "$stage/SHA256SUMS" + mkdir -p "$public/.staging/$identifier" "$public/releases" + rsync -rt --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r "$stage/" "$public/.staging/$identifier/" + (cd "$public/.staging/$identifier" && sha256sum -c SHA256SUMS) + mv "$public/.staging/$identifier" "$public/releases/$identifier" + ln -s "repository-releases/$identifier" "$root/.repository-next" + mv -Tf "$root/.repository-next" "$root/repository" + ln -s "releases/$identifier" "$public/.apt-next" + mv -Tf "$public/.apt-next" "$public/apt" + # Activation is not success until the actual HTTPS endpoint matches every file. + temporary=$(mktemp -d "$root/.https-check.XXXXXX") + while read -r expected file; do + curl -fsSL --max-time 60 "$url/${file#./}" -o "$temporary/file" + actual=$(sha256sum "$temporary/file") + [ "${actual%% *}" = "$expected" ] || fail "HTTPS checksum mismatch: $file" + done < "$stage/SHA256SUMS" + curl -fsSL --max-time 60 "$url/SHA256SUMS" -o "$temporary/sums" + cmp "$temporary/sums" "$stage/SHA256SUMS" + printf '%s\n' "$identifier" > "$receipt/DEPLOYED" + printf 'Published and verified retained + HTTPS release: %s (%s)\n' "$identifier" "$rev" + ;; +*) fail 'Unknown action' ;; +esac
diff --git a/tests/apt-client.sh b/tests/apt-client.sh @@ -20,8 +20,16 @@ apt_update() { -o APT::Update::Error-Mode=any update } apt_update "$work/good.list" "$work/lists" +# Resolve and download via real APT (including index checksum verification), no install. +(cd "$work" && apt-get -o "Dir::Etc::sourcelist=$work/good.list" \ + -o Dir::Etc::sourceparts=- -o "Dir::State::lists=$work/lists" \ + -o "APT::Sandbox::User=$(id -un)" download saait) +set -- "$work"/saait_*.deb +[ "$#" -eq 1 ] && [ -f "$1" ] +[ "$(dpkg-deb -f "$1" Package)" = saait ] +[ "$(dpkg-deb -f "$1" Architecture)" = amd64 ] if apt_update "$work/bad.list" "$work/bad-lists" > "$work/rejected.log" 2>&1; then echo 'FAIL: repository accepted with an invalid signing key' >&2; exit 1 fi grep -Ei 'NO_PUBKEY|Missing key|not signed|signature' "$work/rejected.log" >/dev/null -printf 'PASS: real APT accepts scoped archive key and rejects invalid key; live APT state untouched\n' +printf 'PASS: real APT accepts scoped archive key, downloads saait and rejects invalid key; live APT state untouched\n'
diff --git a/tests/apt-publisher.sh b/tests/apt-publisher.sh @@ -0,0 +1,67 @@ +#!/bin/sh +# Isolated native publication regression; never uses production keys or APT state. +set -eu +for tool in dpkg-deb apt-ftparchive sha256sum sha512sum gpg gpgv rsync; do + command -v "$tool" >/dev/null 2>&1 || { echo "SKIP: requires $tool"; exit 0; } +done +self=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) +work=$(mktemp -d) +cleanup() { gpgconf --homedir "$work/keys" --kill gpg-agent >/dev/null 2>&1 || :; rm -rf "$work"; } +trap cleanup 0 +trap 'exit 1' HUP INT TERM +export GNUPGHOME=$work/keys +mkdir -m700 "$GNUPGHOME" +gpg --batch --pinentry-mode loopback --passphrase '' --quick-generate-key 'Isolated APT fixture' rsa2048 sign 1d >/dev/null 2>&1 +FPKGS_APT_FINGERPRINT=$(gpg --batch --with-colons --list-keys | awk -F: '$1=="fpr" {print $10; exit}') +export FPKGS_APT_FINGERPRINT +export FPKGS_APT_ROOT=$work/publisher FPKGS_APT_PUBLIC_ROOT=$work/public FPKGS_APT_URL=https://fixture.invalid/apt +mkdir -p "$work/bin" "$work/bundle/fixture" "$work/payload/DEBIAN" "$work/payload/usr/share/fixture" +printf 'Package: fixture\nVersion: 1.0-1\nArchitecture: all\nMaintainer: Fixture <fixture@example.invalid>\nDescription: Fixture\n' > "$work/payload/DEBIAN/control" +printf 'fixture\n' > "$work/payload/usr/share/fixture/content" +dpkg-deb --root-owner-group --build "$work/payload" "$work/bundle/fixture/fixture_1.0-1_all.deb" >/dev/null +rev=1111111111111111111111111111111111111111 +printf 'source snapshot fixture\n' > "$work/bundle/source.tar.gz" +printf 'pkgname=fixture\ngitrev=%s\ntarget=x86_64-unknown-linux-gnu\nformat=deb\nartifact=fixture_1.0-1_all.deb\n' "$rev" > "$work/bundle/fixture/manifest" +printf 'build log fixture\n' > "$work/bundle/fixture/build.log" +(cd "$work/bundle/fixture" && sha256sum fixture_1.0-1_all.deb > SHA256SUMS) +# The offline transport serves the real staged public tree, not canned metadata. +cat > "$work/bin/curl" <<'SH' +#!/bin/sh +set -eu +while [ "$#" -gt 0 ]; do + case "$1" in https://fixture.invalid/apt/*) relative=${1#https://fixture.invalid/apt/} ;; -o) shift; output=$1 ;; esac + shift +done +cp "$FPKGS_APT_PUBLIC_ROOT/apt/$relative" "$output" +SH +chmod 755 "$work/bin/curl" +export PATH=$work/bin:$PATH +run() { sh "$self/scripts/publish-apt.sh" "$@"; } +reject() { if "$@" > "$work/rejected.log" 2>&1; then echo 'FAIL: unsafe publication accepted' >&2; exit 1; fi; } +reject run deploy "$rev" +cp "$work/bundle/fixture/manifest" "$work/manifest" +printf '\ngitrev=2222222222222222222222222222222222222222\n' >> "$work/bundle/fixture/manifest" +reject run receive "$rev" "$work/bundle" +cp "$work/manifest" "$work/bundle/fixture/manifest" +cp "$work/bundle/fixture/SHA256SUMS" "$work/sums" +printf '00 ../../outside\n' > "$work/bundle/fixture/SHA256SUMS" +reject run receive "$rev" "$work/bundle" +cp "$work/sums" "$work/bundle/fixture/SHA256SUMS" +ln -s "$work/manifest" "$work/bundle/link" +reject run receive "$rev" "$work/bundle" +rm "$work/bundle/link" +run receive "$rev" "$work/bundle" +run receive "$rev" "$work/bundle" +run deploy "$rev" +[ -s "$FPKGS_APT_ROOT/provenance/$rev/DEPLOYED" ] +gpgv --keyring "$FPKGS_APT_PUBLIC_ROOT/apt/foundationpkgs-archive-keyring.gpg" "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/InRelease" +cp "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/InRelease" "$work/signed" +printf 'tampered' >> "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/Release" +reject gpgv --keyring "$FPKGS_APT_PUBLIC_ROOT/apt/foundationpkgs-archive-keyring.gpg" "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/Release.gpg" "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/Release" +# Repeat publication preserves old by-hash indexes and immutable package bytes. +run deploy "$rev" +[ "$(find "$FPKGS_APT_PUBLIC_ROOT/releases" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 2 ] +archive=$FPKGS_APT_ROOT/archive/pool/main/f/fixture/fixture_1.0-1_all.deb +printf 'different archive bytes' > "$archive" +reject run deploy "$rev" +printf 'PASS: exact revision, safe paths, copied checksums, idempotent receive, immutable versions, real indexes/signatures, atomic snapshots, tamper rejection\n'
diff --git a/tests/apt-repository.py b/tests/apt-repository.py @@ -1,79 +0,0 @@ -#!/usr/bin/env python3 -"""Offline archive/index safety checks; no SSH, private keys, or live APT state.""" -import datetime -from email.utils import format_datetime -import gzip -import hashlib -import importlib.util -from pathlib import Path -import tempfile - -spec = importlib.util.spec_from_file_location('publisher', Path(__file__).resolve().parents[1] / 'scripts/publish-apt.py') -publisher = importlib.util.module_from_spec(spec) -spec.loader.exec_module(publisher) - - -def rejected(call): - try: - call() - except (ValueError, KeyError): - return - raise AssertionError('unsafe input accepted') - - -with tempfile.TemporaryDirectory() as directory: - root = Path(directory) - publisher.ROOT = root - source = root / 'fixture_1.0-1_amd64.deb' - source.write_bytes(b'synthetic archive fixture') - publisher.import_package(source) - publisher.import_package(source) - archived = root / 'archive/pool/main/f/fixture' / source.name - assert archived.read_bytes() == source.read_bytes() - source.write_bytes(b'different bytes at the same version') - rejected(lambda: publisher.import_package(source)) - assert archived.read_bytes() != source.read_bytes() - invalid = root / 'bad.deb' - invalid.write_bytes(b'bad filename') - rejected(lambda: publisher.import_package(invalid)) - stage = root / 'archive' - relative = archived.relative_to(stage).as_posix() - index = '\n'.join([ - 'Package: fixture', 'Version: 1.0-1', 'Architecture: amd64', - 'Filename: ' + relative, 'Size: ' + str(archived.stat().st_size), - 'SHA256: ' + publisher.digest(archived), '', - ]) - publisher.verify_packages(stage, index) - rejected(lambda: publisher.verify_packages(stage, index.replace(relative, '../outside.deb'))) - rejected(lambda: publisher.verify_packages(stage, index.replace(relative, '/outside.deb'))) - rejected(lambda: publisher.verify_packages(stage, index.replace('amd64\n', 'arm64\n'))) - rejected(lambda: publisher.verify_packages(stage, index.replace('Version: 1.0-1', 'Version: 2.0-1'))) - rejected(lambda: publisher.verify_packages(stage, index.replace(publisher.digest(archived), '0' * 64))) - extra = archived.parent / 'extra_1.0-1_amd64.deb' - extra.write_bytes(b'not indexed') - rejected(lambda: publisher.verify_packages(stage, index)) - index_dir = stage / 'dists/trixie/main/binary-amd64' - index_dir.mkdir(parents=True) - (index_dir / 'Packages').write_text(index) - (index_dir / 'Packages.gz').write_bytes(gzip.compress(index.encode())) - now = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0) - release = '\n'.join([ - 'Origin: Foundation Packages', 'Suite: trixie', 'Codename: trixie', - 'Architectures: amd64', 'Components: main', 'Acquire-By-Hash: yes', - 'Date: ' + format_datetime(now), - 'Valid-Until: ' + format_datetime(now + datetime.timedelta(days=90)), - ]) + '\n' - for algorithm in ('SHA256', 'SHA512'): - release += algorithm + ':\n' - for name in ('Packages', 'Packages.gz'): - data = (index_dir / name).read_bytes() - release += ' {} {} main/binary-amd64/{}\n'.format( - hashlib.new(algorithm.lower(), data).hexdigest(), len(data), name) - publisher.verify_release(stage, release) - rejected(lambda: publisher.verify_release(stage, release.replace('Suite: trixie', 'Suite: other'))) - rejected(lambda: publisher.verify_release(stage, release.replace('main/binary-amd64/Packages.gz', '../outside'))) - rejected(lambda: publisher.verify_release(stage, release.replace( - format_datetime(now + datetime.timedelta(days=90)), format_datetime(now - datetime.timedelta(days=1))))) - (index_dir / 'Packages').write_text('tampered') - rejected(lambda: publisher.verify_release(stage, release)) -print('PASS: immutable archive, complete/safe package index, Release identity/expiry/checksum rejection')
: nply/foundationpkgs-binaries