#!/bin/sh # System scope is world-readable, like /usr (gl_scope_dir_mode): every # user must be able to run what syspkg installs, through /usr or # /glacier/sys/links, and read the system index. User scope stays 0700. # syspkg runs under umask 077 here, so a mode that only comes from # mkdir()'s argument (and not an explicit chmod) fails. Runs INSIDE the # Dockerfile.alpine_root image: # # ./run_docker.sh Dockerfile.alpine_root # builds glacier-alpine_root # docker run --rm -v "$PWD/tests/sys_perms_alpine.sh:/t.sh:ro" glacier-alpine_root sh /t.sh FAILS=0 check() { d=$1; shift; if "$@"; then echo "PASS: $d"; else echo "FAIL: $d"; FAILS=$((FAILS+1)); fi; } mode() { [ "$(stat -c %a "$1")" = "$2" ]; } U() { su glacier -c "$1" >/dev/null 2>&1; } # mkpkg NAME REPO -> /srv/NAME-1.0.0.gpkg (+ sidecar). The archive lists # only files, no directory entries, so every parent of usr/bin/NAME is # created implicitly at extraction. mkpkg() { w=$(mktemp -d); d=$w/$1-1.0.0 mkdir -p $d/files/usr/bin printf '#!/bin/sh\necho %s-ok\n' "$1" > $d/files/usr/bin/$1; chmod 755 $d/files/usr/bin/$1 printf 'PKG_NAME = "%s";\nPKG_VER = "1.0.0";\nPKG_DESC = "t";\nPKG_MAINT = "t@e";\nPKG_COPYRIGHT = "MIT";\nPKG_REPO = "%s";\nPKG_DEPS = ();\nPKG_CONFS = ();\n' "$1" "$2" > $d/manifest.gpm.cfg tar czf /srv/$1-1.0.0.gpkg -C $w $1-1.0.0/manifest.gpm.cfg $1-1.0.0/files/usr/bin/$1 printf 'sha256:%s\n' "$(sha256sum /srv/$1-1.0.0.gpkg | cut -d' ' -f1)" > /srv/$1-1.0.0.gpkg.sha256 gsign -S -s /root/glacier-test.sec -m /srv/$1-1.0.0.gpkg.sha256 >/dev/null chmod 644 /srv/$1-1.0.0.gpkg /srv/$1-1.0.0.gpkg.sha256 /srv/$1-1.0.0.gpkg.sha256.sig rm -rf $w } mkdir -p /srv; chmod 755 /srv mkpkg pbase base; mkpkg pextra extra; mkpkg puser extra cd /app (umask 077; ./syspkg -n >/dev/null 2>&1) (umask 077; echo y | ./syspkg -l /srv/pbase-1.0.0.gpkg /srv/pextra-1.0.0.gpkg >/dev/null 2>&1) echo "== system scope, installed under umask 077" for d in /glacier/sys/index /glacier/sys/store /glacier/sys/links \ /glacier/sys/store/base /glacier/sys/store/base/pbase \ /glacier/sys/store/base/pbase/pbase-1.0.0 \ /glacier/sys/store/base/pbase/pbase-1.0.0/usr \ /glacier/sys/store/base/pbase/pbase-1.0.0/usr/bin \ /glacier/sys/links/bin; do check "$d is 755" mode $d 755 done check "system index file is 644" mode "$(readlink -f /glacier/sys/index/current)" 644 check "user runs a base package through /usr" U "/usr/bin/pbase | grep -q pbase-ok" check "user runs an extra package through sys links" U "/glacier/sys/links/bin/pextra | grep -q pextra-ok" check "user reads the system index" U "grep -q base::pbase /glacier/sys/index/current" echo "== a later transaction (seeded stage) keeps the modes" (umask 077; echo y | ./syspkg -x pextra >/dev/null 2>&1) check "store still 755 after removal" mode /glacier/sys/store 755 check "store/base still 755 after removal" mode /glacier/sys/store/base 755 check "index file still 644 after removal" mode "$(readlink -f /glacier/sys/index/current)" 644 check "user still runs the base package" U "/usr/bin/pbase | grep -q pbase-ok" echo "== user scope stays private" U "doas /app/gstore -n" U "cd /app && echo y | ./gpkg -l /srv/puser-1.0.0.gpkg" B=/glacier/usr/1000 check "user package installed" test -d $B/store/extra/puser for d in $B/index $B/store $B/links $B/store/extra $B/store/extra/puser \ $B/store/extra/puser/puser-1.0.0 $B/store/extra/puser/puser-1.0.0/usr; do check "$d is 700" mode $d 700 done check "user index file is 600" mode "$(readlink -f $B/index/current)" 600 echo [ $FAILS -eq 0 ] && echo "ALL PASSED" || echo "$FAILS FAILED" exit $FAILS