Files
inbuxa-installer/e2e/cases/all-host.sh
T
jcoffey-dev 2da8df0289 --proxy snippets: nginx routes 443 by name, the server serves its own names (#48)
The nginx file terminated TLS for the server's names with a certificate the
operator supplied, for the names known at install time only. A domain added
later got the wrong certificate on 443, its HTTP-01 challenges weren't
forwarded on port 80, and the server's _443._tcp TLSA records described a
certificate nobody was served.

nginx now routes 443 by name, in nginx-inbuxa-stream.conf (stream,
ssl_preread). The console and the webmail go to nginx's own TLS on
127.0.0.1:8444; every other name goes, untouched and with the PROXY protocol
header, to the server's own HTTPS listener on 127.0.0.1:8443. That listener
is fitted by the installer (jmap.PassThroughListener): bound on loopback on
the host, or kept on the container's 443 and published on 127.0.0.1:8443,
and taking PROXY only from where nginx connects. Port 80 also passes the
challenges of the four service names of any domain.

An install from before keeps its layout, since a new file in front of an
unfitted server would break its names at the next reload. Running install
again with --key fits the listener and moves it over; the install record
notes it (passThrough). A move between shapes fits it again.

Caddy can't route by name without a plugin, so its fragment says what that
means for domains added later and TLSA.
2026-11-08 12:24:54 -07:00

80 lines
5.4 KiB
Bash

#!/bin/bash
# SPDX-FileCopyrightText: 2026 Coffey Labs LLC
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# Everything on the host, nothing in a container: the server and the webmail
# under systemd, the console as files, behind the nginx this machine already
# runs (--proxy snippets). No container runtime is installed at all.
#
# Until the console's and the webmail's releases carry their tarballs, pass
# them: CONSOLE_TARBALL=… WEBMAIL_TARBALL=… e2e/vm/run.sh e2e/cases/all-host.sh
set -uo pipefail
pass=0; fail=0
ok() { echo " ok $*"; pass=$((pass+1)); }
bad() { echo " FAIL $*"; fail=$((fail+1)); }
DIR=/var/lib/inbuxa
D=example.test
[ -f /tmp/inbuxa-console-test.tar.gz ] && export INBUXA_CONSOLE_TARBALL=/tmp/inbuxa-console-test.tar.gz
[ -f /tmp/inbuxa-webmail-test.tar.gz ] && export INBUXA_WEBMAIL_TARBALL=/tmp/inbuxa-webmail-test.tar.gz
echo "==> a machine with nginx, and no container runtime"
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nginx libnginx-mod-stream openssl >/dev/null 2>&1
systemctl is-active --quiet nginx && ok "nginx is running" || { bad "no nginx"; exit 1; }
echo
echo "==> installing everything on the host"
OUT="$(/tmp/inbuxa install --domain $D --server host --console host --webmail host --proxy snippets --install-deps --yes 2>&1)"; rc=$?
echo "$OUT" | grep -v '^ |' | tail -16 | sed 's/^/ /'
[ $rc -eq 0 ] && ok "installed (exit 0)" || bad "exit $rc"
command -v docker >/dev/null || command -v podman >/dev/null && bad "a container runtime was installed" || ok "no container runtime was installed"
[ -f $DIR/compose.yaml ] && bad "there is a compose project" || ok "no compose project"
for u in inbuxa-server inbuxa-webmail; do systemctl is-active --quiet $u && ok "$u is running" || bad "$u is not running"; done
grep -q "name=\"api-base-url\" content=\"https://mail.$D\"" $DIR/console/index.html && ok "the console's files name https://mail.$D" || bad "the console's index.html"
echo
echo "==> behind nginx, from the configuration it wrote"
mkdir -p /etc/ssl/inbuxa
for n in mail.$D admin.$D webmail.$D; do
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 2 -subj "/CN=$n" \
-keyout /etc/ssl/inbuxa/$n.key.pem -out /etc/ssl/inbuxa/$n.fullchain.pem 2>/dev/null
done
cp $DIR/proxy/nginx-inbuxa.conf /etc/nginx/conf.d/inbuxa.conf
echo "include $DIR/proxy/nginx-inbuxa-stream.conf;" >> /etc/nginx/nginx.conf
nginx -t >/dev/null 2>&1 && ok "nginx -t accepts it" || { bad "nginx -t"; nginx -t 2>&1 | sed 's/^/ /'; }
systemctl reload nginx; sleep 3
via() { curl -sk --resolve "$1:443:127.0.0.1" "${@:2}"; }
PAGE=$(via admin.$D https://admin.$D/)
grep -q "content=\"https://mail.$D\"" <<<"$PAGE" && ok "the console is served from its files" || bad "the console is not served"
CODE=$(via admin.$D -o /dev/null -w '%{http_code}' https://admin.$D/some/route/in/the/app)
[ "$CODE" = 200 ] && ok "and its routes fall back to the app" || bad "an app route answered $CODE"
ASSET=$(grep -o '/assets/[^"]*\.js' <<<"$PAGE" | head -1)
via admin.$D -D - -o /dev/null "https://admin.$D$ASSET" | grep -qi "cache-control: public, immutable" && ok "hashed assets are cached for good" || bad "no immutable cache on $ASSET"
via webmail.$D https://webmail.$D/api/health | grep -q '"ok":true' && ok "the webmail is healthy through nginx" || bad "the webmail through nginx"
CODE=$(via mail.$D -o /dev/null -w '%{http_code}' https://mail.$D/.well-known/jmap)
case "$CODE" in 30*|200|401) ok "the mail server through nginx ($CODE)" ;; *) bad "the server through nginx: $CODE" ;; esac
# Passed through to the server's own HTTPS on loopback, not nginx's (#48).
MAIL_FP=$(echo | timeout 10 openssl s_client -connect 127.0.0.1:443 -servername mail.$D 2>/dev/null | openssl x509 -noout -fingerprint -sha256 2>/dev/null)
[ -n "$MAIL_FP" ] && [ "$MAIL_FP" != "$(openssl x509 -in /etc/ssl/inbuxa/mail.$D.fullchain.pem -noout -fingerprint -sha256)" ] \
&& ok "mail.$D is served the server's own certificate" || bad "mail.$D is served nginx's certificate"
ss -Hltn 'sport = :8443' | grep -q '127.0.0.1:8443' && ! ss -Hltn 'sport = :8443' | grep -qv '127.0.0.1:8443' \
&& ok "the server's HTTPS is on 127.0.0.1:8443 only" || bad "8443: $(ss -Hltn 'sport = :8443' | awk '{print $4}' | tr '\n' ' ')"
# The server gives a code for the webmail's own address only if it knows the
# webmail's client: registered from the secret in its environment.
USER=$(awk '/^first mailbox/ {print $3}' "$DIR/credentials.txt")
PASS=$(awk '/^first mailbox/{getline; print $2}' "$DIR/credentials.txt")
ANSWER=$(via mail.$D -X POST https://mail.$D/api/auth -H 'Content-Type: application/json' -H 'Accept: application/json' \
-d "{\"type\":\"authCode\",\"accountName\":\"$USER\",\"accountSecret\":\"$PASS\",\"clientId\":\"ihasmail-inbuxa\",\"redirectUri\":\"https://webmail.$D/api/auth/callback\",\"codeChallenge\":\"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM\",\"codeChallengeMethod\":\"S256\"}")
grep -q '"client_\{0,1\}[cC]ode"' <<<"$ANSWER" && ok "the server signs people in for the webmail at https://webmail.$D" || { bad "no sign-in for the webmail"; head -c 200 <<<"$ANSWER" | sed 's/^/ /'; }
echo
echo "==> status"
STATUS="$(/tmp/inbuxa status 2>&1)"; rc=$?
for k in server console webmail; do grep -q "$k.*installed as a host" <<<"$STATUS" && ok "status: the $k is a host install" || bad "status: $k"; done
[ $rc -eq 0 ] && ok "intent and reality agree" || { bad "status exit $rc"; echo "$STATUS" | sed 's/^/ /'; }
echo
echo "==> $pass passed, $fail failed"
[ "$fail" -eq 0 ]