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 backend bootstrap input silent on BusyBox hosts

pulse-triage[bot]624d3f09a3ce
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 50e9dc861d..38070ea137 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -15,6 +15,21 @@
## Purpose
+### Backend bootstrap preserves silent input on BusyBox hosts
+
+Setup, Proxmox and container bootstrap commands prefer standalone `stty`,
+otherwise the BusyBox `stty` applet. They distinguish absent terminals, missing
+or unsupported tools and failed snapshot/echo/restoration before installation.
+The privileged Bash child keeps the selected tool and complete saved terminal
+state through EXIT/HUP/INT/TERM cleanup. Overflow is drained while silent;
+empty, interrupted or oversized input never reaches the installer. The isolated
+POSIX root/sudo prefix emits that child once, without moving credentials into
+shell source, argv, environment or history. Existing complete-download,
+preflight, private-file, scope, profile, identity and TLS boundaries remain.
+`portable_bootstrap_test.go` exercises all three producers with real PTYs and
+BusyBox, full terminal restoration and closed privilege/download fixtures;
+it is not native appliance installation or recovery evidence.
+
### Unraid/QNAP removal retires exact boot entries and confirms watchdog quiescence
The Unix uninstall caller selects these platforms from their vendor/installed
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index dfab6e4712..18242e0140 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -20,6 +20,19 @@
## Purpose
+### Copied backend bootstrap commands have one portable private reader
+
+Existing setup artifact aliases and Proxmox/container command fields retain
+separate credential response fields. Their command text now selects standalone
+`stty` or, only when absent, BusyBox `stty`, with distinct fail-closed terminal,
+tool and mode diagnostics. One isolated root/sudo prefix emits the privileged
+reader once, preserving complete fetch/preflight and 0700/0600 path handoff.
+No route, payload key, issuance scope, TLS policy or install authority changes.
+`TestContract_PortablePrivateBootstrapPayloads` checks the serialized producer
+boundary; full configapi PTY/tool/privacy/caller tests exercise the commands.
+Browser acceptance must use the actual producer fields through their existing
+setup/agent consumers, not a frontend-file guard skip or fabricated commands.
+
### Patrol setup panel reuses existing AI endpoints
The Patrol page setup panel adds no endpoint or payload field. It calls
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index e621be5a19..917008ab8f 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -21,6 +21,18 @@
## Purpose
+### Portable installation input does not change recovery authority
+
+The backend setup/Proxmox/container copied-command reader can use BusyBox `stty`
+when standalone `stty` is absent. Tool or terminal-mode failures stop before
+installation; full same-tool restoration and silent overflow draining retain
+the private credential boundary. The shorter root/sudo dispatch adds no root
+profile, state/identity replacement, backup operation or incident-replay right.
+Reported QNAP installed boot/watchdog/removal/reinstall recovery remains a
+separate native outcome; source PTYs and publishing an incoming updater do
+not establish it. `portable_bootstrap_test.go` and the serialized API contract
+cover these producer boundaries without touching stored monitoring data.
+
### Patrol maintenance coverage adds no recovery execution
Patrol's operator-state projection now projects the active recurring
diff --git a/internal/api/configapi/config_handlers_setup_url_test.go b/internal/api/configapi/config_handlers_setup_url_test.go
index e5d5487a14..ba5ec2ab2c 100644
--- a/internal/api/configapi/config_handlers_setup_url_test.go
+++ b/internal/api/configapi/config_handlers_setup_url_test.go
@@ -91,7 +91,7 @@ func TestHandleSetupScriptURL(t *testing.T) {
}
quotedURL := posixShellQuote(url)
for _, candidate := range []string{command, commandWithoutEnv} {
- if !strings.Contains(candidate, "curl -fsSL "+quotedURL+` -o "$install_script"`) || strings.Contains(candidate, token) || !strings.Contains(candidate, "PULSE_SETUP_TOKEN_FILE=") || !strings.Contains(candidate, "sudo bash -c") {
+ if !strings.Contains(candidate, "curl -fsSL "+quotedURL+` -o "$install_script"`) || strings.Contains(candidate, token) || !strings.Contains(candidate, "PULSE_SETUP_TOKEN_FILE=") || !strings.Contains(candidate, `"$@" bash -c`) {
t.Error("setup command must download completely, prompt privately, and pass only the token file")
}
}
@@ -290,7 +290,7 @@ func TestHandleSetupScriptURL_PreservesConfiguredPublicURLSchemeOnLoopback(t *te
}
command, _ := response["command"].(string)
- if !strings.Contains(command, "curl -fsSL "+posixShellQuote(urlValue)+` -o "$install_script"`) || !strings.Contains(command, `sudo bash -c`) {
+ if !strings.Contains(command, "curl -fsSL "+posixShellQuote(urlValue)+` -o "$install_script"`) || !strings.Contains(command, `"$@" bash -c`) {
t.Fatalf("command = %q, want quoted setup-script URL", command)
}
}
diff --git a/internal/api/configapi/install_command.go b/internal/api/configapi/install_command.go
index 8c514f782e..7ac65f7ebd 100644
--- a/internal/api/configapi/install_command.go
+++ b/internal/api/configapi/install_command.go
@@ -84,17 +84,23 @@ func privateBootstrapCommand(scriptURL, curlFlags, preflight, run string, needsT
`token_dir=$(mktemp -d /tmp/pulse-agent-bootstrap.XXXXXX);`,
`token_file="$token_dir/token";`,
`unset pulse_token pulse_discard tty_state;`,
- `cleanup() { unset pulse_token pulse_discard; if [ -n "${tty_state:-}" ]; then stty "$tty_state" </dev/tty 2>/dev/null || :; fi; rm -f -- "$token_file"; rmdir -- "$token_dir"; };`,
+ `tty_control=();`,
+ `cleanup() { unset pulse_token pulse_discard; if [ -n "${tty_state:-}" ]; then "${tty_control[@]}" "$tty_state" </dev/tty 2>/dev/null || :; fi; rm -f -- "$token_file"; rmdir -- "$token_dir"; };`,
`trap cleanup EXIT; trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM;`,
// A normal canonical tty silently truncates long lines (4095 bytes on
// Linux). Bounded character input preserves valid input and detects
// overflow; keep echo off while draining the rest of an invalid line
// so it cannot become a second command in the caller's shell history.
- `if ! tty_state=$(stty -g </dev/tty); then echo "A terminal is required to enter the token. No installation was attempted." >&2; exit 1; fi;`,
- `stty -echo </dev/tty;`,
+ // NAS hosts may expose stty only as a BusyBox applet. Preserve the
+ // selected tool for full restoration; an unsafe mode never falls
+ // back to echoed input or another privilege/credential channel.
+ `if ! { : </dev/tty; } 2>/dev/null; then echo "A terminal is required to enter the token. Use a private token-file command instead. No installation was attempted." >&2; exit 1; fi;`,
+ `if command -v stty >/dev/null 2>&1; then tty_control=(stty); elif command -v busybox >/dev/null 2>&1; then tty_control=(busybox stty); else echo "Silent token input requires stty or BusyBox stty. Use a private token-file command instead. No installation was attempted." >&2; exit 1; fi;`,
+ `if ! tty_state=$("${tty_control[@]}" -g </dev/tty 2>/dev/null) || [ -z "$tty_state" ]; then echo "Cannot read terminal settings with stty or BusyBox stty. Use a private token-file command instead. No installation was attempted." >&2; exit 1; fi;`,
+ `if ! "${tty_control[@]}" -echo </dev/tty 2>/dev/null; then echo "Cannot disable terminal echo. No token was requested and no installation was attempted." >&2; exit 1; fi;`,
`if ! IFS= read -r -s -p `+posixShellQuote(prompt+" (paste at this prompt, not in the command): ")+` -n 4097 pulse_token </dev/tty; then echo "Token input was interrupted. No installation was attempted." >&2; exit 1; fi;`,
`if [ "${#pulse_token}" -gt 4096 ]; then while IFS= read -r -s -n 4097 pulse_discard </dev/tty && [ "${#pulse_discard}" -eq 4097 ]; do :; done; unset pulse_discard; fi;`,
- `stty "$tty_state" </dev/tty; unset tty_state;`,
+ `if ! "${tty_control[@]}" "$tty_state" </dev/tty 2>/dev/null; then echo "Cannot restore terminal settings. No installation was attempted." >&2; exit 1; fi; unset tty_state;`,
`printf '\n' >/dev/tty;`,
`if [ -z "$pulse_token" ] || [ "${#pulse_token}" -gt 4096 ]; then echo "A non-empty token of at most 4096 characters is required." >&2; exit 1; fi;`,
`printf %s "$pulse_token" > "$token_file"; unset pulse_token;`,
@@ -111,7 +117,10 @@ func privateBootstrapCommand(scriptURL, curlFlags, preflight, run string, needsT
`trap cleanup EXIT; trap 'exit 129' HUP; trap 'exit 130' INT; trap 'exit 143' TERM;`,
"curl " + curlFlags + " " + posixShellQuote(strings.TrimSpace(scriptURL)) + ` -o "$install_script";`,
preflight,
- `if [ "$(id -u)" -eq 0 ]; then ` + child + " else sudo " + child + " fi;",
+ // Expand the root/sudo prefix once, inside this isolated POSIX subshell.
+ // Duplicating the quoted reader can exceed a pasted line's tty budget.
+ `if [ "$(id -u)" -eq 0 ]; then set --; else set -- sudo; fi;`,
+ `"$@" ` + child,
")",
}, " ")
}
diff --git a/internal/api/configapi/install_command_test.go b/internal/api/configapi/install_command_test.go
index 0ed3e13afb..b7ea2811f1 100644
--- a/internal/api/configapi/install_command_test.go
+++ b/internal/api/configapi/install_command_test.go
@@ -197,7 +197,7 @@ func TestPrivateBootstrapKeepsSecretsOutOfCommands(t *testing.T) {
if strings.Contains(command, secret) || strings.ContainsAny(command, "\r\n") || strings.Contains(command, "PULSE_SETUP_TOKEN=") || strings.Contains(command, "--token '") || strings.Contains(command, "| bash") {
t.Fatal("copied command exposes a credential or executes a partial fetch")
}
- if !strings.Contains(command, "read -r -s -p") || !strings.Contains(command, "sudo bash -c") || !strings.Contains(command, " -o \"$install_script\"") {
+ if !strings.Contains(command, "read -r -s -p") || !strings.Contains(command, `"$@" bash -c`) || !strings.Contains(command, " -o \"$install_script\"") {
t.Fatal("missing private prompt, sudo or complete download")
}
})
diff --git a/internal/api/configapi/portable_bootstrap_test.go b/internal/api/configapi/portable_bootstrap_test.go
index c7d249bb44..093f329bcc 100644
--- a/internal/api/configapi/portable_bootstrap_test.go
+++ b/internal/api/configapi/portable_bootstrap_test.go
@@ -1,6 +1,7 @@
package configapi
import (
+ "encoding/base64"
"encoding/json"
"fmt"
"os"
@@ -270,3 +271,26 @@ func TestPrivateBootstrapSinglePrivilegedBody(t *testing.T) {
})
}
}
+
+// The browser uses these actual builder fields, never a handwritten command.
+// All credentials/endpoints here are inert synthetic values, not issued tokens.
+func TestPrivateBootstrapConsumerPayload(t *testing.T) {
+ const base = "http://127.0.0.1:5237"
+ payload := make(map[string]any)
+ for _, kind := range []string{"pve", "pbs"} {
+ token := strings.Repeat("a", 32)
+ payload[kind+"-setup"] = BuildSetupScriptInstallArtifact(base, kind, "https://"+kind+".example:"+map[string]string{"pve": "8006", "pbs": "8007"}[kind], base, false, token, 1900000000)
+ payload[kind+"-agent"] = map[string]string{
+ "command": BuildProxmoxAgentInstallCommand(AgentInstallCommandOptions{BaseURL: base, Token: strings.Repeat("b", 32), InstallType: kind, IncludeInstallType: true}),
+ "token": strings.Repeat("b", 32),
+ }
+ }
+ payload["container"] = map[string]string{"command": BuildContainerRuntimeAgentInstallCommand(base, strings.Repeat("c", 32), false), "token": strings.Repeat("c", 32)}
+ body, err := json.Marshal(payload)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if os.Getenv("PULSE_EMIT_BOOTSTRAP_CONSUMER") == "1" {
+ t.Logf("PRIVATE_BOOTSTRAP_PAYLOAD=%s", base64.StdEncoding.EncodeToString(body))
+ }
+}
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 4ac8f03ae7..588583c021 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -7546,7 +7546,7 @@ func TestContract_DiagnosticsDockerPrepareTokenInstallCommandUsesLifecycleTransp
if strings.Contains(got, "--disable-host") {
t.Fatalf("install command preserved stale disable-host flag: %s", got)
}
- if !strings.Contains(got, `sudo bash -c`) || !strings.Contains(got, `--token-file "$token_file"`) || !strings.Contains(got, "--preflight-only") {
+ if !strings.Contains(got, `"$@" bash -c`) || !strings.Contains(got, `--token-file "$token_file"`) || !strings.Contains(got, "--preflight-only") {
t.Fatal("install command missing private-token/preflight root-or-sudo boundary")
}
if strings.Contains(got, "token-123") || strings.Contains(got, "| bash") || strings.Contains(got, "| sudo") {
@@ -7579,7 +7579,7 @@ func TestContract_DiagnosticsDockerPrepareTokenPreservesExplicitWorkloadOnlyMode
func TestContract_SetupScriptURLCommandUsesFailFastQuotedTransport(t *testing.T) {
url := "https://pulse.example.com/api/setup-script?type=pve&host=pve1.local"
got := buildSetupScriptCommand(url, "token-123")
- for _, required := range []string{"curl -fsSL " + posixShellQuote(url) + ` -o "$install_script"`, "sudo bash -c", "PULSE_SETUP_TOKEN_FILE="} {
+ for _, required := range []string{"curl -fsSL " + posixShellQuote(url) + ` -o "$install_script"`, `"$@" bash -c`, "PULSE_SETUP_TOKEN_FILE="} {
if !strings.Contains(got, required) {
t.Fatalf("missing secure bootstrap fragment %s", required)
}
@@ -11141,7 +11141,7 @@ func TestContract_ProxmoxInstallCommandUsesPrivilegeEscalationWrapper(t *testing
if !strings.Contains(got, `if [ "$(id -u)" -eq 0 ]; then`) {
t.Fatalf("install command missing root-or-sudo wrapper: %s", got)
}
- if !strings.Contains(got, `sudo bash -c`) {
+ if !strings.Contains(got, `"$@" bash -c`) {
t.Fatalf("install command missing sudo fallback: %s", got)
}
if !strings.Contains(got, `token_dir=$(mktemp -d /tmp/pulse-agent-bootstrap.XXXXXX)`) {
@@ -27169,3 +27169,42 @@ func TestContract_DiagnosticsTLSGuidanceSurvivesSerialization(t *testing.T) {
})
}
}
+
+func TestContract_PortablePrivateBootstrapPayloads(t *testing.T) {
+ const token = "synthetic-portable-install-token"
+ artifact := configapi.BuildSetupScriptInstallArtifact("https://pulse.example", "pbs", "https://pbs.example:8007", "https://pulse.example", false, token, 1900000000)
+ payload := map[string]any{
+ "setup": artifact,
+ "proxmox": AgentInstallCommandResponse{Command: configapi.BuildProxmoxAgentInstallCommand(configapi.AgentInstallCommandOptions{BaseURL: "https://pulse.example", Token: token, InstallType: "pbs", IncludeInstallType: true}), Token: token},
+ "container": map[string]string{"command": buildContainerRuntimeAgentInstallCommand("https://pulse.example", token, false), "token": token},
+ }
+ encoded, err := json.Marshal(payload)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var wire map[string]map[string]any
+ if err := json.Unmarshal(encoded, &wire); err != nil {
+ t.Fatal(err)
+ }
+ for kind, fields := range wire {
+ command, ok := fields["command"].(string)
+ if !ok || strings.Contains(command, token) || strings.ContainsAny(command, "\r\n") || strings.Count(command, "bash -c ") != 1 {
+ t.Fatalf("%s wire command lost its single private body", kind)
+ }
+ for _, required := range []string{`"$@" bash -c`, "tty_control=(stty)", "tty_control=(busybox stty)", "Cannot restore terminal settings.", ` -o "$install_script"`} {
+ if !strings.Contains(command, required) {
+ t.Fatalf("%s wire command lost %s", kind, required)
+ }
+ }
+ credentialKey := "token"
+ if kind == "setup" {
+ credentialKey = "setupToken"
+ if fields["commandWithEnv"] != command || fields["commandWithoutEnv"] != command || fields["downloadURL"] != fields["url"] {
+ t.Fatal("setup artifact aliases or credential-free download changed")
+ }
+ }
+ if fields[credentialKey] != token {
+ t.Fatalf("%s lost its separate credential field", kind)
+ }
+ }
+}