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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Stage remote container installers before execution
pulse-triage[bot]468769bb2980
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.mdindex f2ad2f6176..d9be2d2735 100644--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md@@ -6241,6 +6241,15 @@ match that default by forwarding `--enable-docker --enable-host`; it may pointoperators who need workload-only behavior to the canonical installer'sexplicit `--enable-host=false` option, but must not choose that opt-out forthem.+When that wrapper has no adjacent canonical installer, it must download the+remote `install.sh` into an owned private temporary directory and admit a+successful, nonempty, syntactically valid Bash response before executing any+of it. A failed or truncated transfer, an empty response, or a trailing syntax+error must not execute an otherwise valid prefix. The local installer route,+literal argument forwarding, explicit TLS opt-out and installer exit status+remain intact; temporary download files are removed on ordinary completion or+failure. This is transfer/syntax admission, not a replacement for the canonical+installer's artifact signature checks or proof of installed recovery.That same update-runtime boundary now also owns bounded rollback retention anddisk-space fail-closed behavior for self-hosted app updates. `internal/updates/`must prune stale retained rollback snapshots, clear history references when andiff --git a/scripts/install-container-agent.sh b/scripts/install-container-agent.shindex 9d377c6f2c..5edef2d7d5 100755--- a/scripts/install-container-agent.sh+++ b/scripts/install-container-agent.sh@@ -112,4 +112,36 @@ if [[ "$INSECURE" == "true" ]]; thencurl_flags=(-kfsSL)fi-curl "${curl_flags[@]}" "$URL/install.sh" | bash -s -- "${forward_args[@]}"+# A pipe can execute an installer's first commands before curl discovers a+# truncated transfer. Admit the complete script before running any of it.+download_dir="$(mktemp -d "${TMPDIR:-/tmp}/pulse-container-installer.XXXXXX")" || {+ echo "[ERROR] Could not prepare a private installer download directory." >&2+ exit 1+}+download_file="$download_dir/install.sh"+cleanup_download() {+ local status=$?+ trap - EXIT+ if ! rm -f -- "$download_file" || ! rmdir -- "$download_dir"; then+ echo "[WARNING] Could not remove the temporary installer download." >&2+ fi+ exit "$status"+}+trap cleanup_download EXIT++# Keep downloaded code private even when the caller's umask is permissive.+if ! (umask 077; : > "$download_file"); then+ echo "[ERROR] Could not prepare the installer download file." >&2+ exit 1+fi+if ! curl "${curl_flags[@]}" --output "$download_file" -- "$URL/install.sh"; then+ echo "[ERROR] Could not download the complete install.sh; nothing was executed." >&2+ exit 1+fi+if [[ ! -s "$download_file" ]] || ! bash -n -- "$download_file" >/dev/null 2>&1; then+ echo "[ERROR] Downloaded install.sh is empty or invalid Bash; nothing was executed." >&2+ exit 1+fi++# Do not exec: the wrapper still owns cleanup and preserves the installer's exit.+bash -- "$download_file" "${forward_args[@]}"diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.goindex 5b788a1216..7c1bb7fe58 100644--- a/scripts/installtests/install_sh_test.go+++ b/scripts/installtests/install_sh_test.go@@ -45,6 +45,161 @@ func TestContainerAgentCompatibilityWrapperDefaultsToUnifiedHostAndDockerMonitor}}+func containerAgentWrapperCommand(t *testing.T, arguments ...string) (*exec.Cmd, string) {+ t.Helper()+ root := t.TempDir()+ scriptDir := filepath.Join(root, "scripts with spaces")+ temporaryDir := filepath.Join(root, "temporary files")+ for _, directory := range []string{scriptDir, temporaryDir} {+ if err := os.Mkdir(directory, 0o700); err != nil {+ t.Fatal(err)+ }+ }+ wrapper, err := os.ReadFile(repoFile("scripts", "install-container-agent.sh"))+ if err != nil {+ t.Fatal(err)+ }+ path := filepath.Join(scriptDir, "install-container-agent.sh")+ if err := os.WriteFile(path, wrapper, 0o700); err != nil {+ t.Fatal(err)+ }+ ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)+ t.Cleanup(cancel)+ cmd := exec.CommandContext(ctx, "bash", append([]string{path}, arguments...)...)+ cmd.Dir = root+ cmd.Env = append(os.Environ(), "TMPDIR="+temporaryDir,+ "CURL_HOME="+root, "NO_PROXY=*", "no_proxy=*",+ "WRAPPER_MARKER="+filepath.Join(root, "executed"),+ "WRAPPER_ARGS="+filepath.Join(root, "arguments"))+ return cmd, root+}++func assertContainerWrapperDownloadRemoved(t *testing.T, root string) {+ t.Helper()+ entries, err := os.ReadDir(filepath.Join(root, "temporary files"))+ if err != nil || len(entries) != 0 {+ t.Fatalf("temporary installer download remains: entries=%v err=%v", entries, err)+ }+}++func TestContainerAgentCompatibilityWrapperRejectsIncompleteDownloadBeforeExecution(t *testing.T) {+ const prefix = "printf touched > \"$WRAPPER_MARKER\"\n"+ for _, tc := range []struct {+ name, body, diagnostic string+ status, extraBytes int+ }{+ {"truncated", prefix, "Could not download the complete install.sh", http.StatusOK, 100},+ {"invalid-shell", prefix + "if then\n", "empty or invalid Bash", http.StatusOK, 0},+ {"empty", "", "empty or invalid Bash", http.StatusOK, 0},+ {"http-error", prefix, "Could not download the complete install.sh", http.StatusServiceUnavailable, 0},+ } {+ t.Run(tc.name, func(t *testing.T) {+ var requests atomic.Int32+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ requests.Add(1)+ if r.URL.Path != "/install.sh" {+ t.Errorf("unexpected installer URL %q", r.URL.Path)+ }+ w.Header().Set("Content-Length", strconv.Itoa(len(tc.body)+tc.extraBytes))+ w.WriteHeader(tc.status)+ _, _ = io.WriteString(w, tc.body)+ }))+ defer server.Close()+ cmd, root := containerAgentWrapperCommand(t, "--url", server.URL)+ output, err := cmd.CombinedOutput()+ if err == nil || !strings.Contains(string(output), tc.diagnostic) {+ t.Fatalf("inadmissible download was not rejected: %v\n%s", err, output)+ }+ if _, err := os.Stat(filepath.Join(root, "executed")); !os.IsNotExist(err) {+ t.Fatalf("download prefix executed or marker unavailable: %v", err)+ }+ if requests.Load() != 1 {+ t.Fatalf("download was replayed: %d requests", requests.Load())+ }+ assertContainerWrapperDownloadRemoved(t, root)+ })+ }+}++func TestContainerAgentCompatibilityWrapperPreservesRemoteArgumentsAndExit(t *testing.T) {+ const body = "printf touched > \"$WRAPPER_MARKER\"\nprintf '%s\\0' \"$@\" > \"$WRAPPER_ARGS\"\nexit 37\n"+ for _, uninstall := range []bool{false, true} {+ t.Run(fmt.Sprintf("uninstall=%t", uninstall), func(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {+ _, _ = io.WriteString(w, body)+ }))+ defer server.Close()+ arguments := []string{"--url", server.URL, "--token", "synthetic $; literal", "--interval", "7 s; literal"}+ expected := append([]string{}, arguments...)+ if uninstall {+ arguments = append(arguments, "--uninstall")+ expected = append(expected, "--uninstall")+ } else {+ expected = append(expected, "--enable-docker", "--enable-host")+ }+ cmd, root := containerAgentWrapperCommand(t, arguments...)+ output, err := cmd.CombinedOutput()+ var exit *exec.ExitError+ if !errors.As(err, &exit) || exit.ExitCode() != 37 {+ t.Fatalf("installer exit changed: %v\n%s", err, output)+ }+ actual, err := os.ReadFile(filepath.Join(root, "arguments"))+ if err != nil || string(actual) != strings.Join(expected, "\x00")+"\x00" {+ t.Fatalf("installer arguments changed: %q (%v)", actual, err)+ }+ assertContainerWrapperDownloadRemoved(t, root)+ })+ }+}++func TestContainerAgentCompatibilityWrapperRetainsExplicitTLSOptOut(t *testing.T) {+ server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {+ _, _ = io.WriteString(w, "printf '%s\\0' \"$@\" > \"$WRAPPER_ARGS\"\n")+ }))+ defer server.Close()+ for _, insecure := range []bool{false, true} {+ t.Run(fmt.Sprintf("insecure=%t", insecure), func(t *testing.T) {+ arguments := []string{"--url", server.URL}+ if insecure {+ arguments = append(arguments, "--insecure")+ }+ cmd, root := containerAgentWrapperCommand(t, arguments...)+ output, err := cmd.CombinedOutput()+ if (err == nil) != insecure {+ t.Fatalf("unexpected TLS admission: %v\n%s", err, output)+ }+ actual, readErr := os.ReadFile(filepath.Join(root, "arguments"))+ if insecure {+ expected := append(arguments, "--enable-docker", "--enable-host")+ if readErr != nil || string(actual) != strings.Join(expected, "\x00")+"\x00" {+ t.Fatalf("explicit insecure arguments changed: %q (%v)", actual, readErr)+ }+ } else if !os.IsNotExist(readErr) {+ t.Fatalf("untrusted TLS download executed: %q (%v)", actual, readErr)+ }+ assertContainerWrapperDownloadRemoved(t, root)+ })+ }+}++func TestContainerAgentCompatibilityWrapperPrefersAdjacentInstaller(t *testing.T) {+ cmd, root := containerAgentWrapperCommand(t, "--uninstall")+ local := filepath.Join(root, "scripts with spaces", "install.sh")+ if err := os.WriteFile(local, []byte("#!/bin/sh\nprintf '%s\\0' \"$@\" > \"$WRAPPER_ARGS\"\nexit 39\n"), 0o700); err != nil {+ t.Fatal(err)+ }+ output, err := cmd.CombinedOutput()+ var exit *exec.ExitError+ if !errors.As(err, &exit) || exit.ExitCode() != 39 {+ t.Fatalf("adjacent installer route changed: %v\n%s", err, output)+ }+ actual, err := os.ReadFile(filepath.Join(root, "arguments"))+ if err != nil || string(actual) != "--uninstall\x00" {+ t.Fatalf("adjacent installer arguments changed: %q (%v)", actual, err)+ }+ assertContainerWrapperDownloadRemoved(t, root)+}+func TestInstallSHAllowsMissingTokenForOptionalAuth(t *testing.T) {content, err := os.ReadFile(repoFile("scripts", "install.sh"))if err != nil {