Make Fedora/Rocky a tested SELinux tier in the e2e harness #64

Merged
jcoffey-dev merged 1 commits from feat/selinux-tier into main 2026-11-13 16:34:44 +00:00
4 changed files with 174 additions and 1 deletions

No files matched your search

+11
View File
@@ -294,6 +294,8 @@ is tested on a throwaway virtual machine rather than on anybody's desk:
e2e/vm/run.sh e2e/cases/status-export.sh intent against reality, and the file
OLD_REF=<commit> e2e/vm/run.sh e2e/cases/upgrade-volumes.sh
an install from before #5, upgraded
DISTRO=fedora e2e/vm/run.sh e2e/cases/selinux.sh
the SELinux-sensitive paths, with it enforcing
e2e/vm/down.sh remove it
`SERVER_BINARY=path/to/inbuxa e2e/vm/run.sh …` installs a server build
@@ -308,6 +310,15 @@ is free to break it and a failure is the installer's rather than the last
run's leftovers. `e2e/vm/up.sh` needs qemu, KVM and xorriso; nothing needs
root on your machine.
On Fedora and Rocky the machine runs SELinux enforcing, and the installer has
to live within it -- a container could not once read a directory mounted into
it. So on those two, `run.sh` reads the audit log after *any* case and fails
the run if the installer provoked an SELinux denial, even one the case
survived; `SELINUX_IGNORE=1` downgrades that to a warning. `e2e/cases/selinux.sh`
drives the paths that have been caught before (the backup archives the
server's volumes through a container) and checks them directly; on a
distribution without SELinux enforcing it skips and passes.
## License
AGPL-3.0-or-later. Some of this began as [ihasmail-oneshot], which is ours
+107
View File
@@ -0,0 +1,107 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# The SELinux tier: drive the paths SELinux has stopped the installer on
# before, with SELinux enforcing, and prove it provoked no denial.
#
# The path that bit, and the one this leans on, is the server backup: the
# installer archives the server's two volumes by mounting them, read-only,
# into a throwaway container running tar (internal/apply/upgrade.go). On
# Fedora and Rocky that is refused unless the volumes carry a label the
# container may read -- which is exactly the kind of thing a container-naive
# change breaks without noticing on Debian. So: install in containers, take a
# backup, converge, and after each step read the audit log for AVC denials in
# the installer's footprint, and confirm SELinux is still enforcing.
#
# Only meaningful where SELinux enforces, so on Debian/Ubuntu/Arch it skips and
# passes. Run it on the family it is for:
# DISTRO=fedora e2e/vm/run.sh e2e/cases/selinux.sh
# DISTRO=rocky9 e2e/vm/run.sh e2e/cases/selinux.sh
set -uo pipefail
export PATH="/usr/sbin:/sbin:$PATH" # getenforce and ausearch live here
pass=0; fail=0
ok() { echo " ok $*"; pass=$((pass+1)); }
bad() { echo " FAIL $*"; fail=$((fail+1)); }
DIR=/var/lib/inbuxa
if ! command -v getenforce >/dev/null 2>&1 || [ "$(getenforce)" != Enforcing ]; then
echo "SKIPPED: SELinux is not enforcing here ($(. /etc/os-release && echo "$PRETTY_NAME"))."
echo "This tier runs on Fedora or Rocky, e.g. DISTRO=fedora e2e/vm/run.sh e2e/cases/selinux.sh"
exit 0
fi
echo "==> SELinux is enforcing ($(. /etc/os-release && echo "$ID $VERSION_ID"))"
ok "getenforce reports Enforcing"
command -v ausearch >/dev/null 2>&1 \
&& ok "ausearch is present to read the audit log" \
|| bad "ausearch is missing (install the audit package); the denial scan cannot run"
# scan LABEL SINCE: fail if the installer provoked an AVC denial in its own
# footprint (its containers, or /var/lib/inbuxa) after the checkpoint.
scan() {
local d
d="$(ausearch -i -m avc,user_avc -ts "$2" 2>/dev/null \
| grep -iE 'inbuxa|container_t|container_file_t|svirt|conmon' || true)"
if [ -z "$d" ]; then
ok "$1: no SELinux denials"
else
bad "$1: SELinux denied something"
echo "$d" | sed 's/^/ /'
fi
}
enforcing() { [ "$(getenforce)" = Enforcing ]; }
# Whichever runtime the installer chose (podman on this family).
rt() { command -v docker >/dev/null 2>&1 && echo docker || echo podman; }
compose() {
if [ "$(rt)" = docker ]; then
docker compose -f "$DIR/compose.yaml" "$@"
else
DOCKER_HOST=unix:///run/podman/podman.sock \
/usr/local/lib/docker/cli-plugins/docker-compose -f "$DIR/compose.yaml" "$@"
fi
}
echo
echo "==> installing the suite in containers"
C=$(date +%T)
OUT="$(/tmp/inbuxa install --local --domain example.test --install-deps --yes 2>&1)"; rc=$?
[ $rc -eq 0 ] && ok "installed (exit 0)" || { bad "install exit $rc"; echo "$OUT" | tail -20 | sed 's/^/ /'; }
scan "install" "$C"
enforcing && ok "still enforcing after install" || bad "no longer enforcing after install"
STATE="$(compose ps --format '{{.Service}} {{.State}}' 2>/dev/null)"
for s in server console webmail; do
grep -q "^$s running" <<<"$STATE" && ok "$s is running" || { bad "$s is not running"; echo "$STATE" | sed 's/^/ /'; }
done
echo
echo "==> taking a backup (archives the server's volumes through a container)"
C=$(date +%T)
OUT="$(/tmp/inbuxa backup --yes 2>&1)"; rc=$?
[ $rc -eq 0 ] && ok "backup (exit 0)" || { bad "backup exit $rc"; echo "$OUT" | tail -20 | sed 's/^/ /'; }
scan "backup (archiveVolumes)" "$C"
ls "$DIR"/backups/server-*.tar.gz >/dev/null 2>&1 && ok "an archive was written: $(ls "$DIR"/backups)" || bad "no archive in $DIR/backups"
# Whole listing first: grep -q stops at the first match, and under pipefail the
# cut-off tar would fail the check on its own.
LIST="$(tar -tzf "$DIR"/backups/server-*.tar.gz 2>/dev/null)"
grep -q "config.json" <<<"$LIST" && ok "with the server's configuration in it" || bad "the archive has no config.json"
# The backup stops the server and must start it again.
grep -q "^server running" <<<"$(compose ps --format '{{.Service}} {{.State}}' 2>/dev/null)" \
&& ok "the server is running again after the backup" || bad "the server did not come back after the backup"
echo
echo "==> running install again converges, under SELinux, without a denial"
C=$(date +%T)
/tmp/inbuxa install --local --domain example.test --yes >/dev/null 2>&1 && ok "converged (exit 0)" || bad "the second install failed"
scan "converge" "$C"
echo
echo "==> SELinux is still enforcing at the end"
enforcing && ok "getenforce still reports Enforcing" || bad "SELinux is no longer enforcing"
echo
echo "==> $pass passed, $fail failed"
[ "$fail" -eq 0 ]
+30
View File
@@ -93,3 +93,33 @@ vm_scp() {
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-o LogLevel=ERROR -P "$SSH_PORT" "$@"
}
# ---- the SELinux tier ----
#
# On the Red Hat family the installer runs under SELinux enforcing, and SELinux
# has stopped it before (a container could not read a directory mounted into
# it; see internal/apply/upgrade.go). These let run.sh turn any case on Fedora
# or Rocky into a check that the installer provoked no SELinux denial. They run
# in the guest, where the audit log is, and report nothing anywhere SELinux is
# not enforcing, so they are harmless on Debian, Ubuntu and Arch.
# vm_selinux_enforcing is true only where the guest has SELinux in enforcing
# mode. getenforce is in /sbin, which a non-login shell may not have on PATH,
# so this goes through sudo, whose secure_path does.
vm_selinux_enforcing() {
[ "$(vm_ssh 'sudo getenforce 2>/dev/null || echo Disabled')" = Enforcing ]
}
# vm_audit_checkpoint prints a time to hand back to vm_selinux_denials, so a
# scan sees only what happened after it -- not the machine's boot.
vm_audit_checkpoint() {
vm_ssh 'date +%T'
}
# vm_selinux_denials prints the guest's AVC denials since the checkpoint that
# touch the installer's footprint -- its containers and /var/lib/inbuxa -- one
# per line, or nothing. Reading the audit log needs root.
vm_selinux_denials() {
vm_ssh "sudo ausearch -i -m avc,user_avc -ts '$1' 2>/dev/null" \
| grep -iE 'inbuxa|container_t|container_file_t|svirt|conmon' || true
}
+26 -1
View File
@@ -61,4 +61,29 @@ vm_scp "$ROOT/$CASE" [email protected]:/tmp/case.sh >/dev/null
vm_ssh 'chmod +x /tmp/inbuxa /tmp/case.sh; [ ! -f /tmp/inbuxa-old ] || chmod +x /tmp/inbuxa-old'
echo "==> running $(basename "$CASE")"
vm_ssh 'sudo -E bash /tmp/case.sh'
# On Fedora/Rocky the case runs under SELinux enforcing; note the time first so
# the scan afterwards sees only what the case provoked, not the boot.
CKPT=""
if vm_selinux_enforcing; then CKPT="$(vm_audit_checkpoint)"; fi
rc=0
vm_ssh 'sudo -E bash /tmp/case.sh' || rc=$?
# The SELinux tier: a case that passed its own checks still fails the run if
# the installer made SELinux deny something -- a denial it happened to survive
# today is a latent break. SELINUX_IGNORE=1 downgrades that to a warning.
if [ -n "$CKPT" ]; then
echo "==> SELinux: denials since the case began"
DEN="$(vm_selinux_denials "$CKPT")"
if [ -n "$DEN" ]; then
echo "$DEN" | sed 's/^/ /'
if [ "${SELINUX_IGNORE:-}" = 1 ]; then
echo " SELINUX_IGNORE=1: not failing the run on these."
else
echo " the installer must not provoke SELinux denials (SELINUX_IGNORE=1 to override)" >&2
rc=1
fi
else
echo " none -- SELinux stayed out of the installer's way"
fi
fi
exit "$rc"