Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Keep server installer inputs private and authenticated

pulse-triage[bot]843b8d82b6b4
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index c6ac6c653c..5d96e129fe 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -15,6 +15,37 @@
## Purpose
+### Private, authenticated server-installer inputs
+
+Release archive downloads and their signature sidecars stay inside the same
+owner-only `mktemp -d` directory, not an unreserved filename in shared `/tmp`.
+The archive basename retains exact release inference for local/LXC handoff.
+Normal completion, failed download/admission and failed readiness remove only
+the owned archive and sidecar and an empty parent. A deliberate `--archive`
+input and its sidecar are never treated as owned download scratch.
+
+The piped Proxmox bootstrap downloads its installer, signature and transport
+diagnostic inside a separate owner-only directory. It resolves one exact
+installer URL, requires the existing pinned-key verifier, and admits the
+complete installer and its matching signature before any container copy or
+execution. Missing tools, metadata, signature, failed transfer or failed
+verification stop that path. A caller-supplied local installer remains the
+existing deliberate local-source route, not a claimed signed download.
+
+The bootstrap's EXIT cleanup retains both owned input directories across
+copy failures and interruption; it neither deletes a caller's local files nor
+recursively erases unexpected scratch content. Existing archive re-verification,
+architecture/version admission, staging-before-stop, service-state recovery,
+timer consent and removal quiescence remain unchanged.
+
+`TestRootInstallTemporaryInputsRemainPrivateAndAuthenticated` runs actual
+staging, prefetch, download and whole-bootstrap functions with no-network and
+no-host-mutation doubles, real fixture SSH signatures, permissive/normal/private
+umasks, bad/missing signatures, failed transfers, allocation/readiness/admission/
+copy failures, interruption and caller-owned-file preservation. These are
+ordinary-user source controls, not root, native PVE/LXC or installed acceptance;
+complete exact-source CI and the existing safe native routes remain separate.
+
### Existing-installation menu actions require exact target and intent
The root server installer's existing-installation menu admits stable/preview
diff --git a/install.sh b/install.sh
index 60e68c8d51..93eb9c6fb9 100755
--- a/install.sh
+++ b/install.sh
@@ -1268,6 +1268,14 @@ cleanup_stale_sensor_proxy_mounts() {
}
create_lxc_container() {
+ # Only files created by this invocation belong to its EXIT cleanup. Local
+ # --archive inputs and a caller-supplied installer must remain untouched.
+ local container_script_temp_dir=""
+ local container_archive_source=""
+ local container_archive_dest=""
+ local container_archive_temp=false
+ local archive_requested=false
+ trap 'cleanup_container_install_inputs "${container_script_temp_dir:-}" "${container_archive_source:-}" "${container_archive_temp:-false}"' EXIT
CURRENT_INSTALL_CTID=""
CONTAINER_CREATED_FOR_CLEANUP=false
trap handle_install_interrupt INT TERM
@@ -2035,11 +2043,6 @@ create_lxc_container() {
cleanup_on_error
fi
- local container_archive_source=""
- local container_archive_dest=""
- local container_archive_temp=false
- local archive_requested=false
-
if [[ -n "$ARCHIVE_OVERRIDE" ]]; then
archive_requested=true
container_archive_source="$ARCHIVE_OVERRIDE"
@@ -2057,57 +2060,11 @@ create_lxc_container() {
print_info "Installing Pulse..."
# When piped through curl, $0 is "bash" not the script. Download fresh copy.
- local script_source="/tmp/pulse_install_$$.sh"
+ local script_source="$0"
if [[ "$0" == "bash" ]] || [[ ! -f "$0" ]]; then
- # We're being piped, download the script with retry logic
- local download_url=""
- if ! download_url=$(resolve_install_script_download_url); then
- print_error "Failed to determine installer download URL for the selected release channel"
- cleanup_on_error
- fi
- local download_success=false
- local download_error=""
- local max_retries=3
-
- for attempt in $(seq 1 $max_retries); do
- if [[ $attempt -gt 1 ]]; then
- print_info "Retrying download (attempt $attempt/$max_retries)..."
- sleep 2
- fi
-
- local curl_stderr="/tmp/curl_error_$$.txt"
- if command -v timeout >/dev/null 2>&1; then
- if timeout 30 curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" > "$script_source" 2>"$curl_stderr"; then
- download_success=true
- rm -f "$curl_stderr"
- break
- fi
- else
- if curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" > "$script_source" 2>"$curl_stderr"; then
- download_success=true
- rm -f "$curl_stderr"
- break
- fi
- fi
- download_error=$(cat "$curl_stderr" 2>/dev/null || echo "unknown error")
- rm -f "$curl_stderr"
- done
-
- if [[ "$download_success" != "true" ]]; then
- print_error "Failed to download install script after $max_retries attempts"
- print_error "URL: $download_url"
- if [[ -n "$download_error" ]]; then
- print_error "Error: $download_error"
- fi
- print_info ""
- print_info "Workaround: Download the script manually and run it locally:"
- print_info " curl -fsSL $download_url -o install.sh"
- print_info " bash install.sh"
+ if ! download_container_installer script_source container_script_temp_dir; then
cleanup_on_error
fi
- else
- # We have a local script file
- script_source="$0"
fi
# Copy this script to container and run it
@@ -2116,16 +2073,15 @@ create_lxc_container() {
cleanup_on_error
fi
- # Clean up temp file if we created one
- if [[ "$script_source" == "/tmp/pulse_install_"* ]]; then
- rm -f "$script_source"
- fi
+ cleanup_container_install_inputs "$container_script_temp_dir" "" false
+ container_script_temp_dir=""
if [[ -n "$container_archive_source" ]]; then
print_info "Copying Pulse release archive to container..."
if ! pct push $CTID "$container_archive_source" "$container_archive_dest" >/dev/null 2>&1; then
if [[ "$container_archive_temp" == "true" ]]; then
- rm -f "$container_archive_source" "${container_archive_source}.sshsig"
+ cleanup_temp_archive_path "$container_archive_source"
+ container_archive_temp=false
fi
if [[ "$archive_requested" == "true" ]]; then
print_error "Failed to copy Pulse release archive to container"
@@ -2141,14 +2097,16 @@ create_lxc_container() {
if [[ -f "${container_archive_source}.sshsig" ]]; then
if ! pct push $CTID "${container_archive_source}.sshsig" "${container_archive_dest}.sshsig" >/dev/null 2>&1; then
if [[ "$container_archive_temp" == "true" ]]; then
- rm -f "$container_archive_source" "${container_archive_source}.sshsig"
+ cleanup_temp_archive_path "$container_archive_source"
+ container_archive_temp=false
fi
print_error "Failed to copy Pulse release archive signature to container"
cleanup_on_error
fi
else
if [[ "$container_archive_temp" == "true" ]]; then
- rm -f "$container_archive_source"
+ cleanup_temp_archive_path "$container_archive_source"
+ container_archive_temp=false
fi
print_error "Pulse release archive signature missing alongside ${container_archive_source}"
cleanup_on_error
@@ -2157,7 +2115,8 @@ create_lxc_container() {
fi
if [[ "$container_archive_temp" == "true" ]]; then
- rm -f "$container_archive_source" "${container_archive_source}.sshsig"
+ cleanup_temp_archive_path "$container_archive_source"
+ container_archive_temp=false
fi
# Run installation with visible progress
@@ -3272,11 +3231,86 @@ validate_pulse_binary_architecture() {
create_temp_archive_path() {
local prefix="$1"
- local temp_base=""
+ local temp_dir=""
- temp_base=$(mktemp "${prefix}-XXXXXX") || return 1
- rm -f "$temp_base"
- printf '%s.tar.gz\n' "$temp_base"
+ # Reserving then unlinking a mktemp file does not reserve the .tar.gz or
+ # sidecar name. Keep both downloads inside one owner-only directory.
+ temp_dir=$(mktemp -d "${prefix}-XXXXXX") || return 1
+ printf '%s/%s.tar.gz\n' "$temp_dir" "${prefix##*/}"
+}
+
+cleanup_temp_archive_path() {
+ local archive_path="$1"
+ [[ -n "$archive_path" ]] || return 0
+ rm -f -- "$archive_path" "${archive_path}.sshsig"
+ # Delete only the two owned leaves and an empty parent, never a tree.
+ rmdir -- "$(dirname "$archive_path")" 2>/dev/null || true
+}
+
+cleanup_container_install_inputs() {
+ local script_dir="${1:-}" archive_path="${2:-}" archive_owned="${3:-false}"
+ if [[ -n "$script_dir" ]]; then
+ rm -f -- "$script_dir/install.sh" "$script_dir/install.sh.sshsig" "$script_dir/curl-error"
+ rmdir -- "$script_dir" 2>/dev/null || true
+ fi
+ if [[ "$archive_owned" == true ]]; then
+ cleanup_temp_archive_path "$archive_path"
+ fi
+}
+
+download_container_installer() {
+ local source_output="$1" directory_output="$2"
+ local download_url="" staging_dir="" staged_installer="" staged_signature=""
+ local download_success=false download_error="" attempt
+ local max_retries=3
+
+ if ! download_url=$(resolve_install_script_download_url); then
+ print_error "Failed to determine installer download URL for the selected release channel"
+ return 1
+ fi
+ if ! require_release_signature_verifier; then
+ print_error "Cannot verify the signed container installer"
+ return 1
+ fi
+ if ! staging_dir=$(mktemp -d /tmp/pulse-lxc-installer-XXXXXX); then
+ print_error "Could not prepare private container installer staging"
+ return 1
+ fi
+ # Return the owned directory before transport so the caller's EXIT trap
+ # can clean an interrupted download too. No path is returned for execution
+ # until both the complete transfer and the pinned signature are admitted.
+ printf -v "$directory_output" '%s' "$staging_dir"
+ staged_installer="$staging_dir/install.sh"
+ staged_signature="$staging_dir/install.sh.sshsig"
+ for attempt in $(seq 1 "$max_retries"); do
+ if [[ "$attempt" -gt 1 ]]; then
+ print_info "Retrying download (attempt $attempt/$max_retries)..."
+ sleep 2
+ fi
+ if command -v timeout >/dev/null 2>&1; then
+ if timeout 30 curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" > "$staged_installer" 2>"$staging_dir/curl-error"; then
+ download_success=true
+ break
+ fi
+ elif curl -fsSL --connect-timeout 10 --max-time 30 "$download_url" > "$staged_installer" 2>"$staging_dir/curl-error"; then
+ download_success=true
+ break
+ fi
+ download_error=$(cat "$staging_dir/curl-error" 2>/dev/null || true)
+ done
+ if [[ "$download_success" != true ]]; then
+ print_error "Failed to download install script after $max_retries attempts"
+ [[ -z "$download_error" ]] || print_error "Error: $download_error"
+ return 1
+ fi
+ if ! curl -fsSL --connect-timeout 10 --max-time 30 "${download_url}.sshsig" > "$staged_signature" 2>"$staging_dir/curl-error"; then
+ print_error "Failed to download container installer signature; refusing to copy or run the installer"
+ return 1
+ fi
+ if ! verify_release_signature "$staged_installer" "$staged_signature" "downloaded container installer"; then
+ return 1
+ fi
+ printf -v "$source_output" '%s' "$staged_installer"
}
resolve_target_release() {
@@ -3609,13 +3643,16 @@ download_pulse() {
}
archive_from_temp=true
if ! download_release_archive "$LATEST_RELEASE" "$pulse_arch" "$archive_path"; then
- rm -f "$archive_path"
+ cleanup_temp_archive_path "$archive_path"
exit 1
fi
expected_release="$LATEST_RELEASE"
fi
if ! run_upgrade_readiness_preflight "$CURRENT_VERSION" "$expected_release"; then
+ if [[ "$archive_from_temp" == true ]]; then
+ cleanup_temp_archive_path "$archive_path"
+ fi
exit 1
fi
@@ -3623,14 +3660,14 @@ download_pulse() {
# local signature/content/architecture/version failures leave Pulse up.
if ! install_pulse_archive "$archive_path" "$expected_release"; then
if [[ "$archive_from_temp" == "true" ]]; then
- rm -f "$archive_path" "${archive_path}.sshsig"
+ cleanup_temp_archive_path "$archive_path"
fi
exit 1
fi
rm -f "$BUILD_FROM_SOURCE_MARKER"
if [[ "$archive_from_temp" == "true" ]]; then
- rm -f "$archive_path" "${archive_path}.sshsig"
+ cleanup_temp_archive_path "$archive_path"
fi
fi # End of SKIP_DOWNLOAD check
}
@@ -3657,7 +3694,7 @@ prefetch_pulse_archive_for_container() {
return 1
}
if ! download_release_archive "$LATEST_RELEASE" "$pulse_arch" "$archive_path"; then
- rm -f "$archive_path"
+ cleanup_temp_archive_path "$archive_path"
return 1
fi
diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.go
index 5f453f10f9..4480416539 100644
--- a/scripts/installtests/install_sh_test.go
+++ b/scripts/installtests/install_sh_test.go
@@ -4527,6 +4527,19 @@ func TestRootInstallExistingMenuRequiresExactAutomaticIntent(t *testing.T) {
}
}
+// Execute the real staging and container-bootstrap functions with confined
+// transports/host commands and real fixture signatures, never a live LXC.
+func TestRootInstallTemporaryInputsRemainPrivateAndAuthenticated(t *testing.T) {
+ ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
+ defer cancel()
+ cmd := exec.CommandContext(ctx, "python3", repoFile("scripts", "tests", "test_server_installer_temporary_inputs.py"), "-v")
+ cmd.Env = append(os.Environ(), "PULSE_INSTALLER_UNDER_TEST="+repoFile("install.sh"))
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("installer private/authenticated temporary-input controls: %v\n%s", err, out)
+ }
+}
+
func TestRootInstallStableReleaseTagRejectsPrereleaseShapes(t *testing.T) {
script := `
` + extractRootInstallShellFunction(t, "is_stable_release_tag") + `
diff --git a/scripts/tests/test_server_installer_temporary_inputs.py b/scripts/tests/test_server_installer_temporary_inputs.py
new file mode 100644
index 0000000000..e54c6c3896
--- /dev/null
+++ b/scripts/tests/test_server_installer_temporary_inputs.py
@@ -0,0 +1,346 @@
+#!/usr/bin/env python3
+"""Actual installer staging functions, confined to ordinary-user fixtures.
+
+Transport and service boundaries are doubles; signature verification is real.
+Directory modes establish the staging boundary, not a native root/LXC proof.
+"""
+
+import os
+from pathlib import Path
+import stat
+import subprocess
+import tempfile
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[2]
+INSTALLER = Path(os.environ.get("PULSE_INSTALLER_UNDER_TEST", ROOT / "install.sh"))
+
+HARNESS = r'''
+source "$INSTALLER"
+print_info() { :; }
+print_success() { :; }
+print_warn() { printf '%s\n' "$*" >&2; }
+print_error() { printf '%s\n' "$*" >&2; }
+mktemp() {
+ [[ "$FAULT" != allocation ]] || return 1
+ local template="${@: -1}" created
+ local -a args=("$@")
+ args[${#args[@]}-1]="$FIXTURE/shared/${template##*/}"
+ created=$(command mktemp "${args[@]}") || return 1
+ printf '%s\n' "$created" >> "$FIXTURE/created"
+ if [[ -d "$created" ]]; then
+ stat -c '%a' "$created" >> "$FIXTURE/directory-modes"
+ fi
+ printf '%s\n' "$created"
+}
+timeout() { shift; "$@"; }
+sleep() { :; }
+curl() {
+ local url="${@: -1}"
+ printf '%s\n' "$url" >> "$FIXTURE/transport"
+ case "$url" in
+ https://github.com/rcourtman/Pulse/releases/download/v6.6.0/install.sh)
+ cat "$FIXTURE/installer-input" || return 1
+ [[ "$FAULT" != script_interrupt ]] || kill -TERM "$$"
+ [[ "$FAULT" != script_transport ]] ;;
+ https://github.com/rcourtman/Pulse/releases/download/v6.6.0/install.sh.sshsig)
+ cat "$FIXTURE/installer-input.sig" || return 1
+ [[ "$FAULT" != signature_transport ]] ;;
+ *) return 97 ;;
+ esac
+}
+resolve_install_script_download_url() {
+ [[ "$FAULT" != metadata ]] || return 1
+ echo https://github.com/rcourtman/Pulse/releases/download/v6.6.0/install.sh
+}
+PINNED_RELEASE_SSH_PUBLIC_KEY=$(cat "$FIXTURE/signing-key.pub")
+if [[ "$FAULT" == verifier ]]; then
+ command() {
+ [[ "$*" != '-v ssh-keygen' ]] || return 1
+ builtin command "$@"
+ }
+fi
+INSTALL_DIR="$FIXTURE/install"
+BUILD_FROM_SOURCE_MARKER="$INSTALL_DIR/BUILD_FROM_SOURCE"
+CURRENT_VERSION=v6.5.0
+LATEST_RELEASE=v6.6.0
+detect_pulse_architecture() { echo amd64; }
+ensure_update_disk_headroom() { return 0; }
+resolve_target_release() { :; }
+download_release_archive() {
+ printf '%s\n' "$3" > "$FIXTURE/archive-path"
+ printf 'archive fixture' > "$3"
+ printf 'signature fixture' > "${3}.sshsig"
+ [[ "$FAULT" != archive_transport ]]
+}
+run_upgrade_readiness_preflight() { [[ "$FAULT" != readiness ]]; }
+install_pulse_archive() {
+ echo INSTALL >> "$FIXTURE/calls"
+ [[ "$FAULT" != archive_admission ]]
+}
+# Exercise the complete production bootstrap too; no pct, package, service,
+# registration, bridge or guest command below can reach a real host/guest.
+print_header() { :; }
+cleanup_stale_sensor_proxy_mounts() { :; }
+safe_read_with_default() { printf -v "$2" '%s' "$3"; }
+detect_network_bridges() { echo vmbr0; }
+ip() { printf 'default via 198.51.100.1 dev vmbr0\n'; }
+ensure_debian_template() { DEBIAN_TEMPLATE=fixture.tar.zst; }
+pvesh() { echo 600; }
+qm() { return 1; }
+pvesm() { printf 'Name Type Status Total Used Available\nlocal dir active 99999999 1 99999998\n'; }
+pveam() { printf 'NAME SIZE\nlocal:vztmpl/fixture.tar.zst 1\n'; }
+auto_register_pve_node() { :; }
+wait_for_pulse_ready() { :; }
+pct() {
+ case "$1" in
+ create|start|stop|destroy) return 0 ;;
+ push)
+ printf 'PUSH=%s\n' "$4" >> "$FIXTURE/calls"
+ [[ -f "$3" ]] || return 1
+ [[ "$FAULT" != script_copy || "$4" != /tmp/install.sh ]] || return 1
+ if [[ "$4" == /tmp/install.sh ]]; then
+ cp "$3" "$FIXTURE/copied-script"
+ fi
+ return 0 ;;
+ exec)
+ if [[ "$*" == *'hostname -I'* ]]; then
+ echo 198.51.100.2
+ elif [[ "$*" == *'bash /tmp/install.sh'* ]]; then
+ echo EXECUTE >> "$FIXTURE/calls"
+ fi
+ return 0 ;;
+ *) return 97 ;;
+ esac
+}
+umask "$MASK"
+case "$FLOW" in
+ reserve)
+ path=$(create_temp_archive_path "$FIXTURE/shared/pulse-v6.6.0-linux-amd64")
+ printf '%s\n' "$path" > "$FIXTURE/archive-path"
+ infer_release_from_archive_name "$path" > "$FIXTURE/inferred"
+ ;;
+ cleanup)
+ path=$(create_temp_archive_path "$FIXTURE/shared/pulse-v6.6.0-linux-amd64")
+ printf '%s\n' "$path" > "$FIXTURE/archive-path"
+ printf archive > "$path"
+ printf signature > "${path}.sshsig"
+ [[ "$FAULT" != extra_file ]] || touch "$(dirname "$path")/unowned"
+ cleanup_temp_archive_path "$path"
+ ;;
+ download) download_pulse ;;
+ override)
+ ARCHIVE_OVERRIDE="$FIXTURE/pulse-v6.6.0-linux-amd64.tar.gz"
+ FORCE_VERSION=v6.6.0
+ download_pulse
+ ;;
+ prefetch)
+ prefetched=""
+ prefetch_pulse_archive_for_container prefetched
+ printf '%s\n' "$prefetched" > "$FIXTURE/returned"
+ ;;
+ bootstrap)
+ script_source=""
+ container_script_temp_dir=""
+ trap 'cleanup_container_install_inputs "${container_script_temp_dir:-}" "" false' EXIT
+ download_container_installer script_source container_script_temp_dir
+ printf '%s\n' "$script_source" > "$FIXTURE/returned"
+ cp "$script_source" "$FIXTURE/copied-script"
+ ;;
+ interrupted_bootstrap)
+ script_source=""
+ container_script_temp_dir=""
+ trap 'cleanup_container_install_inputs "${container_script_temp_dir:-}" "" false' EXIT
+ trap 'exit 143' TERM
+ download_container_installer script_source container_script_temp_dir
+ kill -TERM "$$"
+ ;;
+ container_cleanup)
+ container_archive_source=""
+ prefetch_pulse_archive_for_container container_archive_source
+ script_source=""
+ container_script_temp_dir=""
+ trap 'cleanup_container_install_inputs "${container_script_temp_dir:-}" "$container_archive_source" true' EXIT
+ download_container_installer script_source container_script_temp_dir
+ exit 42
+ ;;
+ connected_container) create_lxc_container ;;
+ local_container)
+ ARCHIVE_OVERRIDE="$FIXTURE/pulse-v6.6.0-linux-amd64.tar.gz"
+ create_lxc_container
+ ;;
+esac
+'''
+
+
+class ServerInstallerTemporaryInputsTest(unittest.TestCase):
+ def exercise(self, flow, fault="", mask="000"):
+ with tempfile.TemporaryDirectory() as temporary:
+ fixture = Path(temporary)
+ (fixture / "shared").mkdir(mode=0o777)
+ (fixture / "shared").chmod(0o1777)
+ (fixture / "install").mkdir()
+ (fixture / "install/BUILD_FROM_SOURCE").write_text("old marker")
+ (fixture / "installer-input").write_text("#!/bin/bash\n# inert signed fixture\n")
+ key = fixture / "signing-key"
+ subprocess.run(["ssh-keygen", "-q", "-t", "ed25519", "-N", "", "-f", str(key)],
+ check=True, capture_output=True)
+ subprocess.run(["ssh-keygen", "-q", "-Y", "sign", "-f", str(key),
+ "-n", "pulse-install", str(fixture / "installer-input")],
+ check=True, capture_output=True)
+ if fault == "bad_signature":
+ (fixture / "installer-input").write_text("unsigned changed fixture\n")
+ if fault == "missing_signature":
+ (fixture / "installer-input.sig").unlink()
+ override = fixture / "pulse-v6.6.0-linux-amd64.tar.gz"
+ override.write_bytes(b"caller archive")
+ Path(str(override) + ".sshsig").write_bytes(b"caller signature")
+ env = {**os.environ, "INSTALLER": str(INSTALLER), "FIXTURE": str(fixture),
+ "FLOW": flow, "FAULT": fault, "MASK": mask}
+ command = ["bash", "-c", HARNESS]
+ if flow == "local_container":
+ command.append(str(fixture / "installer-input"))
+ result = subprocess.run(command, env=env, text=True,
+ capture_output=True, timeout=15)
+ observed = {}
+ for name in ("archive-path", "returned", "inferred", "calls", "transport", "directory-modes"):
+ p = fixture / name
+ observed[name] = p.read_text().splitlines() if p.exists() else []
+ archive_path = Path(observed["archive-path"][0]) if observed["archive-path"] else None
+ observed["archive_parent_is_private"] = bool(archive_path and archive_path.parent != fixture / "shared"
+ and archive_path.parent.is_dir() and stat.S_IMODE(archive_path.parent.stat().st_mode) == 0o700)
+ observed["shared_entries"] = sorted(p.name for p in (fixture / "shared").iterdir())
+ observed["unowned"] = sorted(str(p.relative_to(fixture / "shared"))
+ for p in (fixture / "shared").rglob("unowned"))
+ observed["copied"] = (fixture / "copied-script").read_bytes() if (fixture / "copied-script").exists() else None
+ observed["caller-script"] = (fixture / "installer-input").read_bytes() if (fixture / "installer-input").exists() else None
+ observed["override"] = (override.read_bytes(), Path(str(override) + ".sshsig").read_bytes())
+ return result, observed
+
+ def test_archive_and_sidecar_reserve_a_private_parent(self):
+ for mask in ("000", "022", "077"):
+ with self.subTest(umask=mask):
+ r, o = self.exercise("reserve", mask=mask)
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertTrue(o["archive_parent_is_private"], o)
+ self.assertEqual(o["inferred"], ["v6.6.0"])
+
+ def test_allocation_failure_cannot_return_an_unreserved_path(self):
+ r, o = self.exercise("reserve", "allocation")
+ self.assertNotEqual(r.returncode, 0)
+ self.assertEqual(o["archive-path"], [])
+ self.assertEqual(o["shared_entries"], [])
+ self.assertEqual(o["directory-modes"], [])
+
+ def test_cleanup_removes_archive_sidecar_and_owned_empty_directory(self):
+ r, o = self.exercise("cleanup")
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_bootstrap_staging_is_private_even_with_a_permissive_umask(self):
+ for mask in ("000", "022", "077"):
+ with self.subTest(umask=mask):
+ r, o = self.exercise("bootstrap", mask=mask)
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertEqual(o["directory-modes"], ["700"])
+
+ def test_cleanup_never_recursively_erases_an_unexpected_file(self):
+ r, o = self.exercise("cleanup", "extra_file")
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertEqual(len(o["unowned"]), 1, o)
+
+ def test_download_success_and_each_failure_clean_owned_inputs(self):
+ for fault in ("", "archive_transport", "readiness", "archive_admission", "allocation"):
+ with self.subTest(fault=fault):
+ r, o = self.exercise("download", fault)
+ self.assertEqual(r.returncode, 1 if fault else 0, r.stderr)
+ self.assertEqual(o["shared_entries"], [], o)
+ self.assertEqual(o["calls"], ["INSTALL"] if fault in ("", "archive_admission") else [])
+
+ def test_explicit_archive_and_sidecar_are_never_owned_or_deleted(self):
+ for fault in ("", "readiness", "archive_admission"):
+ with self.subTest(fault=fault):
+ r, o = self.exercise("override", fault)
+ self.assertEqual(r.returncode, 1 if fault else 0, r.stderr)
+ self.assertEqual(o["override"], (b"caller archive", b"caller signature"))
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_prefetch_retains_private_archive_until_handoff(self):
+ r, o = self.exercise("prefetch")
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertTrue(o["archive_parent_is_private"], o)
+ self.assertEqual(o["returned"], o["archive-path"])
+
+ def test_prefetch_failure_releases_its_private_inputs(self):
+ r, o = self.exercise("prefetch", "archive_transport")
+ self.assertNotEqual(r.returncode, 0)
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_bootstrap_checks_real_signature_before_copy(self):
+ r, o = self.exercise("bootstrap")
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertEqual(o["copied"], b"#!/bin/bash\n# inert signed fixture\n")
+ self.assertEqual(o["caller-script"], b"#!/bin/bash\n# inert signed fixture\n")
+ self.assertEqual(o["transport"], [
+ "https://github.com/rcourtman/Pulse/releases/download/v6.6.0/install.sh",
+ "https://github.com/rcourtman/Pulse/releases/download/v6.6.0/install.sh.sshsig"])
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_bootstrap_fails_closed_and_cleans_every_owned_input(self):
+ for fault in ("metadata", "verifier", "allocation", "script_transport",
+ "signature_transport", "missing_signature", "bad_signature"):
+ with self.subTest(fault=fault):
+ r, o = self.exercise("bootstrap", fault)
+ self.assertNotEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertIsNone(o["copied"])
+ self.assertEqual(o["shared_entries"], [], o)
+ if fault in ("metadata", "verifier", "allocation"):
+ self.assertEqual(o["transport"], [])
+
+ def test_interrupted_bootstrap_cleans_inputs_without_a_copy(self):
+ r, o = self.exercise("interrupted_bootstrap")
+ self.assertEqual(r.returncode, 143, r.stderr)
+ self.assertIsNone(o["copied"])
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_container_failure_cleans_both_owned_staging_directories(self):
+ r, o = self.exercise("container_cleanup")
+ self.assertEqual(r.returncode, 42, r.stderr)
+ self.assertEqual(o["shared_entries"], [], o)
+
+ def test_production_container_bootstrap_copies_only_the_verified_installer(self):
+ r, o = self.exercise("connected_container")
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertEqual(o["copied"], b"#!/bin/bash\n# inert signed fixture\n")
+ self.assertIn("EXECUTE", o["calls"])
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_production_container_never_copies_invalid_or_unavailable_signed_input(self):
+ for fault in ("bad_signature", "script_transport", "signature_transport", "missing_signature", "script_interrupt"):
+ with self.subTest(fault=fault):
+ r, o = self.exercise("connected_container", fault)
+ self.assertEqual(r.returncode, 1, r.stdout + r.stderr)
+ self.assertIsNone(o["copied"])
+ self.assertNotIn("EXECUTE", o["calls"])
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_production_container_failed_script_copy_cleans_prefetched_inputs_too(self):
+ r, o = self.exercise("connected_container", "script_copy")
+ self.assertEqual(r.returncode, 1, r.stdout + r.stderr)
+ self.assertIsNone(o["copied"])
+ self.assertNotIn("EXECUTE", o["calls"])
+ self.assertEqual(o["shared_entries"], [])
+
+ def test_production_local_installer_and_archive_remain_caller_owned(self):
+ r, o = self.exercise("local_container")
+ self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
+ self.assertEqual(o["transport"], [])
+ self.assertEqual(o["override"], (b"caller archive", b"caller signature"))
+ self.assertEqual(o["copied"], b"#!/bin/bash\n# inert signed fixture\n")
+ self.assertEqual(o["caller-script"], b"#!/bin/bash\n# inert signed fixture\n")
+ self.assertEqual(o["shared_entries"], [])
+
+
+if __name__ == "__main__":
+ unittest.main()