security: pin and verify the tinfoil-proxy binary on every boot

This commit is contained in:
inference-admin committed 2026-11-19 23:35:57 +00:00
1 parent ac9b3b17af
commit fc519fb586
1 file changed
+22 -3
+22 -3
View File
@@ -222,13 +222,32 @@ echo "Starting LiteLLM on port 4000..."
# The proxy binary is downloaded at runtime into /app/data (persistent,
# writable) because Cloudron's build sandbox has no outbound network access to
# GitHub. The running container does, so we fetch it here on first start.
TINFOIL_PROXY_BIN="/app/data/tinfoil-proxy"
TINFOIL_PROXY_VERSION="v0.2.3"
TINFOIL_PROXY_SHA256="eb219044e46b65a11096a063de0a01acab562a42f7941e7aba5bc8150577c16d"
TINFOIL_PROXY_BIN="/app/data/tinfoil-proxy-${TINFOIL_PROXY_VERSION}"
TINFOIL_PROXY_URL="https://github.com/tinfoilsh/tinfoil-proxy/releases/download/${TINFOIL_PROXY_VERSION}/tinfoil-proxy-linux-amd64"
if [ ! -f "$TINFOIL_PROXY_BIN" ]; then
echo "Downloading Tinfoil proxy ${TINFOIL_PROXY_VERSION}..."
python3 -c "import urllib.request; urllib.request.urlretrieve('https://github.com/tinfoilsh/tinfoil-proxy/releases/download/${TINFOIL_PROXY_VERSION}/tinfoil-proxy-linux-amd64', '${TINFOIL_PROXY_BIN}')"
echo "Downloading Tinfoil proxy ${TINFOIL_PROXY_VERSION} (sha256 pinned)..."
python3 -c "import urllib.request; urllib.request.urlretrieve('${TINFOIL_PROXY_URL}', '${TINFOIL_PROXY_BIN}.part')"
actual=$(python3 -c "import hashlib,sys; print(hashlib.sha256(open(sys.argv[1],'rb').read()).hexdigest())" "${TINFOIL_PROXY_BIN}.part")
if [ "$actual" != "$TINFOIL_PROXY_SHA256" ]; then
echo "FATAL: tinfoil-proxy checksum mismatch (got $actual, want $TINFOIL_PROXY_SHA256)" >&2
rm -f "${TINFOIL_PROXY_BIN}.part"
exit 1
fi
mv "${TINFOIL_PROXY_BIN}.part" "$TINFOIL_PROXY_BIN"
chmod +x "$TINFOIL_PROXY_BIN"
fi
# Verify EVERY boot: a tampered persistent volume or restored backup must not
# silently disable attestation.
actual=$(python3 -c "import hashlib,sys; print(hashlib.sha256(open(sys.argv[1],'rb').read()).hexdigest())" "$TINFOIL_PROXY_BIN")
if [ "$actual" != "$TINFOIL_PROXY_SHA256" ]; then
echo "FATAL: tinfoil-proxy binary checksum mismatch (got $actual); refusing to start unverified proxy" >&2
exit 1
fi
# Remove the old unversioned binary from earlier releases so a version bump can
# never leave the previous executable in place.
rm -f /app/data/tinfoil-proxy
echo "Starting Tinfoil proxy on 127.0.0.1:3301..."
# Kill any stale proxy from a previous start attempt first — on process-level