#!/bin/bash # # Build Archipelago Auto-Installer ISO (StartOS-like) # # This creates an ISO that automatically installs to the internal disk # with minimal user interaction - similar to StartOS experience. # # Requires --source-ref and --input-manifest . # Inputs are verified before host/build operations. No live-node captures. # # Features: # - Pre-built root filesystem (no network needed during install) # - Auto-detects internal disk (skips USB boot drive) # - Automatic installation with progress display # - Boots directly to web UI after install # # Image versions: sourced from scripts/image-versions.sh (single source of truth). # All container image references MUST use the $*_IMAGE variables defined there. # # --- PLANNED REFACTOR (post-beta) --- # This script is ~1870 lines and should be split into a modular library. # Proposed structure: # image-recipe/ # build-auto-installer-iso.sh — Main orchestrator (config, CLI args, step sequencing) # lib/ # rootfs.sh — Step 1: Build root filesystem via Docker (~185 lines) # installer-env.sh — Step 2: Build minimal installer via debootstrap (~80 lines) # components.sh — Step 3: Add Archipelago components (binary, configs, web UI) (~120 lines) # container-images.sh — Step 3b: Bundle container images for offline install (~330 lines) # auto-install-script.sh — Step 4: Generate the embedded auto-install.sh (~615 lines) # boot-config.sh — Step 5: Configure live boot auto-start + overlay squashfs (~215 lines) # create-iso.sh — Step 6: Build final bootable ISO with xorriso/grub (~140 lines) # Each lib/ script exports functions; main script sources them and calls in sequence. # DO NOT split until tested on the build server — this is critical infrastructure. # --- # set -e # Explicit private-UAT input only. Never inherit this from sudo -E/environment: # signed wrappers do not pass this option and retain their existing byte gates. UAT_OCI="" UAT_KERNEL="" INPUT_MANIFEST="" SOURCE_REF="" while [ "$#" -gt 0 ]; do case "$1" in --input-manifest) [ "$#" -ge 2 ] && [ -z "$INPUT_MANIFEST" ] || exit 2; INPUT_MANIFEST="$2"; shift 2 ;; --source-ref) [ "$#" -ge 2 ] && [ -z "$SOURCE_REF" ] || exit 2; SOURCE_REF="$2"; shift 2 ;; --unsigned-uat-oci) [ "$#" -ge 2 ] && [ -z "$UAT_OCI" ] && [ -f "$2/BUNDLE.json" ] || exit 2 UAT_OCI="$2"; shift 2 ;; --uat-kernel) [ "$#" -ge 2 ] && [ -z "$UAT_KERNEL" ] && [ -f "$2" ] || exit 2 UAT_KERNEL="$2"; shift 2 ;; *) echo "Unsupported ISO builder option: $1" >&2; exit 2 ;; esac done if { [ -n "$UAT_OCI" ] && [ -z "$UAT_KERNEL" ]; } || { [ -z "$UAT_OCI" ] && [ -n "$UAT_KERNEL" ]; }; then echo 'Unsigned UAT requires both explicit OCI and exact kernel inputs' >&2 exit 2 fi # Source pinned image versions (single source of truth) SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" [ -f "$SCRIPT_DIR/../../scripts/image-versions.sh" ] && . "$SCRIPT_DIR/../../scripts/image-versions.sh" # Configuration DEV_SERVER="${DEV_SERVER:-archipelago@192.0.2.10}" BUILD_FROM_SOURCE="${BUILD_FROM_SOURCE:-0}" UNBUNDLED="${UNBUNDLED:-0}" ARCH="${ARCH:-x86_64}" UAT_KERNEL_SPEC="" if [ -n "$UAT_KERNEL" ]; then case "$ARCH" in x86_64|amd64) UAT_DEB_ARCH=amd64 ;; arm64|aarch64) UAT_DEB_ARCH=arm64 ;; *) exit 2 ;; esac UAT_KERNEL_SPEC=$(python3 "$SCRIPT_DIR/../../scripts/uat_kernel.py" validate "$UAT_KERNEL" --architecture "$UAT_DEB_ARCH") fi # Every build starts from explicitly reviewed input bytes and an immutable source. [ -n "$INPUT_MANIFEST" ] && [ -n "$SOURCE_REF" ] || { echo 'Required: --source-ref --input-manifest ' >&2; exit 2; } BUILD_VERSION=$(sed -n 's/^version = "\([^"]*\)"/\1/p' "$SCRIPT_DIR/../../core/archipelago/Cargo.toml" | head -1) GIT_SHORT=${SOURCE_REF:0:12} # Architecture-dependent variables case "$ARCH" in x86_64|amd64) ARCH="x86_64" DEB_ARCH="amd64" LINUX_IMAGE_PKG="linux-image-amd64" GRUB_EFI_PKG="grub-efi-amd64" GRUB_EFI_SIGNED_PKG="grub-efi-amd64-signed" SHIM_HELPERS_PKG="shim-helpers-amd64-signed" GRUB_PC_PKG="grub-pc-bin" GRUB_TARGET="x86_64-efi" GRUB_BIOS_TARGET="i386-pc" CONTAINER_PLATFORM="linux/amd64" LIB_DIR="x86_64-linux-gnu" ;; arm64|aarch64) ARCH="arm64" DEB_ARCH="arm64" LINUX_IMAGE_PKG="linux-image-arm64" GRUB_EFI_PKG="grub-efi-arm64" GRUB_EFI_SIGNED_PKG="grub-efi-arm64-signed" SHIM_HELPERS_PKG="shim-helpers-arm64-signed" GRUB_PC_PKG="" GRUB_TARGET="arm64-efi" GRUB_BIOS_TARGET="" CONTAINER_PLATFORM="linux/arm64" LIB_DIR="aarch64-linux-gnu" ;; *) echo "❌ Unsupported architecture: $ARCH (use x86_64 or arm64)" exit 1 ;; esac SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" if [ -n "$UAT_KERNEL_SPEC" ]; then LINUX_IMAGE_PKG="$UAT_KERNEL_SPEC"; fi WORK_DIR="$SCRIPT_DIR/build/auto-installer" OUTPUT_DIR="$SCRIPT_DIR/results" ROOTFS_DIR="$WORK_DIR/rootfs" INSTALLER_DIR="$WORK_DIR/installer" mkdir -p "$WORK_DIR" INPUT_STAGE=$(mktemp -d "$WORK_DIR/input-stage.XXXXXX") rmdir "$INPUT_STAGE" python3 "$SCRIPT_DIR/../../scripts/image_inputs.py" --manifest "$INPUT_MANIFEST" \ --source-ref "$SOURCE_REF" --repo "$SCRIPT_DIR/../.." --architecture "$DEB_ARCH" --stage "$INPUT_STAGE" mkdir "$INPUT_STAGE/source" tar -xf "$INPUT_STAGE/source.tar" -C "$INPUT_STAGE/source" image-recipe/host-policy BUILD_NUM=$(cat "$INPUT_STAGE/build-number") export SOURCE_DATE_EPOCH=$(cat "$INPUT_STAGE/source-date-epoch") echo "Build #$BUILD_NUM ($BUILD_VERSION, commit $SOURCE_REF)" if [ "$UNBUNDLED" = "1" ]; then echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Building Archipelago UNBUNDLED ISO (no pre-loaded apps) ║" echo "╚════════════════════════════════════════════════════════════════╝" else echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Building Archipelago Auto-Installer ISO (StartOS-like) ║" echo "╚════════════════════════════════════════════════════════════════╝" fi echo "" if [ "$BUILD_FROM_SOURCE" = "1" ]; then echo "📦 Mode: Building from SOURCE CODE" elif [ "$UNBUNDLED" = "1" ]; then echo "📦 Mode: UNBUNDLED (apps downloaded on-demand from Marketplace)" echo " Server: $DEV_SERVER (backend + web UI only)" else echo "📦 Mode: Capturing LIVE SERVER state" echo " Server: $DEV_SERVER" fi echo "🏗️ Architecture: $ARCH ($DEB_ARCH)" echo "" # Check for required tools check_tools() { local missing="" local can_install=false # Check if we can auto-install (running as root on Debian/Ubuntu) if [ "$EUID" -eq 0 ] && [ -f /etc/debian_version ]; then can_install=true fi # Check for docker or podman if command -v docker >/dev/null 2>&1; then CONTAINER_CMD="docker" elif command -v podman >/dev/null 2>&1; then CONTAINER_CMD="podman" else missing="$missing docker-or-podman" fi for tool in xorriso mksquashfs; do if ! command -v $tool >/dev/null 2>&1; then missing="$missing $tool" fi done # Check for isolinux MBR (needed for hybrid USB boot) if [ ! -f /usr/lib/ISOLINUX/isohdpfx.bin ] && [ ! -f /usr/share/syslinux/isohdpfx.bin ]; then missing="$missing isolinux" fi if [ -n "$missing" ]; then echo "Missing required tools:$missing" echo "Install the reviewed builder prerequisites before running this recipe." >&2 exit 1 fi # Re-check after potential installation if command -v docker >/dev/null 2>&1; then CONTAINER_CMD="docker" elif command -v podman >/dev/null 2>&1; then CONTAINER_CMD="podman" else echo "❌ Container runtime still not available after installation" exit 1 fi echo "Using container runtime: $CONTAINER_CMD" # Fix root podman D-Bus issue (sd-bus: Transport endpoint is not connected) # When running as sudo, systemd cgroup manager can't reach the user D-Bus session. if [ "$CONTAINER_CMD" = "podman" ] && [ "$(id -u)" = "0" ]; then if ! $CONTAINER_CMD run --rm docker.io/library/debian:trixie@sha256:9c6e381421d0f48d1b8133e573f33c185ee16cbf505eda9c4a8a4791b25ea8a6 true 2>/dev/null; then echo " Root podman D-Bus issue detected, using cgroupfs manager" CONTAINER_CMD="podman --cgroup-manager=cgroupfs" fi fi # Registry TLS verification is never disabled by this builder. } check_tools mkdir -p "$WORK_DIR" cp "$SCRIPT_DIR/../../scripts/kernel-security.py" "$WORK_DIR/kernel-security.py" cp "$SCRIPT_DIR/../../scripts/secure_boot.py" "$WORK_DIR/secure_boot.py" cp "$SCRIPT_DIR/../../scripts/uat_kernel.py" "$WORK_DIR/uat_kernel.py" cp "$SCRIPT_DIR/../configs/build-snapshot-sources.sh" "$WORK_DIR/build-snapshot-sources.sh" cp "$INPUT_STAGE/artifacts/fips.deb" "$INPUT_STAGE/artifacts/tailscale.deb" "$WORK_DIR/" if [ -n "$UAT_KERNEL" ]; then cp "$UAT_KERNEL" "$WORK_DIR/uat-kernel.json"; else : > "$WORK_DIR/uat-kernel.json"; fi mkdir -p "$OUTPUT_DIR" # ============================================================================= # STEP 1: Build complete root filesystem using Docker # ============================================================================= echo "📦 Step 1: Building root filesystem..." ROOTFS_TAR="$WORK_DIR/archipelago-rootfs.tar" ROOTFS_STAMP="$WORK_DIR/archipelago-rootfs.recipe.sha256" ROOTFS_DIGEST="$WORK_DIR/archipelago-rootfs.payload.sha256" # The cached rootfs must be invalidated when its recipe changes: a stale # archipelago-rootfs.tar on the build machine shipped ISOs with NO # wpasupplicant/iw/rfkill (WiFi dead on laptops) long after those packages # were added to the Dockerfile below — the cache condition never looked at # the recipe. Hash the rootfs-defining region of this script; any edit to it # forces a rebuild. `--rebuild` still forces one unconditionally. RECIPE_HASH=$( { sed -n '/^# STEP 1: Build complete root filesystem/,/^# STEP 2: Build minimal installer/p' "$0" cat "$SCRIPT_DIR/../configs/install-ngit.sh" cat "$WORK_DIR/kernel-security.py" cat "$WORK_DIR/secure_boot.py" cat "$WORK_DIR/uat_kernel.py" cat "$WORK_DIR/uat-kernel.json" cat "$INPUT_STAGE/inputs.json" cat "$WORK_DIR/build-snapshot-sources.sh" find "$INPUT_STAGE/source/image-recipe/host-policy" -type f ! -path "*/__pycache__/*" -print0 | sort -z | xargs -0 sha256sum } | sha256sum | cut -d' ' -f1 ) if [ ! -f "$ROOTFS_TAR" ] || [ "$(sha256sum "$ROOTFS_TAR" 2>/dev/null | cut -d' ' -f1)" != "$(cat "$ROOTFS_DIGEST" 2>/dev/null)" ] || [ "${1:-}" == "--rebuild" ] || [ "$(cat "$ROOTFS_STAMP" 2>/dev/null)" != "$RECIPE_HASH" ]; then echo " Using Docker to create Debian root filesystem..." # Create a Dockerfile for building the rootfs # The Dockerfile body is written with a QUOTED heredoc delimiter. # # It used to be unquoted, which meant the build shell performed command # substitution on the body: any backtick in a Dockerfile COMMENT was executed # on the build host and its output spliced into the Dockerfile. Six comments # did that, and one of them ran "systemctl start archipelago-fips.service" # against the build machine on every ISO build. The comment text was also # silently deleted from the generated Dockerfile. # # bash -n cannot see this class of bug — the script is syntactically perfect # either way — so quoting the delimiter is the fix, not vigilance about # backticks. tests/first-boot-secrets/run-tests.sh case 7 fails if the # delimiter is ever unquoted again, or if a substitution appears in the body. # # The whole body needs exactly four build-time values, all package names, and # they are interpolated explicitly by the printf between the two halves. cat > "$WORK_DIR/Dockerfile.rootfs" <<'DOCKERFILE_HEAD' # Exact OCI index and snapshot package indexes bind the rootfs build inputs. FROM docker.io/library/debian:trixie@sha256:9c6e381421d0f48d1b8133e573f33c185ee16cbf505eda9c4a8a4791b25ea8a6 ENV DEBIAN_FRONTEND=noninteractive COPY uat_kernel.py /usr/local/lib/archipelago/uat_kernel.py COPY uat-kernel.json /usr/local/lib/archipelago/uat-kernel.json # Preseed keyboard/console config to prevent console-setup.service failure RUN echo "keyboard-configuration keyboard-configuration/layoutcode string us" | debconf-set-selections && \ echo "keyboard-configuration keyboard-configuration/model select Generic 105-key PC" | debconf-set-selections && \ echo "console-setup console-setup/charmap47 select UTF-8" | debconf-set-selections && \ echo "console-setup console-setup/codeset47 select Uni2" | debconf-set-selections && \ echo "console-setup console-setup/fontface47 select Terminus" | debconf-set-selections && \ echo "console-setup console-setup/fontsize-fb47 select 16" | debconf-set-selections COPY build-snapshot-sources.sh /tmp/build-snapshot-sources.sh RUN sh /tmp/build-snapshot-sources.sh / # UAT policy precedes full-upgrade and any kernel install/recommendation. A fresh # authenticated index must contain the exact version/hash; no local-deb bypass. RUN if [ -s /usr/local/lib/archipelago/uat-kernel.json ]; then \ apt-get -o Acquire::ForceIPv4=true update && \ apt-get install -y --no-install-recommends python3 python3-apt && \ python3 /usr/local/lib/archipelago/uat_kernel.py prepare /usr/local/lib/archipelago/uat-kernel.json; fi # Install all packages we need including nginx, podman, tor, and openssl (for self-signed certs) RUN apt-get -o Acquire::ForceIPv4=true update && apt-get -o Acquire::ForceIPv4=true -y full-upgrade && apt-get -o Acquire::ForceIPv4=true install -y --no-install-recommends \ DOCKERFILE_HEAD # The ONLY build-time interpolation in the entire Dockerfile: the kernel and # GRUB package names, which vary by architecture and Debian suite. printf ' %s \\\n' \ "$LINUX_IMAGE_PKG" "$GRUB_EFI_PKG" "$GRUB_EFI_SIGNED_PKG" "$SHIM_HELPERS_PKG" "$GRUB_PC_PKG" \ >> "$WORK_DIR/Dockerfile.rootfs" cat >> "$WORK_DIR/Dockerfile.rootfs" <<'DOCKERFILE_TAIL' shim-signed \ sbsigntool \ systemd \ systemd-sysv \ dbus \ sudo \ network-manager \ wpasupplicant \ wireless-regdb \ iw \ rfkill \ polkitd \ openssh-server \ nginx \ avahi-daemon \ avahi-utils \ libnss-mdns \ podman \ catatonit \ uidmap \ slirp4netns \ passt \ aardvark-dns \ netavark \ nftables apparmor apparmor-utils \ fuse-overlayfs \ tor \ python3 \ python3-apt \ curl \ git \ tmux \ vim-tiny \ nano \ ca-certificates \ openssl \ chrony \ iputils-ping \ esptool \ python3-venv \ binutils \ libpython3.13 \ locales \ console-setup \ keyboard-configuration \ cryptsetup \ cryptsetup-initramfs \ e2fsprogs \ firmware-realtek \ firmware-iwlwifi \ firmware-misc-nonfree \ firmware-linux-nonfree \ firmware-intel-graphics \ firmware-amd-graphics \ intel-microcode \ amd64-microcode \ xorg \ xdotool \ chromium \ mesa-va-drivers \ intel-media-va-driver \ i965-va-driver \ vainfo \ pipewire \ pipewire-pulse \ pipewire-alsa \ wireplumber \ alsa-utils \ unclutter \ fonts-liberation \ fonts-noto-color-emoji \ xfonts-base \ plymouth \ plymouth-themes \ zstd \ socat \ python3 \ apache2-utils \ wireguard-tools \ acpid \ acpi-support-base \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* COPY kernel-security.py /usr/local/lib/archipelago/kernel-security.py COPY secure_boot.py /usr/local/lib/archipelago/secure_boot.py # CVE-2026-98432: fail the rootfs build if the signed Debian package floor # has not reached this security fix. A newer userspace does not patch a kernel. RUN apt-get update && \ if [ -s /usr/local/lib/archipelago/uat-kernel.json ]; then \ python3 /usr/local/lib/archipelago/uat_kernel.py prepare /usr/local/lib/archipelago/uat-kernel.json && \ KVER=$(python3 -c 'import json; print(json.load(open("/usr/local/lib/archipelago/uat-kernel.json"))["package"].removeprefix("linux-image-"))') && \ python3 /usr/local/lib/archipelago/kernel-security.py --record-provenance --image "$KVER" && \ python3 /usr/local/lib/archipelago/uat_kernel.py verify /usr/local/lib/archipelago/uat-kernel.json; \ else \ dpkg --compare-versions "$(dpkg-query -W -f='${Version}' linux-image-$(dpkg --print-architecture))" ge 6.12.113-1 && \ python3 /usr/local/lib/archipelago/kernel-security.py --record-provenance --image "$(ls /lib/modules/ | sort -V | tail -1)"; fi # Strip docs, man pages, and unused locales RUN find /usr/share/doc -depth -type f ! -name copyright -delete 2>/dev/null || true && \ find /usr/share/doc -empty -delete 2>/dev/null || true && \ rm -rf /usr/share/man /usr/share/info /usr/share/lintian /usr/share/linda && \ find /usr/share/locale -maxdepth 1 -mindepth 1 ! -name 'en_US' ! -name 'locale.alias' -exec rm -rf {} + 2>/dev/null || true # Exact reviewed package artifacts; dependencies resolve only from build snapshots. COPY tailscale.deb fips.deb /tmp/ RUN apt-get update && apt-get install -y --no-install-recommends /tmp/tailscale.deb /tmp/fips.deb && \ apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/tailscale.deb /tmp/fips.deb # Install the pinned Nostr Git runtime. The installer verifies the release # archive before copying ngit and git-remote-nostr into /usr/bin. COPY install-ngit.sh /tmp/install-ngit.sh RUN chmod 0755 /tmp/install-ngit.sh && \ /tmp/install-ngit.sh && \ rm /tmp/install-ngit.sh # Configure locale RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen # Password logins stay locked until owner setup chooses a password. Never bake # a reusable credential into an image; the local kiosk remains available. # audio group: PipeWire runs under the lingering user manager (no logind seat # session), so udev's seat ACLs on /dev/snd never apply — group access is the # only way the kiosk's audio can open the hardware. RUN useradd -m -s /bin/bash -G sudo,dialout,audio archipelago && \ passwd --lock archipelago && \ passwd --lock root # Privileged node operations must use the installed typed owners/scoped policy. # Never grant the network-facing daemon unrestricted passwordless root. # Fail the build if a login credential was introduced before owner setup. RUN awk -F: '($1 == "archipelago" || $1 == "root") { seen++; if ($2 !~ /^[!*]/) bad=1 } END { exit (seen != 2 || bad) }' /etc/shadow # Set hostname RUN echo "archipelago" > /etc/hostname # Configure SSH RUN mkdir -p /etc/ssh/sshd_config.d && \ printf '%s\n' 'PasswordAuthentication no' 'KbdInteractiveAuthentication no' 'PermitRootLogin no' \ > /etc/ssh/sshd_config.d/00-archipelago-hardening.conf # Configure nginx for Archipelago RUN rm -f /etc/nginx/sites-enabled/default COPY nginx-archipelago.conf /etc/nginx/sites-available/archipelago RUN ln -sf /etc/nginx/sites-available/archipelago /etc/nginx/sites-enabled/archipelago # Install nginx snippets (PWA config, HTTPS app proxies) COPY snippets/ /etc/nginx/snippets/ # The self-signed HTTPS keypair is NOT generated here (audit F-03). # # It used to be: this layer ran "openssl req" and baked one keypair into the # shared image, which meant every node flashed from one ISO — and everyone who # downloaded the ISO — held the same TLS private key. The strip layer at the # end of this Dockerfile would delete it again anyway, so generating it here # now only creates a SECOND piece of code that can mint a TLS key with its own # accounting. There is exactly one producer of this keypair, and it is # first-boot-secrets.sh, which retries and reports. # # The ssl directory is created so that producer's staging swap has somewhere # to land. RUN mkdir -p /etc/archipelago/ssl # Fail the BUILD if the rootfs cannot generate per-device secrets. # # The one realistic way first-boot generation fails on every retry is a missing # generator binary, and that failure is deterministic, not transient — retries # and reboots will never fix it. A node in the field must not be where we # discover it. openssl and openssh-server are both in the package list above # (and openssh-server hard-depends openssh-client, which ships ssh-keygen), so # today this assertion is cheap insurance rather than a fix. It earns its place # by turning a silent fleet-wide brick into a loud build failure the first time # anyone edits that package list. RUN set -e; \ for bin in /usr/bin/openssl /usr/bin/ssh-keygen; do \ if [ ! -x "$bin" ]; then \ echo "FATAL: $bin missing or not executable in the rootfs." >&2; \ echo "first-boot-secrets.sh cannot generate per-device SSH host keys" >&2; \ echo "or the TLS keypair without it, and that failure is permanent." >&2; \ echo "Restore openssl / openssh-server in the package list above." >&2; \ exit 1; \ fi; \ done; \ echo "first-boot secret generators present: openssl, ssh-keygen" # Create archipelago systemd service COPY archipelago.service /etc/systemd/system/archipelago.service COPY archipelago-doctor.service /etc/systemd/system/archipelago-doctor.service COPY archipelago-doctor.timer /etc/systemd/system/archipelago-doctor.timer COPY archipelago-tor-helper.service /etc/systemd/system/archipelago-tor-helper.service COPY archipelago-tor-helper.path /etc/systemd/system/archipelago-tor-helper.path COPY nostr-vpn.service /etc/systemd/system/nostr-vpn.service COPY archipelago-wg.service /etc/systemd/system/archipelago-wg.service COPY archipelago-wg-address.service /etc/systemd/system/archipelago-wg-address.service COPY archipelago-fips.service /etc/systemd/system/archipelago-fips.service COPY nostr-relay.service /etc/systemd/system/nostr-relay.service COPY nostr-relay-config.toml /etc/archipelago/nostr-relay-config.toml # WireGuard kernel module auto-load on boot RUN echo "wireguard" >> /etc/modules-load.d/wireguard.conf # Copy container doctor + reconcile scripts (referenced by services and the # OTA update RPC; the reconcile systemd timer is gone as of Step 8a, but the # script stays until Step 8b/c ports all manifests — update.rs still shells # out to it during package updates). RUN mkdir -p /home/archipelago/archy/scripts/lib COPY container-doctor.sh /home/archipelago/archy/scripts/container-doctor.sh COPY reconcile-containers.sh /home/archipelago/archy/scripts/reconcile-containers.sh COPY container-specs.sh /home/archipelago/archy/scripts/container-specs.sh COPY tor-helper.sh /opt/archipelago/scripts/tor-helper.sh COPY lib/ /home/archipelago/archy/scripts/lib/ RUN chmod +x /home/archipelago/archy/scripts/*.sh /home/archipelago/archy/scripts/lib/*.sh /opt/archipelago/scripts/*.sh && \ chown -R archipelago:archipelago /home/archipelago/archy # Enable cgroup delegation for rootless podman (CPU/memory limits require this) RUN mkdir -p /etc/systemd/system/user@.service.d && \ printf '[Service]\nDelegate=cpu cpuset io memory pids\n' > /etc/systemd/system/user@.service.d/delegate.conf # Allow unprivileged ping inside rootless containers RUN printf 'net.ipv4.ping_group_range=0 2147483647\n' > /etc/sysctl.d/90-podman-ping.conf # Archipelago's web UI manages Wi-Fi through the backend service, not a local # desktop seat. Allow the dedicated system user to control NetworkManager. RUN mkdir -p /etc/polkit-1/rules.d && \ printf '%s\n' \ 'polkit.addRule(function(action, subject) {' \ ' if (subject.user == "archipelago" && action.id.indexOf("org.freedesktop.NetworkManager.") == 0) {' \ ' return polkit.Result.YES;' \ ' }' \ '});' \ > /etc/polkit-1/rules.d/49-archipelago-networkmanager.rules && \ chmod 644 /etc/polkit-1/rules.d/49-archipelago-networkmanager.rules # kdump + rasdaemon (#144, docs/kdump-rasdaemon-design.md): crash dumps and # hardware-error capture on the host. Packages + config are baked in for fresh # installs; the binary's host_fixups module delivers the identical end state to # already-deployed nodes over OTA (idempotent no-op here once applied). RUN set -eu; \ apt-get update; \ apt-get install -y --no-install-recommends kdump-tools kexec-tools makedumpfile rasdaemon; \ apt-get clean; rm -rf /var/lib/apt/lists/*; \ CONF=/etc/default/kdump-tools; \ sed -i 's|^#\?USE_KDUMP=.*|USE_KDUMP="1"|' "$CONF"; \ grep -q '^KDUMP_COREDIR=' "$CONF" \ && sed -i 's|^KDUMP_COREDIR=.*|KDUMP_COREDIR="/var/crash"|' "$CONF" \ || printf '\nKDUMP_COREDIR="/var/crash"\n' >> "$CONF"; \ grep -q '^CORE_COLLECTOR=' "$CONF" \ && sed -i 's|^CORE_COLLECTOR=.*|CORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"|' "$CONF" \ || printf '\nCORE_COLLECTOR="makedumpfile -l --message-level 1 -d 31"\n' >> "$CONF"; \ printf '%s\n' \ '# Archipelago kdump policy (#144). A wedged kiosk is useless until someone' \ '# power-cycles it — capture the evidence, then reboot by itself. Dumps land in' \ '# /var/crash (see docs/kdump-rasdaemon-design.md); keep-2 pruning is done by' \ '# the host fixup pass, not a timer.' \ 'kernel.panic = 10' \ 'kernel.panic_on_oops = 1' \ 'kernel.hung_task_panic = 1' \ 'kernel.hardlockup_panic = 1' \ > /etc/sysctl.d/99-archipelago-kdump.conf # Enable services RUN systemctl enable NetworkManager || true && \ systemctl enable polkit || systemctl enable polkit.service || true && \ systemctl enable ssh || true && \ systemctl enable nginx || true && \ systemctl enable avahi-daemon || true && \ systemctl enable archipelago || true && \ systemctl enable tor || true && \ systemctl enable tailscaled || true && \ systemctl enable chrony || true && \ systemctl enable archipelago-doctor.timer || true && \ systemctl enable archipelago-tor-helper.path || true && \ systemctl enable nostr-relay || true && \ systemctl enable rasdaemon || true && \ systemctl enable kdump-tools || true # archipelago-fips.service + archipelago-wg.service + archipelago-wg-address.service # stay installed and enabled. They all use `ConditionPathExists=` on their # respective seed-derived key files, so on a fresh pre-onboarding boot # systemd quietly skips them with no [FAILED] in the MOTD. Once the user # completes the seed onboarding flow, archipelago writes the key files, # the archipelago backend calls `systemctl start archipelago-fips.service` # (see server.rs post-onboarding auto-activate block) and the WG setup # path runs `archipelago-wg setup` directly. No masking, no user-facing # "Activate" button — install → onboard → FIPS + WG are just running. RUN systemctl enable archipelago-fips.service || true # nostr-vpn is the legacy nostr-tunnel service — deprecated in favour of # the upstream FIPS daemon. It still crash-loops on boot if left enabled # (env file doesn't exist until onboarding) so we mask it outright. # `systemctl mask` alone doesn't stick because the real .service file is # already in place — explicit rm + /dev/null symlink is what sticks. RUN rm -f /etc/systemd/system/nostr-vpn.service && \ ln -sf /dev/null /etc/systemd/system/nostr-vpn.service # Remove policy-rc.d so services can start on first boot RUN rm -f /usr/sbin/policy-rc.d # Create directories (including Cloud storage for FileBrowser) RUN mkdir -p /var/lib/archipelago/data /var/lib/archipelago/config /var/lib/archipelago/containers /var/lib/archipelago/nostr-relay /var/lib/archipelago/nostr-vpn && \ mkdir -p /etc/archipelago && \ mkdir -p /opt/archipelago/bin /opt/archipelago/scripts /opt/archipelago/web-ui && \ mkdir -p /var/lib/archipelago/data/cloud/Documents /var/lib/archipelago/data/cloud/Photos /var/lib/archipelago/data/cloud/Music /var/lib/archipelago/data/cloud/Videos /var/lib/archipelago/data/cloud/Downloads && \ cp /etc/archipelago/nostr-relay-config.toml /var/lib/archipelago/nostr-relay/config.toml && \ chown -R archipelago:archipelago /var/lib/archipelago /opt/archipelago # Persist journalctl across reboots — without /var/log/journal systemd # journal uses tmpfs and everything before the last boot is lost. We # need the full history to diagnose first-boot / install / onboarding # issues after the fact. Size cap keeps it from eating the disk, and the # explicit rate limit stops a single chatty service (e.g. a container # spamming conmon->journald during Bitcoin IBD) from drowning the journal. # Keep this byte-identical to image-recipe/configs/journald-archipelago.conf — # the backend self-heals the same file onto deployed nodes (bootstrap.rs). RUN mkdir -p /var/log/journal && \ systemd-tmpfiles --create --prefix /var/log/journal 2>/dev/null || true && \ install -d -m 0755 /etc/systemd/journald.conf.d && \ printf '[Journal]\nStorage=persistent\nSystemMaxUse=500M\nRuntimeMaxUse=100M\nForwardToSyslog=no\nRateLimitIntervalSec=30s\nRateLimitBurst=10000\n' > /etc/systemd/journald.conf.d/10-archipelago-persistent.conf # Requalify after every package operation and intentional documentation stripping. RUN apt-get update && \ python3 /usr/local/lib/archipelago/kernel-security.py --record-provenance --image "$(basename "$(readlink /vmlinuz)" | sed 's/^vmlinuz-//')" && \ if [ -s /usr/local/lib/archipelago/uat-kernel.json ]; then \ python3 /usr/local/lib/archipelago/uat_kernel.py prepare /usr/local/lib/archipelago/uat-kernel.json && \ python3 /usr/local/lib/archipelago/uat_kernel.py verify /usr/local/lib/archipelago/uat-kernel.json; fi # Record exact signed EFI bytes from authenticated Debian archives before indexes disappear. RUN python3 /usr/local/lib/archipelago/secure_boot.py record --architecture "$(dpkg --print-architecture)" # Clean up RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # ─── Strip fleet-shared identity material (audit finding F-03) ────────────── # # This image is exported to a tar and extracted VERBATIM onto every disk # flashed from the resulting ISO, and the ISO is a published artefact. Anything # identity-shaped left in here is therefore held by every node AND by every # person who downloaded the ISO. # # NOTE: this heredoc is UNQUOTED, so backticks here are command substitution # and would run at build time. Never put backticks in these comments. # # The TLS keypair is no longer generated in this Dockerfile at all (see the # note where that layer used to be). What still gets baked without anyone # asking for it is Debian's openssh-server postinst, which generates # /etc/ssh/ssh_host_* at package install time — i.e. inside this container # build — plus /etc/machine-id, which systemd populates during the build and # which correlates every node flashed from one ISO. This layer removes both. # # archipelago-first-boot-secrets.service recreates all of it per device on # first boot, retrying on a timer until it succeeds. The point of removing it # HERE is to change what a generation failure costs: with the material # stripped, a failure degrades to "no key, the service refuses to start" # instead of "fleet-shared key, silently" — which is the whole of F-03. That # makes fail-closed structural rather than procedural. # # This must stay the LAST layer: anything that installs packages after it can # reintroduce host keys. The rm of the TLS keypair is kept as belt-and-braces # even though nothing in this build creates one any more — if a future layer # starts baking a cert, this catches it. Keep the /etc/archipelago/ssl # directory itself so the first-boot script's staging swap has somewhere to # land. RUN rm -f /etc/ssh/ssh_host_* && \ rm -f /etc/archipelago/ssl/archipelago.key /etc/archipelago/ssl/archipelago.crt && \ mkdir -p /etc/archipelago/ssl && \ : > /etc/machine-id && \ { [ -L /var/lib/dbus/machine-id ] || rm -f /var/lib/dbus/machine-id ; } && \ mkdir -p /opt/archipelago && \ printf 'F-03 identity strip: this rootfs was built with the identity-strip layer.\nRemoved:\n /etc/ssh/ssh_host_*\n /etc/archipelago/ssl/archipelago.key\n /etc/archipelago/ssl/archipelago.crt\nTruncated:\n /etc/machine-id\nRecreated per device by archipelago-first-boot-secrets.service on first boot.\n' > /opt/archipelago/rootfs-identity-stripped DOCKERFILE_TAIL # Copy nginx snippets for HTTPS (PWA, app proxies) if [ -d "$SCRIPT_DIR/../configs/snippets" ]; then mkdir -p "$WORK_DIR/snippets" cp "$SCRIPT_DIR/../configs/snippets/"*.conf "$WORK_DIR/snippets/" 2>/dev/null || true echo " Using nginx snippets from configs/snippets/" else mkdir -p "$WORK_DIR/snippets" echo " ⚠ No nginx snippets found, HTTPS features may not work" fi # Use nginx config from configs/ (includes app proxies for Nextcloud, Vaultwarden, etc.) if [ -f "$SCRIPT_DIR/../configs/nginx-archipelago.conf" ]; then cp "$SCRIPT_DIR/../configs/nginx-archipelago.conf" "$WORK_DIR/nginx-archipelago.conf" echo " Using nginx config from configs/nginx-archipelago.conf" else echo " ⚠ configs/nginx-archipelago.conf not found, using minimal config" cat > "$WORK_DIR/nginx-archipelago.conf" <<'NGINXCONF' server { listen 80; server_name _; root /opt/archipelago/web-ui; index index.html; location / { try_files $uri $uri/ /index.html; } location /archipelago/ { proxy_pass http://127.0.0.1:5678; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /rpc/ { proxy_pass http://127.0.0.1:5678; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; } location /ws { proxy_pass http://127.0.0.1:5678; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_read_timeout 86400s; } } NGINXCONF fi # Copy udev rule for mesh radio stable naming if [ -f "$SCRIPT_DIR/../configs/99-mesh-radio.rules" ]; then cp "$SCRIPT_DIR/../configs/99-mesh-radio.rules" "$WORK_DIR/99-mesh-radio.rules" echo " Using 99-mesh-radio.rules from configs/" fi # Legacy self-update units are masked by the offline D09 policy. # Copy container doctor timer + reconcile script (the reconcile systemd # timer is gone as of Step 8a — BootReconciler replaces it — but the # reconcile-containers.sh script stays, invoked by the OTA update RPC # until Step 8b/c ports all manifests to the Rust orchestrator). if [ -f "$SCRIPT_DIR/../configs/archipelago-doctor.service" ]; then cp "$SCRIPT_DIR/../configs/archipelago-doctor.service" "$WORK_DIR/archipelago-doctor.service" cp "$SCRIPT_DIR/../configs/archipelago-doctor.timer" "$WORK_DIR/archipelago-doctor.timer" # Copy the actual scripts the services / update RPC reference for s in container-doctor.sh reconcile-containers.sh container-specs.sh tor-helper.sh; do if [ -f "$SCRIPT_DIR/../../scripts/$s" ]; then cp "$SCRIPT_DIR/../../scripts/$s" "$WORK_DIR/$s" fi done # Copy shared script library (mem_limit etc.) if [ -d "$SCRIPT_DIR/../../scripts/lib" ]; then mkdir -p "$WORK_DIR/lib" cp "$SCRIPT_DIR/../../scripts/lib/"*.sh "$WORK_DIR/lib/" 2>/dev/null || true fi echo " Using container doctor timer from configs/" fi # Copy Tor helper path-activated service (allows backend to manage Tor as non-root) if [ -f "$SCRIPT_DIR/../configs/archipelago-tor-helper.service" ]; then cp "$SCRIPT_DIR/../configs/archipelago-tor-helper.service" "$WORK_DIR/archipelago-tor-helper.service" cp "$SCRIPT_DIR/../configs/archipelago-tor-helper.path" "$WORK_DIR/archipelago-tor-helper.path" echo " Using tor-helper path unit from configs/" fi # Copy NostrVPN system service (native mesh VPN, not a container) if [ -f "$SCRIPT_DIR/../configs/nostr-vpn.service" ]; then cp "$SCRIPT_DIR/../configs/nostr-vpn.service" "$WORK_DIR/nostr-vpn.service" echo " Using nostr-vpn.service from configs/" fi if [ -f "$SCRIPT_DIR/../configs/archipelago-wg.service" ]; then cp "$SCRIPT_DIR/../configs/archipelago-wg.service" "$WORK_DIR/archipelago-wg.service" echo " Using archipelago-wg.service from configs/" fi if [ -f "$SCRIPT_DIR/../configs/archipelago-wg-address.service" ]; then cp "$SCRIPT_DIR/../configs/archipelago-wg-address.service" "$WORK_DIR/archipelago-wg-address.service" echo " Using archipelago-wg-address.service from configs/" fi if [ -f "$SCRIPT_DIR/../configs/archipelago-fips.service" ]; then cp "$SCRIPT_DIR/../configs/archipelago-fips.service" "$WORK_DIR/archipelago-fips.service" echo " Using archipelago-fips.service from configs/" fi # Copy private Nostr relay service (native, for NostrVPN signaling) if [ -f "$SCRIPT_DIR/../configs/nostr-relay.service" ]; then cp "$SCRIPT_DIR/../configs/nostr-relay.service" "$WORK_DIR/nostr-relay.service" echo " Using nostr-relay.service from configs/" fi if [ -f "$SCRIPT_DIR/../configs/nostr-relay-config.toml" ]; then cp "$SCRIPT_DIR/../configs/nostr-relay-config.toml" "$WORK_DIR/nostr-relay-config.toml" echo " Using nostr-relay-config.toml from configs/" fi if [ -f "$SCRIPT_DIR/../configs/install-ngit.sh" ]; then cp "$SCRIPT_DIR/../configs/install-ngit.sh" "$WORK_DIR/install-ngit.sh" echo " Using pinned ngit installer from configs/" fi # Copy WireGuard helper script (privileged peer management) if [ -f "$SCRIPT_DIR/../../scripts/archipelago-wg" ]; then cp "$SCRIPT_DIR/../../scripts/archipelago-wg" "$WORK_DIR/archipelago-wg" echo " Using archipelago-wg helper from scripts/" fi # Use archipelago.service from configs/ (User=root for Podman container access) if [ -f "$SCRIPT_DIR/../configs/archipelago.service" ]; then cp "$SCRIPT_DIR/../configs/archipelago.service" "$WORK_DIR/archipelago.service" echo " Using archipelago.service from configs/" else cat > "$WORK_DIR/archipelago.service" <<'SYSTEMDSERVICE' [Unit] Description=Archipelago Backend After=network-online.target archipelago-setup-tor.service Wants=network-online.target [Service] Type=simple User=archipelago Environment="ARCHIPELAGO_BIND=127.0.0.1:5678" Environment="XDG_RUNTIME_DIR=/run/user/1000" ExecStartPre=/bin/bash -c 'mkdir -p /run/user/1000 && chown archipelago:archipelago /run/user/1000 && chmod 700 /run/user/1000' ExecStart=/usr/local/bin/archipelago Restart=on-failure RestartSec=5 ProtectHome=no [Install] WantedBy=multi-user.target SYSTEMDSERVICE fi echo " Building $CONTAINER_CMD image (this may take a few minutes)..." $CONTAINER_CMD build --no-cache --platform $CONTAINER_PLATFORM -t archipelago-rootfs -f "$WORK_DIR/Dockerfile.rootfs" "$WORK_DIR" echo " Exporting filesystem..." $CONTAINER_CMD rm -f archipelago-rootfs-tmp 2>/dev/null || true $CONTAINER_CMD create --platform $CONTAINER_PLATFORM --name archipelago-rootfs-tmp archipelago-rootfs $CONTAINER_CMD export archipelago-rootfs-tmp > "$ROOTFS_TAR" $CONTAINER_CMD rm archipelago-rootfs-tmp # Apply offline policy after all package/service build operations. POLICY_ROOT=$(mktemp -d "$WORK_DIR/policy-root.XXXXXX") tar --numeric-owner -xf "$ROOTFS_TAR" -C "$POLICY_ROOT" mkdir -p "$POLICY_ROOT/usr/lib/archipelago/host-policy" cp -a "$INPUT_STAGE/source/image-recipe/host-policy/." "$POLICY_ROOT/usr/lib/archipelago/host-policy/" python3 "$INPUT_STAGE/source/image-recipe/host-policy/provision.py" --root "$POLICY_ROOT" tar --numeric-owner -cf "$ROOTFS_TAR" -C "$POLICY_ROOT" . rm -rf "$POLICY_ROOT" sha256sum "$ROOTFS_TAR" | cut -d' ' -f1 > "$ROOTFS_DIGEST" echo "$RECIPE_HASH" > "$ROOTFS_STAMP" echo "✅ Root filesystem created: $(du -h "$ROOTFS_TAR" | cut -f1)" else echo "✅ Using cached root filesystem: $(du -h "$ROOTFS_TAR" | cut -f1)" fi if [ -n "$UAT_KERNEL" ]; then python3 "$WORK_DIR/uat_kernel.py" cache "$WORK_DIR/uat-kernel.json" --archive "$ROOTFS_TAR" fi # ============================================================================= # STEP 2: Build minimal installer environment (replaces Debian Live) # ============================================================================= echo "" echo "Step 2: Building minimal installer environment via debootstrap..." INSTALLER_ISO="$WORK_DIR/installer-iso" INSTALLER_SQUASHFS="$WORK_DIR/installer-squashfs" rm -rf "$INSTALLER_ISO" "$INSTALLER_SQUASHFS" mkdir -p "$INSTALLER_ISO/live" "$INSTALLER_ISO/archipelago" mkdir -p "$INSTALLER_ISO/boot/grub" "$INSTALLER_ISO/isolinux" mkdir -p "$INSTALLER_ISO/EFI/BOOT" # Build the installer filesystem inside a container # This creates: vmlinuz, initrd.img, filesystem.squashfs # NOTE: the installer-env script is written to a file and bind-mounted into the # container rather than passed via `bash -c '...'`. On some hosts, the inline # form somehow interferes with debootstrap's dpkg-deb|tar extraction (repro'd # on this box: bash -c fails at "Extracting apt...", bash /script.sh succeeds). _INSTALLER_ENV_SCRIPT="$WORK_DIR/_installer-env.sh" cat > "$_INSTALLER_ENV_SCRIPT" <<'INSTALLER_ENV_EOF' set -e # This build host (and its containers) blackhole IPv6: deb.debian.org # answers AAAA first, wget tries v6 with long timeouts, and debootstrap's # per-package fetch fails ("Couldn't download packages", repro'd twice on # 2026-08-07). Force v4 for every retrieval tool this script drives. APT_V4='-o Acquire::ForceIPv4=true' sh /output/build-snapshot-sources.sh / apt-get $APT_V4 update -qq apt-get $APT_V4 install -y -qq debootstrap squashfs-tools initramfs-tools dosfstools mtools python3 \ grub-efi-amd64-bin grub-pc-bin grub-common isolinux syslinux-common sbsigntool # wget gets its v4 pin AFTER its package is installed — editing /etc/wgetrc # beforehand makes dpkg's conffile prompt fatal on a non-interactive shell # ("end of file on stdin at conffile prompt", repro'd on build #189). echo 'inet4_only = on' >> /etc/wgetrc echo " [container] Running debootstrap --variant=minbase..." KERNEL_INCLUDE="linux-image-${DEB_ARCH}," KERNEL_INSTALL="linux-image-${DEB_ARCH}" if [ -s /output/uat-kernel.json ]; then # No generic metapackage first: it could leave a newer image selected later. KERNEL_INCLUDE="" KERNEL_INSTALL=$(python3 /output/uat_kernel.py validate /output/uat-kernel.json --architecture "$DEB_ARCH") fi # ifupdown + isc-dhcp-client added because live-boot's /init writes # /etc/network/interfaces on the target — without ifupdown, /etc/network/ # doesn't exist and the initramfs throws a non-fatal but noisy # "can't create /root/etc/network/interfaces: nonexistent directory". debootstrap --variant=minbase --arch=${DEB_ARCH} \ --include=systemd,systemd-sysv,udev,dbus,bash,coreutils,mount,util-linux,\ kmod,procps,iproute2,ca-certificates,gdisk,python3,\ cryptsetup,cryptsetup-initramfs,parted,dosfstools,e2fsprogs,\ ${KERNEL_INCLUDE}grub-efi-${DEB_ARCH},grub-efi-${DEB_ARCH}-signed,shim-signed,shim-helpers-${DEB_ARCH}-signed,sbsigntool,grub-pc-bin,\ ifupdown,isc-dhcp-client,\ wpasupplicant,wireless-regdb,iw,rfkill,\ pciutils,usbutils,less,nano \ trixie /installer http://snapshot.debian.org/archive/debian/20261109T224401Z/ # Install live-boot via chroot — debootstrap minbase resolver cannot handle it. # The chroot approach works (confirmed in CI run 90) — just needs proc/sys/dev mounts. echo " [container] Installing live-boot for squashfs root support..." cp /etc/resolv.conf /installer/etc/resolv.conf 2>/dev/null || true mount --bind /proc /installer/proc mount --bind /sys /installer/sys mount --bind /dev /installer/dev # Same v6-blackhole discipline inside the chroot (its apt reads the # chroot's own config, not the container's). sh /output/build-snapshot-sources.sh /installer chroot /installer apt-get -o Acquire::ForceIPv4=true update -qq mkdir -p /installer/usr/local/lib/archipelago cp /output/uat_kernel.py /output/uat-kernel.json /installer/usr/local/lib/archipelago/ if [ -s /output/uat-kernel.json ]; then chroot /installer apt-get install -y --no-install-recommends python3-apt chroot /installer python3 /usr/local/lib/archipelago/uat_kernel.py prepare /usr/local/lib/archipelago/uat-kernel.json fi chroot /installer apt-get -o Acquire::ForceIPv4=true -y -qq full-upgrade chroot /installer apt-get -o Acquire::ForceIPv4=true install -y --no-install-recommends live-boot live-boot-initramfs-tools "$KERNEL_INSTALL" python3-apt mkdir -p /installer/usr/local/lib/archipelago cp /output/kernel-security.py /installer/usr/local/lib/archipelago/kernel-security.py cp /output/secure_boot.py /installer/usr/local/lib/archipelago/secure_boot.py chroot /installer python3 /usr/local/lib/archipelago/secure_boot.py record --architecture "$DEB_ARCH" chroot /installer python3 /usr/local/lib/archipelago/kernel-security.py --installed --record-provenance chroot /installer apt-get clean umount /installer/dev 2>/dev/null || true umount /installer/sys 2>/dev/null || true umount /installer/proc 2>/dev/null || true # Verify live-boot hooks are in place (scripts/live is a FILE not a directory) if [ -e /installer/usr/share/initramfs-tools/scripts/live ]; then echo " [container] live-boot initramfs hooks: OK" else echo " [container] FATAL: live-boot hooks not found after install!" ls -la /installer/usr/share/initramfs-tools/scripts/ 2>/dev/null exit 1 fi echo " [container] Configuring installer environment..." # Set hostname echo "archipelago-installer" > /installer/etc/hostname # The installer console uses physical autologin, never a shared root password. chroot /installer passwd --lock root # Auto-login on tty1 mkdir -p /installer/etc/systemd/system/getty@tty1.service.d cat > /installer/etc/systemd/system/getty@tty1.service.d/autologin.conf < /installer/etc/profile.d/z99-archipelago-installer.sh </dev/null || exit 0 fi export INSTALLER_STARTED=1 sleep 1 clear echo "" echo -e "\033[38;5;208m ▄▀█ █▀▄ █▀▀ █ █ █ █▀█ █▀▀ █ ▄▀█ █▀▀ █▀█\033[0m" echo -e "\033[38;5;208m █▀█ █▀▄ █ █▀█ █ █▀▀ ██▀ █ █▀█ █ █ █ █\033[0m" echo -e "\033[38;5;208m ▀ ▀ ▀ ▀ ▀▀▀ ▀ ▀ ▀ ▀ ▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀ ▀▀▀\033[0m" echo -e " \033[38;5;130mbitcoin node os\033[0m" echo "" BOOT_MEDIA="" for dev in /run/live/medium /lib/live/mount/medium /run/archiso /cdrom /media/cdrom /mnt/iso; do if [ -f "\$dev/archipelago/auto-install.sh" ]; then BOOT_MEDIA="\$dev" break fi done # If standard mount points failed, actively find and mount the boot device if [ -z "\$BOOT_MEDIA" ]; then echo -e " \033[37mSearching for boot device...\033[0m" mkdir -p /run/archiso 2>/dev/null for blk in /dev/sr0 /dev/sd[a-z] /dev/sd[a-z][0-9] /dev/nvme[0-9]n[0-9]p[0-9]; do [ -b "\$blk" ] || continue mount -o ro "\$blk" /run/archiso 2>/dev/null || continue if [ -f /run/archiso/archipelago/auto-install.sh ]; then BOOT_MEDIA="/run/archiso" break fi umount /run/archiso 2>/dev/null done fi if [ -n "\$BOOT_MEDIA" ]; then echo -e " \033[37mFound installer at: \$BOOT_MEDIA\033[0m" echo "" echo -e " Press Enter to install | \033[1;37mCtrl+C\033[0m for shell" read -s bash "\$BOOT_MEDIA/archipelago/auto-install.sh" else echo -e " \033[37mInstaller not found on boot media.\033[0m" echo "" echo -e " \033[37mDebug info:\033[0m" ls -la /run/live/ 2>/dev/null || echo " /run/live/ does not exist" mount | grep -E "iso9660|squashfs|overlay" 2>/dev/null echo "" echo -e " \033[37mTry: mount /dev/sdX /mnt/iso && bash /mnt/iso/archipelago/auto-install.sh\033[0m" echo "" fi PROFILE chmod +x /installer/etc/profile.d/z99-archipelago-installer.sh # Custom initramfs hook: mount ISO boot media at /run/archiso mkdir -p /installer/etc/initramfs-tools/hooks cat > /installer/etc/initramfs-tools/hooks/archipelago </dev/null || true copy_exec /sbin/blkid manual_add_modules iso9660 vfat squashfs overlay HOOK chmod +x /installer/etc/initramfs-tools/hooks/archipelago mkdir -p /installer/etc/initramfs-tools/scripts/local-bottom cat > /installer/etc/initramfs-tools/scripts/local-bottom/archipelago-mount </dev/null || continue mount -o ro "\$dev" /run/archiso 2>/dev/null || continue if [ -d /run/archiso/archipelago ]; then log_end_msg 0 echo "Found Archipelago media on \$dev" exit 0 fi umount /run/archiso 2>/dev/null || true done log_end_msg 1 echo "Archipelago boot media not found (will retry from userspace)" INITSCRIPT chmod +x /installer/etc/initramfs-tools/scripts/local-bottom/archipelago-mount # Strip docs and man pages from installer rm -rf /installer/usr/share/man/* /installer/usr/share/doc/* rm -rf /installer/var/lib/apt/lists/* /installer/var/cache/apt/* # Extract kernel KVER=$(ls /installer/lib/modules/ | sort -V | tail -1) if [ -s /output/uat-kernel.json ]; then KVER=${KERNEL_INSTALL%%=*} KVER=${KVER#linux-image-} fi chroot /installer python3 /usr/local/lib/archipelago/kernel-security.py --image "$KVER" echo " [container] Kernel version: $KVER" cp /installer/boot/vmlinuz-$KVER /output/vmlinuz # Mount virtual filesystems for proper initramfs generation mount --bind /proc /installer/proc mount --bind /sys /installer/sys mount --bind /dev /installer/dev # Build initramfs with live-boot hooks + our custom hooks chroot /installer update-initramfs -c -k $KVER cp /installer/boot/initrd.img-$KVER /output/initrd.img if [ -s /output/uat-kernel.json ]; then chroot /installer python3 /usr/local/lib/archipelago/uat_kernel.py verify /usr/local/lib/archipelago/uat-kernel.json fi # Cleanup mounts umount /installer/dev 2>/dev/null || true umount /installer/sys 2>/dev/null || true umount /installer/proc 2>/dev/null || true # Create squashfs echo " [container] Creating installer squashfs..." mksquashfs /installer /output/filesystem.squashfs -comp xz -Xbcj x86 -noappend -quiet # Preserve the Debian shim -> signed GRUB -> signed kernel chain on the media. # Authentication was recorded from APT before its indexes were removed. The # helper refuses changed/unsigned EFI payloads and never generates an EFI binary. python3 /output/secure_boot.py stage --root /installer --esp /output/efi-tree \ --architecture "$DEB_ARCH" --label ARCHIPELAGO # Include both removable and Debian vendor paths; the bootstrap config searches # the ISO label and loads /boot/grub/grub.cfg from the ISO filesystem. dd if=/dev/zero of=/output/efi.img bs=1M count=20 2>/dev/null mkfs.vfat /output/efi.img >/dev/null mcopy -s -i /output/efi.img /output/efi-tree/EFI ::/ # Copy ISOLINUX files for legacy BIOS boot cp /usr/lib/ISOLINUX/isolinux.bin /output/isolinux.bin cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /output/ldlinux.c32 cp /usr/lib/syslinux/modules/bios/menu.c32 /output/menu.c32 2>/dev/null || true cp /usr/lib/syslinux/modules/bios/vesamenu.c32 /output/vesamenu.c32 2>/dev/null || true cp /usr/lib/syslinux/modules/bios/libutil.c32 /output/libutil.c32 2>/dev/null || true cp /usr/lib/syslinux/modules/bios/libcom32.c32 /output/libcom32.c32 2>/dev/null || true cp /usr/lib/ISOLINUX/isohdpfx.bin /output/isohdpfx.bin # Generate GRUB fonts for theme echo " [container] Generating GRUB fonts..." apt-get install -y -qq fonts-dejavu-core grub-common >/dev/null 2>&1 mkdir -p /output/grub-fonts grub-mkfont -s 12 -o /output/grub-fonts/dejavu_12.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf grub-mkfont -s 14 -o /output/grub-fonts/dejavu_14.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf grub-mkfont -s 16 -o /output/grub-fonts/dejavu_16.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf grub-mkfont -s 24 -o /output/grub-fonts/dejavu_24.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf echo " [container] Done!" INSTALLER_ENV_EOF $CONTAINER_CMD run --rm --privileged --platform $CONTAINER_PLATFORM \ -v "$WORK_DIR:/output" \ -v "$_INSTALLER_ENV_SCRIPT:/installer-env.sh:ro" \ -e DEB_ARCH="$DEB_ARCH" \ -e LIB_DIR="$LIB_DIR" \ docker.io/library/debian:trixie@sha256:9c6e381421d0f48d1b8133e573f33c185ee16cbf505eda9c4a8a4791b25ea8a6 bash /installer-env.sh # Verify artifacts for artifact in vmlinuz initrd.img filesystem.squashfs efi.img isolinux.bin isohdpfx.bin; do if [ ! -f "$WORK_DIR/$artifact" ]; then echo " FATAL: Missing build artifact: $artifact" exit 1 fi done # Place artifacts into ISO directory structure cp "$WORK_DIR/vmlinuz" "$INSTALLER_ISO/live/vmlinuz" cp "$WORK_DIR/initrd.img" "$INSTALLER_ISO/live/initrd.img" cp "$WORK_DIR/filesystem.squashfs" "$INSTALLER_ISO/live/filesystem.squashfs" cp -a "$WORK_DIR/efi-tree/EFI/." "$INSTALLER_ISO/EFI/" cp "$WORK_DIR/efi.img" "$INSTALLER_ISO/boot/grub/efi.img" cp "$WORK_DIR/isolinux.bin" "$INSTALLER_ISO/isolinux/isolinux.bin" cp "$WORK_DIR/ldlinux.c32" "$INSTALLER_ISO/isolinux/ldlinux.c32" cp "$WORK_DIR/menu.c32" "$INSTALLER_ISO/isolinux/menu.c32" 2>/dev/null || true cp "$WORK_DIR/vesamenu.c32" "$INSTALLER_ISO/isolinux/vesamenu.c32" 2>/dev/null || true cp "$WORK_DIR/libutil.c32" "$INSTALLER_ISO/isolinux/libutil.c32" 2>/dev/null || true cp "$WORK_DIR/libcom32.c32" "$INSTALLER_ISO/isolinux/libcom32.c32" 2>/dev/null || true # Install GRUB theme THEME_SRC="$SCRIPT_DIR/branding/grub-theme" THEME_DST="$INSTALLER_ISO/boot/grub/themes/archipelago" mkdir -p "$THEME_DST" if [ -f "$THEME_SRC/theme.txt" ]; then cp "$THEME_SRC/theme.txt" "$THEME_DST/" echo " Installed GRUB theme from branding/grub-theme/" fi # Install generated fonts if [ -d "$WORK_DIR/grub-fonts" ]; then cp "$WORK_DIR/grub-fonts/"*.pf2 "$THEME_DST/" # Also copy unicode font for GRUB to load cp "$WORK_DIR/grub-fonts/dejavu_16.pf2" "$INSTALLER_ISO/boot/grub/font.pf2" fi # Copy GRUB background image (static asset or generate if missing) GRUB_BG="$SCRIPT_DIR/branding/grub-theme/background.png" if [ -f "$GRUB_BG" ]; then cp "$GRUB_BG" "$THEME_DST/background.png" echo " Installed GRUB background" elif [ -f "$SCRIPT_DIR/branding/generate-grub-background.py" ]; then echo " Generating GRUB background..." python3 "$SCRIPT_DIR/branding/generate-grub-background.py" "$THEME_DST/background.png" 2>/dev/null || \ echo " WARNING: Could not generate GRUB background" fi echo " Installer squashfs: $(du -h "$INSTALLER_ISO/live/filesystem.squashfs" | cut -f1)" echo " Kernel: $(du -h "$INSTALLER_ISO/live/vmlinuz" | cut -f1)" echo " Initrd: $(du -h "$INSTALLER_ISO/live/initrd.img" | cut -f1)" echo " Step 2 complete (custom minimal base, no Debian Live)" # ============================================================================= # STEP 3: Add Archipelago components # ============================================================================= echo "" echo "📦 Step 3: Adding Archipelago components..." ARCH_DIR="$INSTALLER_ISO/archipelago" mkdir -p "$ARCH_DIR" mkdir -p "$ARCH_DIR/bin" mkdir -p "$ARCH_DIR/scripts" # Kept separate from container-images: its generic first-boot loader must never # import this private candidate into root's or the legacy shared default store. if [ -n "$UAT_OCI" ]; then mkdir -p "$ARCH_DIR/unsigned-uat-oci" cp -a "$UAT_OCI/." "$ARCH_DIR/unsigned-uat-oci/" fi # netavark + aardvark-dns are installed in the rootfs via Dockerfile.rootfs (Debian 13 packages). # Do NOT copy from the build host — the host may run a different glibc version. echo " netavark + aardvark-dns: included in rootfs (Debian 13 packages)" # Copy the pre-built rootfs echo " Including root filesystem..." cp "$ROOTFS_TAR" "$ARCH_DIR/rootfs.tar" # Ship the canonical systemd unit on the ISO. The rootfs tar is a cached # artifact that can predate unit fixes (B17: RequiresMountsFor on the data # volume — without it fresh installs boot-loop "[FAILED]" until the LUKS # mount lands), so the installer overwrites the rootfs copy with this one. mkdir -p "$ARCH_DIR/configs" cp "$SCRIPT_DIR/../configs/archipelago.service" "$ARCH_DIR/configs/archipelago.service" cp "$SCRIPT_DIR/../configs/prepare-terminal-workspace.sh" "$ARCH_DIR/configs/prepare-terminal-workspace.sh" echo " Using archipelago.service from configs/ (installer overrides rootfs copy)" # Copy only prequalified bytes selected by the manifest, never installed binaries. for name in archipelago archy-reticulum-daemon archy-rnodeconf archy-esptool nostr-rs-relay; do install -m 755 "$INPUT_STAGE/artifacts/$name" "$ARCH_DIR/bin/$name" done "$ARCH_DIR/bin/archy-esptool" --archy-self-test cp "$INPUT_STAGE/inputs.json" "$ARCH_DIR/image-inputs.json" cp "$INPUT_STAGE/source.tar" "$ARCH_DIR/source.tar" cp -a "$INPUT_STAGE/source/image-recipe/host-policy" "$ARCH_DIR/host-policy" # Copy WireGuard helper script if [ -f "$WORK_DIR/archipelago-wg" ]; then cp "$WORK_DIR/archipelago-wg" "$ARCH_DIR/bin/archipelago-wg" chmod +x "$ARCH_DIR/bin/archipelago-wg" echo " ✅ WireGuard helper script included" fi # Copy NostrVPN UI dashboard for nginx serving if [ -d "$SCRIPT_DIR/../../docker/nostr-vpn-ui" ]; then mkdir -p "$ARCH_DIR/web-ui/nostr-vpn" cp "$SCRIPT_DIR/../../docker/nostr-vpn-ui/index.html" "$ARCH_DIR/web-ui/nostr-vpn/" echo " ✅ NostrVPN UI dashboard included" fi # Native AIUI is part of the qualified dashboard graph; no standalone fallback. mkdir -p "$ARCH_DIR/web-ui" cp -a "$INPUT_STAGE/web-ui/." "$ARCH_DIR/web-ui/" # Copy app manifests if [ -d "$SCRIPT_DIR/../../apps" ]; then echo " Including app manifests..." python3 "$SCRIPT_DIR/../../scripts/public_app_policy.py" "$SCRIPT_DIR/../../apps" "$ARCH_DIR/apps" fi # Copy Plymouth theme files for installation on target PLYMOUTH_SRC="$SCRIPT_DIR/branding/plymouth-theme" if [ -d "$PLYMOUTH_SRC" ]; then mkdir -p "$ARCH_DIR/plymouth-theme" cp "$PLYMOUTH_SRC/"* "$ARCH_DIR/plymouth-theme/" echo " Included Plymouth theme" fi # ============================================================================= # STEP 3b: Bundle container images for offline installation # ============================================================================= echo "" # Hash-bound offline image archives, with no remote capture/tag pull/cache fallback. IMAGES_DIR="$ARCH_DIR/container-images" mkdir -p "$IMAGES_DIR" cp -a "$INPUT_STAGE/container-images/." "$IMAGES_DIR/" if [ "$UNBUNDLED" = "1" ]; then touch "$ARCH_DIR/.unbundled"; fi # Create first-boot service to load images into Podman echo " Creating first-boot image loader service..." cat > "$WORK_DIR/archipelago-load-images.service" <<'LOADSERVICE' [Unit] Description=Load Archipelago Container Images After=network.target podman.service ConditionPathExists=/opt/archipelago/container-images ConditionPathExists=!/var/lib/archipelago/.images-loaded [Service] Type=oneshot ExecStart=/opt/archipelago/scripts/load-container-images.sh ExecStartPost=/usr/bin/touch /var/lib/archipelago/.images-loaded RemainAfterExit=yes [Install] WantedBy=multi-user.target LOADSERVICE cat > "$WORK_DIR/load-container-images.sh" <<'LOADSCRIPT' #!/bin/bash # Load pre-bundled container images into Podman # # CRITICAL: all Archipelago containers run ROOTLESS as the archipelago user. # This script runs as root (systemd oneshot), so a plain `podman load` here # puts the images into root's storage where the rootless runtime can never # see them — containers then silently depend on registry pulls, and a fresh # install without internet gets no apps at all. Always load into the # archipelago user's storage. IMAGES_DIR="/opt/archipelago/container-images" LOG_FILE="/var/log/archipelago-images.log" echo "$(date): Starting container image load" >> "$LOG_FILE" if [ ! -d "$IMAGES_DIR" ]; then echo "$(date): No images directory found" >> "$LOG_FILE" exit 0 fi ARCH_UID=$(id -u archipelago) # Linger gives the archipelago user a runtime dir (/run/user/UID) at boot, # before any login — required for rootless podman. loginctl enable-linger archipelago 2>/dev/null || true for _ in $(seq 1 30); do [ -d "/run/user/$ARCH_UID" ] && break sleep 1 done PODMAN="runuser -u archipelago -- env XDG_RUNTIME_DIR=/run/user/$ARCH_UID podman" $PODMAN system migrate >> "$LOG_FILE" 2>&1 || true for tarfile in "$IMAGES_DIR"/*.tar "$IMAGES_DIR"/*.tar.zst; do if [ -f "$tarfile" ]; then echo "$(date): Loading $(basename "$tarfile")..." >> "$LOG_FILE" $PODMAN load -i "$tarfile" >> "$LOG_FILE" 2>&1 && \ echo "$(date): Successfully loaded $(basename "$tarfile")" >> "$LOG_FILE" || \ echo "$(date): Failed to load $(basename "$tarfile")" >> "$LOG_FILE" fi done # Ensure archy-net exists for mempool stack (db, api, frontend) $PODMAN network create archy-net 2>/dev/null || true echo "$(date): Container image load complete" >> "$LOG_FILE" echo "$(date): Available images:" >> "$LOG_FILE" $PODMAN images >> "$LOG_FILE" 2>&1 LOADSCRIPT chmod +x "$WORK_DIR/load-container-images.sh" # Copy scripts to ISO mkdir -p "$ARCH_DIR/scripts" cp "$WORK_DIR/load-container-images.sh" "$ARCH_DIR/scripts/" cp "$WORK_DIR/archipelago-load-images.service" "$ARCH_DIR/scripts/" # First-boot per-device secrets: the squashfs bakes one TLS key and one set # of SSH host keys at build time, so every device flashed from the same image # would share them. Regenerate both on the installed system's first boot, # before the network-facing services come up. echo " Creating first-boot secrets regeneration service..." cat > "$WORK_DIR/archipelago-first-boot-secrets.service" <<'SECRETSSERVICE' [Unit] Description=Regenerate per-device secrets (TLS key, SSH host keys) DefaultDependencies=no After=local-fs.target # No random-seed file is baked into the rootfs today (verified by the entropy # audit's C-4 tar listing), so this ordering is a no-op right now. It is here # so that if one is ever introduced, the pool is credited before this unit — # the first consumer of entropy on a freshly-flashed machine — draws from it. After=systemd-random-seed.service Before=ssh.service nginx.service archipelago.service # There is deliberately NO ConditionPathExists=!.secrets-regenerated here. # # It used to short-circuit the unit once the marker existed, which meant a node # that had completed generation could never be re-examined. That is fine while # the only question is "do the keys exist", and wrong as soon as the question # is "are they still trustworthy" — a cert minted under a wrong clock succeeds # at generation and is only detectable afterwards. Skipping the unit is exactly # how such a node stays broken forever. # # The script owns the decision instead: it exits within milliseconds when the # material is present and correctly dated. One place decides, and it is the # place that can see the whole picture. [Service] Type=oneshot ExecStart=/opt/archipelago/scripts/first-boot-secrets.sh ExecStartPre=/usr/local/bin/archipelago migrate-login-v1 RemainAfterExit=yes [Install] WantedBy=multi-user.target SECRETSSERVICE # Self-heal timer. Fail-closed governs SERVING (never present a key we did not # generate); this timer governs RECOVERING (never dead-end a node). # # Without it, a node whose generators failed all their in-boot retries would sit # with no SSH host key and no TLS key until somebody walked to it with a # keyboard. With it, a transient cause that later clears — a full disk that gets # freed, a pool that eventually seeds — repairs the node unattended. # # The service's own ConditionPathExists=! is what stops this: once the marker # exists, every subsequent trigger is a no-op that systemd records as success, # so the timer costs nothing on a healthy node and needs no separate teardown. # This uses systemd's own facilities on purpose; a sleep loop inside the script # would hold a oneshot open for hours and hide the failure from systemctl. cat > "$WORK_DIR/archipelago-first-boot-secrets.timer" <<'SECRETSTIMER' [Unit] Description=Retry per-device secret generation until it succeeds Documentation=man:archipelago-first-boot-secrets.service(8) [Timer] # First retry shortly after boot has settled — by then the disk, the entropy # pool and any late-mounting filesystem have had a chance to become healthy. OnBootSec=5min OnUnitActiveSec=15min AccuracySec=30s Unit=archipelago-first-boot-secrets.service [Install] WantedBy=timers.target SECRETSTIMER cat > "$WORK_DIR/first-boot-secrets.sh" <<'SECRETSSCRIPT' #!/bin/bash # Create this device's own TLS keypair and SSH host keys on first boot. # # ── FAIL CLOSED — read this before changing anything below (audit F-03) ── # # The rootfs tar is byte-identical on every node flashed from one ISO, and the # ISO is a published artefact. It therefore no longer carries any identity # material: the rootfs Dockerfile in STEP 1 of this builder strips the SSH # host keys, the TLS keypair and machine-id out of the shared image. THIS # SCRIPT IS THE ONLY THING THAT CREATES THEM. That is deliberate. # # SINGLE PRODUCER. gen_tls() below is the only code anywhere in the ISO build # that creates /etc/archipelago/ssl/archipelago.{key,crt}; gen_ssh() is the only # code that creates /etc/ssh/ssh_host_*. The Dockerfile no longer bakes a # keypair and the installer's old "ensure SSL cert exists" fallback is gone. # That is the actual lesson of F-03: the bug was never "a second attempt to # create a key exists", it was that failure was silent and the marker lied # about it. A second producer is dangerous precisely because it has its own # accounting — its own idea of success, its own (absent) retry policy, its own # (absent) failure record. One producer means one place that can fail, one # place that retries, one place that reports. # # FAIL CLOSED applies to SERVING: if generation fails, no key exists, so sshd # and the nginx TLS listener refuse to start. They never come up on a # placeholder, a zero-length file, or a key from anywhere else. gen_tls swaps # into place only after openssl has parsed both halves back, so a truncated or # corrupt artefact is never what a service reads. # # SELF-HEAL applies to RECOVERING, and it is a different thing: a failure must # never dead-end the node. Three attempts with backoff inside the boot, then # archipelago-first-boot-secrets.timer retries every 15 minutes, and every # subsequent boot retries too — all because the marker is never written on # failure. A transient cause that later clears (a full disk that gets freed, a # pool that eventually seeds) repairs the node with nobody at a console. On # success the script restarts whatever refused to start, so recovery is # complete rather than pending-a-reboot. # # The only failure that survives all of that is a deterministic one — a missing # generator binary — and the rootfs build asserts openssl and ssh-keygen are # present and executable, so the build fails rather than the fleet. # # What this replaces was worse in every direction: log a warning, set the # completion marker anyway, never retry, and run forever on the SSH host key and # TLS private key that every downloader of the ISO also holds — undetectable # host impersonation and transparent MITM of the web UI, on a node whose # operator has no idea. # # Testability seam: FIRST_BOOT_SECRETS_ROOT prefixes every absolute path. It is # unset in production — the expansion is empty and behaviour is identical to a # script with the paths hard-coded — and set to a temp dir by # tests/first-boot-secrets/run-tests.sh, which is what makes the fail-closed # property assertable instead of merely claimed. set -u ROOT="${FIRST_BOOT_SECRETS_ROOT:-}" # Waits between attempts at one generator. The attempt count is the number of # entries; the wait after the final attempt is skipped, because a failed last # attempt is terminal and there is nothing left to wait for. With the default # 3-entry list that means 3 attempts at t=0s, t=2s and t=10s, and the trailing # 20 is the ceiling that applies if the list is ever lengthened. Tests override # this with zeros so the suite does not sleep. BACKOFF="${FIRST_BOOT_SECRETS_BACKOFF:-2 8 20}" LOG="$ROOT/var/log/archipelago-first-boot-secrets.log" MARKER="$ROOT/var/lib/archipelago/.secrets-regenerated" FAILED="$ROOT/var/lib/archipelago/first-boot-secrets.failed" CONSOLE="$ROOT/dev/console" SSL_DIR="$ROOT/etc/archipelago/ssl" SSH_DIR="$ROOT/etc/ssh" # Clock plausibility window. A node cannot legitimately believe it is running # before this software existed, and one that thinks it is decades ahead is just # as broken. Used to decide whether the clock can be trusted to date a # certificate — see the CLOCK section below. CLOCK_FLOOR_EPOCH=1767225600 # 2026-01-01T00:00:00Z CLOCK_CEIL_EPOCH=2713910400 # 2056-01-01T00:00:00Z # How far back to date notBefore, so ordinary skew between this node and a # client cannot make a freshly minted cert "not yet valid". BACKDATE_SECONDS=86400 mkdir -p "$ROOT/var/lib/archipelago" "$ROOT/var/log" NODE_NAME=$(hostname 2>/dev/null || echo archipelago) log() { echo "$(date): $*" >> "$LOG"; } # Test seam, same idea as FIRST_BOOT_SECRETS_ROOT: unset in production this is # the real clock. A wrong clock is the whole subject of the CLOCK section and # cannot be exercised otherwise. now_epoch() { echo "${FIRST_BOOT_SECRETS_NOW:-$(date -u +%s)}"; } # A terminal failure must be impossible to miss: journal, console and stderr, # on top of the durable on-disk record. Every channel is guarded so that a # missing /dev/console (test root, or an early boot without one) cannot itself # make the failure path fail. shout() { log "$*" if command -v logger >/dev/null 2>&1; then logger -t archipelago-first-boot-secrets "$*" 2>/dev/null || true fi if [ -w "$CONSOLE" ]; then printf '%s\n' "$*" | tee -a "$CONSOLE" >/dev/null 2>&1 || true fi printf '%s\n' "$*" >&2 } # retry