glacier-ng 4.0.0

This commit is contained in:
lw-everestlinux committed 2026-10-29 09:15:34 -04:00
commit 0cf4829fa5
159 files changed
+33717

No files matched your search

+112
View File
@@ -0,0 +1,112 @@
#!/bin/sh
# syspkg root-path tests. Runs inside a THROWAWAY alpine container as root —
# it installs into /glacier/sys and links base packages into /usr, so never
# run it on a real system.
#
# Builds libglacier-ng from source in-container (the host's glibc .so's
# won't load on musl), copies glacier-ng into a root-owned /opt/glacier,
# then exercises syspkg's privilege checks and install/remove paths.
#
# Usage, from anywhere:
# docker run --rm \
# -v /home/lw/Projects/glacier-ng:/src:ro \
# -v /home/lw/Projects/libglacier-ng:/libsrc:ro \
# -v /home/lw/Projects/glacier-ng/tests/syspkg_alpine.sh:/t.sh:ro \
# alpine:latest sh /t.sh
set -u
# Deps per Dockerfile.alpine, minus debugging tools, plus linux-headers
# (needed for <linux/limits.h>; Dockerfile.alpine is missing it).
apk add --no-cache build-base luajit-dev libarchive-dev libconfig-dev linux-headers doas >/dev/null 2>&1 \
|| { echo "apk failed"; exit 1; }
hr() { echo; echo "=== $* ==="; }
# Symlinks under $1 pointing into the system store. busybox find has no
# -lname, so resolve each link by hand.
glacier_links() {
find "$1" -type l 2>/dev/null | while read -r l; do
case "$(readlink "$l")" in /glacier/sys/store/*) echo "$l -> $(readlink "$l")" ;; esac
done
}
hr "0. build libglacier-ng against musl"
cp -a /libsrc /build && cd /build && make clean >/dev/null && make >/tmp/make.log 2>&1 \
&& echo "build ok" || { tail -30 /tmp/make.log; exit 1; }
cp -a /src /opt/glacier
mkdir -p /opt/glacier/lib/glacier
cp /build/build/lib/shared/libglacier_*.so /opt/glacier/lib/glacier/
chown -R root:root /opt/glacier
chmod -R go-w /opt/glacier
# A throwaway key trusted for base (REPO_DESIGN.txt section 7), and the
# copies' sidecars signed with it.
mkdir -p /etc/glacier/keys
/build/build/bin/gsign -G -p /etc/glacier/keys/t.pub -s /root/t.sec -c t >/dev/null
printf 'repos = (\n\t{ name = "base"; keys = [ "t" ]; }\n);\n' > /etc/glacier/repos.conf
for s in /opt/glacier/*.gpkg.sha256 /opt/glacier/pkgs/*.gpkg.sha256; do
[ -e "$s" ] && /build/build/bin/gsign -S -s /root/t.sec -m "$s" >/dev/null
done
SP=/opt/glacier/syspkg
adduser -D -u 1000 tester
echo "permit nopass tester as root cmd $SP" > /etc/doas.conf
chmod 0400 /etc/doas.conf
hr "1. non-root user: -h/-v allowed, operations refused"
su tester -c "$SP -v"; echo "exit=$? (expect 0)"
su tester -c "$SP -n"; echo "exit=$? (expect 1)"
hr "2. help"
$SP -h; echo "exit=$?"
hr "3. copy owned by a normal user is refused even as root"
cp -a /opt/glacier /home/tester/glacier && chown -R tester /home/tester/glacier
/home/tester/glacier/syspkg -v; echo "exit=$?"
hr "4. hostile lib/ in CWD is ignored (via restricted doas rule)"
mkdir -p /tmp/evil/lib && echo 'print("EVIL CODE RAN") os.exit(9)' > /tmp/evil/lib/cargs.lua
chown -R tester /tmp/evil
su tester -c "cd /tmp/evil && doas $SP -v"; echo "exit=$?"
hr "5. LUA_INIT / LUA_PATH are ignored (as root directly, no doas env reset)"
LUA_INIT='print("EVIL LUA_INIT")' LUA_PATH='/tmp/evil/?.lua' $SP -v; echo "exit=$?"
hr "6. install before -n"
cd /opt/glacier
echo y | $SP -l kilo-0.0.1.gpkg; echo "exit=$?"
hr "7. -n with no /glacier at all"
$SP -n -V; echo "exit=$?"
hr "7b. -n with /glacier/sys pre-created (dirs but no index: completes)"
rm -rf /glacier && mkdir -p /glacier/sys
$SP -n -V; echo "exit=$?"
$SP -n; echo "re-run exit=$? (expect 1: already exists)"
echo "-- index survived the refused re-run:"; cat /glacier/sys/index/current
ls -la /glacier/sys
hr "8. install extra-repo package"
echo y | $SP -l kilo-0.0.1.gpkg; echo "exit=$?"
find /glacier/sys -maxdepth 4 | sort
echo "-- links:"; glacier_links /glacier/sys/links
echo "-- index:"; cat /glacier/sys/index/* 2>/dev/null
hr "9. install base-repo package (should link into /usr)"
echo y | $SP -l pkgs/musl-1.2.5.gpkg; echo "exit=$?"
glacier_links /usr | head
echo "-- index:"; cat /glacier/sys/index/* 2>/dev/null
hr "10. remove both"
echo y | $SP -x kilo; echo "exit=$?"
echo y | $SP -x musl; echo "exit=$?"
echo "-- leftover glacier symlinks in /usr: $(glacier_links /usr | wc -l)"
echo "-- leftover glacier symlinks in /glacier/sys/links: $(glacier_links /glacier/sys/links | wc -l)"
echo "-- index:"; cat /glacier/sys/index/* 2>/dev/null
hr "11. remove something not installed"
echo y | $SP -x nosuchpkg; echo "exit=$?"
hr "12. arg handling"
$SP -n -l x; echo "exit=$?"
$SP --bogus; echo "exit=$?"
$SP -l; echo "exit=$?"