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.

Fix agent download preflight redirects (#1696)

rcourtman837ce5710654
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 3bef267635..60c6faa767 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -5136,7 +5136,10 @@ For Unix-family host installs, that same seamless installer contract requires
the copied command to fetch the shared installer into an ephemeral directory,
run `install.sh --preflight-only` before privilege escalation, and fail before
`sudo` if the selected Pulse URL or exact `/download/pulse-agent?arch=...`
-artifact is unavailable or missing checksum metadata. Token-bearing copied
+artifact is unavailable or missing checksum metadata. Preflight must follow
+redirects to the final Pulse download response before reading that metadata so
+reverse-proxied and canonicalized public URLs do not fail on an intermediate
+redirect that never served an agent binary. Token-bearing copied
commands must pass the credential to the installer through an ephemeral
`--token-file` and clean it up with the downloaded installer script, so the
installed service never receives a raw `--token` argument.
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index e620ebfd81..4bc4387a76 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -3050,7 +3050,10 @@ For Unix-family copied host installs, the deployment-owned shell installer must
support preflight before privilege escalation: `--preflight-only` may run
without root, must check both `/api/health` and the exact
`/download/pulse-agent?arch=...` artifact for checksum metadata, and must fail
-before installation if the server cannot provide that binary.
+before installation if the server cannot provide that binary. Both checks must
+follow redirects to the operator's final Pulse origin before deciding
+reachability or inspecting checksum metadata; an HTTP redirect accepted as a
+successful transport response is not the agent artifact contract.
A server may only hand out an agent binary that carries its own agent version.
Local agent artifacts are build outputs that nothing refreshes on their own, so
they go stale silently, and staleness is not cosmetic: the installer renders its
diff --git a/scripts/install.sh b/scripts/install.sh
index 26c867c77f..101bb4033d 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -204,6 +204,32 @@ url_encode() {
fi
printf '%s' "$output"
}
+final_response_header_value() {
+ local headers_path="$1"
+ local header_name="$2"
+
+ awk -v header_name="$header_name" '
+ BEGIN {
+ prefix = tolower(header_name) ":"
+ value = ""
+ }
+ /^HTTP\// {
+ value = ""
+ next
+ }
+ {
+ line = $0
+ sub(/\r$/, "", line)
+ if (substr(tolower(line), 1, length(prefix)) == prefix) {
+ value = substr(line, length(prefix) + 1)
+ sub(/^[[:space:]]+/, "", value)
+ }
+ }
+ END {
+ print value
+ }
+ ' "$headers_path" 2>/dev/null
+}
fail() {
local code="${2:-1}"
if [[ "$OUTPUT_FORMAT" == "json" ]]; then
@@ -3485,7 +3511,7 @@ if [[ "$PREFLIGHT_ONLY" == "true" ]]; then
# Check 4: Pulse URL reachability and agent binary availability
if [[ -n "$PULSE_URL" ]]; then
- CURL_TEST_ARGS=(-sf --connect-timeout 5 -o /dev/null)
+ CURL_TEST_ARGS=(-sfL --connect-timeout 5 -o /dev/null)
if [[ "$INSECURE" == "true" ]]; then CURL_TEST_ARGS+=(-k); fi
if [[ -n "$CURL_CA_BUNDLE" ]]; then CURL_TEST_ARGS+=(--cacert "$CURL_CA_BUNDLE"); fi
if curl "${CURL_TEST_ARGS[@]}" "${PULSE_URL}/api/health"; then
@@ -3497,13 +3523,13 @@ if [[ "$PREFLIGHT_ONLY" == "true" ]]; then
PREFLIGHT_HEADERS=$(mktemp)
TMP_FILES+=("$PREFLIGHT_HEADERS")
- CURL_DOWNLOAD_CHECK_ARGS=(-fsSI --connect-timeout 5 --max-time 30 -D "$PREFLIGHT_HEADERS" -o /dev/null)
+ CURL_DOWNLOAD_CHECK_ARGS=(-fsSIL --connect-timeout 5 --max-time 30 -D "$PREFLIGHT_HEADERS" -o /dev/null)
if [[ "$INSECURE" == "true" ]]; then CURL_DOWNLOAD_CHECK_ARGS+=(-k); fi
if [[ -n "$CURL_CA_BUNDLE" ]]; then CURL_DOWNLOAD_CHECK_ARGS+=(--cacert "$CURL_CA_BUNDLE"); fi
DOWNLOAD_CHECK_URL="${PULSE_URL}/download/${BINARY_NAME}?arch=${PF_ARCH_PARAM}"
if curl "${CURL_DOWNLOAD_CHECK_ARGS[@]}" "$DOWNLOAD_CHECK_URL"; then
- PREFLIGHT_EXPECTED_SHA=$(grep -i '^X-Checksum-Sha256:' "$PREFLIGHT_HEADERS" 2>/dev/null | tr -d '\r' | awk '{print $2}' || true)
+ PREFLIGHT_EXPECTED_SHA=$(final_response_header_value "$PREFLIGHT_HEADERS" "X-Checksum-Sha256" || true)
if [[ -n "$PREFLIGHT_EXPECTED_SHA" ]]; then
json_event "preflight" "agent_download_available" "Agent binary available for ${PF_ARCH_PARAM}"
else
@@ -3629,8 +3655,8 @@ fi
# Release metadata verification
EXPECTED_SHA=""
SSH_SIGNATURE_HEADER=""
-EXPECTED_SHA=$(grep -i '^X-Checksum-Sha256:' "$TMP_HEADERS" 2>/dev/null | tr -d '\r' | awk '{print $2}' || true)
-SSH_SIGNATURE_HEADER=$(grep -i '^X-Signature-SSHSIG:' "$TMP_HEADERS" 2>/dev/null | tr -d '\r' | sed 's/^[^:]*:[[:space:]]*//' || true)
+EXPECTED_SHA=$(final_response_header_value "$TMP_HEADERS" "X-Checksum-Sha256" || true)
+SSH_SIGNATURE_HEADER=$(final_response_header_value "$TMP_HEADERS" "X-Signature-SSHSIG" || true)
if [[ -z "$EXPECTED_SHA" ]]; then
fail "Server did not provide checksum header; refusing install." "$EXIT_CHECKSUM_FAILED"
diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.go
index 8c2c74d39d..585eb9c006 100644
--- a/scripts/installtests/install_sh_test.go
+++ b/scripts/installtests/install_sh_test.go
@@ -323,6 +323,86 @@ func TestInstallSHPreflightChecksAgentDownloadArtifact(t *testing.T) {
}
}
+func TestInstallSHPreflightFollowsAgentDownloadRedirect(t *testing.T) {
+ var requestedArtifactMethod string
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case "/api/health":
+ w.WriteHeader(http.StatusOK)
+ case "/download/pulse-agent":
+ w.Header().Set("X-Checksum-Sha256", strings.Repeat("a", 64))
+ http.Redirect(w, r, "/artifacts/pulse-agent?"+r.URL.RawQuery, http.StatusTemporaryRedirect)
+ case "/artifacts/pulse-agent":
+ requestedArtifactMethod = r.Method
+ w.Header().Set("X-Checksum-Sha256", strings.Repeat("b", 64))
+ w.WriteHeader(http.StatusOK)
+ default:
+ http.NotFound(w, r)
+ }
+ }))
+ defer server.Close()
+
+ cmd := exec.Command(
+ "bash",
+ repoFile("scripts", "install.sh"),
+ "--url",
+ server.URL,
+ "--preflight-only",
+ "--output",
+ "json",
+ "--non-interactive",
+ )
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("redirected preflight failed: %v\n%s", err, out)
+ }
+
+ if got := string(out); !strings.Contains(got, `"code":"agent_download_available"`) {
+ t.Fatalf("redirected preflight did not report agent download availability:\n%s", got)
+ }
+ if requestedArtifactMethod != http.MethodHead {
+ t.Fatalf("redirected artifact method = %q, want HEAD", requestedArtifactMethod)
+ }
+}
+
+func TestInstallSHPreflightRejectsChecksumOnlyOnRedirectResponse(t *testing.T) {
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case "/api/health":
+ w.WriteHeader(http.StatusOK)
+ case "/download/pulse-agent":
+ w.Header().Set("X-Checksum-Sha256", strings.Repeat("a", 64))
+ http.Redirect(w, r, "/artifacts/pulse-agent?"+r.URL.RawQuery, http.StatusTemporaryRedirect)
+ case "/artifacts/pulse-agent":
+ w.WriteHeader(http.StatusOK)
+ default:
+ http.NotFound(w, r)
+ }
+ }))
+ defer server.Close()
+
+ cmd := exec.Command(
+ "bash",
+ repoFile("scripts", "install.sh"),
+ "--url",
+ server.URL,
+ "--preflight-only",
+ "--output",
+ "json",
+ "--non-interactive",
+ )
+ out, err := cmd.CombinedOutput()
+ if err == nil {
+ t.Fatalf("preflight accepted checksum metadata from an intermediate redirect:\n%s", out)
+ }
+ if exitErr, ok := err.(*exec.ExitError); !ok || exitErr.ExitCode() != 12 {
+ t.Fatalf("redirect-only checksum exit = %v, want 12\n%s", err, out)
+ }
+ if got := string(out); !strings.Contains(got, `"code":"agent_download_checksum_missing"`) {
+ t.Fatalf("preflight did not report missing final-response checksum metadata:\n%s", got)
+ }
+}
+
func TestInstallSHPreflightDoesNotRequireRoot(t *testing.T) {
content, err := os.ReadFile(repoFile("scripts", "install.sh"))
if err != nil {
@@ -333,8 +413,8 @@ func TestInstallSHPreflightDoesNotRequireRoot(t *testing.T) {
required := []string{
`if [[ $EUID -ne 0 && "$PREFLIGHT_ONLY" != "true" ]]; then`,
`DOWNLOAD_CHECK_URL="${PULSE_URL}/download/${BINARY_NAME}?arch=${PF_ARCH_PARAM}"`,
- `CURL_DOWNLOAD_CHECK_ARGS=(-fsSI --connect-timeout 5 --max-time 30 -D "$PREFLIGHT_HEADERS" -o /dev/null)`,
- `grep -i '^X-Checksum-Sha256:' "$PREFLIGHT_HEADERS"`,
+ `CURL_DOWNLOAD_CHECK_ARGS=(-fsSIL --connect-timeout 5 --max-time 30 -D "$PREFLIGHT_HEADERS" -o /dev/null)`,
+ `final_response_header_value "$PREFLIGHT_HEADERS" "X-Checksum-Sha256"`,
`"agent_download_available"`,
`"agent_download_unavailable"`,
`"agent_download_checksum_missing"`,
@@ -3646,7 +3726,7 @@ func TestInstallSHRequiresPinnedSignatureVerificationForReleaseDownloads(t *test
required := []string{
`PINNED_INSTALLER_SSH_PUBLIC_KEY="__PULSE_INSTALLER_SSH_PUBLIC_KEY__"`,
`has_pinned_installer_signature_key() {`,
- `grep -i '^X-Signature-SSHSIG:' "$TMP_HEADERS"`,
+ `final_response_header_value "$TMP_HEADERS" "X-Signature-SSHSIG"`,
`Server did not provide checksum header; refusing install.`,
`Server did not provide SSH signature header; refusing signed install.`,
`ssh-keygen -Y verify`,