mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-16 13:39:36 +00:00
Keep installer registration diagnostics bounded (#4472)
**Keep installer registration diagnostics bounded**
Report the failed stage and numeric curl exit instead of echoing remote
response buffers. Preserve registration admission, payloads, retry
budgets, TLS and completion state. Exercise nine synthetic
shipped-function cases with request, saved-state and output controls,
and bind their compiled input into the existing rootful source manifest.
Contract-Neutral: Installer diagnostic presentation and regression
coverage only; credential and response admission, requests, retries,
TLS, saved state, completion fields and qualification contracts are
unchanged.
**Separate parser fixture startup from its admission verdict**
Give the full installer-parser and separate private-file consumer a
fixed fifteen-second fixture watchdog instead of five. Keep every exit,
handoff, private-file, receipt and no-operation assertion. Exercise a
deliberately delayed real validator and ensure a watchdog expiration
still raises rather than passing as a negative control. The historical
preflight timeout remains an observed five-second interruption, not a
diagnosed source regression or host-load event.
Contract-Neutral: Test-only process watchdog and regression controls;
installer source, admission, credential handling, product deadlines and
lifecycle behavior are unchanged.
---
Fleet candidate `20261116T055230Z-delivery-trust` from the
`delivery-trust` lane. Reviewed tip
`14d30fcfff` on `main`.
[How Pulse handles
triage](https://github.com/rcourtman/Pulse/blob/main/docs/AI_TRANSPARENCY.md)
This commit is contained in:
commit
ab1c22125d
4 changed files with 209 additions and 3 deletions
|
|
@ -2395,7 +2395,7 @@ smoke_test_pve_auto_register_token() {
|
|||
if [[ $smoke_status -ne 0 ]]; then
|
||||
AUTO_NODE_REGISTER_ERROR="token smoke check failed"
|
||||
print_warn "Created Proxmox monitoring token, but a local API smoke check failed; skipping automatic node registration"
|
||||
print_warn "Smoke check error: ${smoke_output}"
|
||||
print_warn "Local API smoke check failed (curl exit ${smoke_status}); check the Proxmox API URL and monitoring-token permissions. Response details are omitted to protect credentials."
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
|
@ -2816,7 +2816,7 @@ PY
|
|||
|
||||
if [[ "$register_status" != "success" ]] || [[ "$register_action" != "use_token" ]] || [[ "$register_type" != "pve" ]] || [[ "$register_source" != "script" ]] || [[ "$register_host" != "$normalized_host_url" ]] || [[ "$register_token_id" != "$token_id" ]] || [[ "$register_token_value" != "$token_value" ]] || [[ -z "$register_node_id" ]] || [[ -z "$register_node_name" ]] || [[ "$register_node_id" != "$register_node_name" ]]; then
|
||||
AUTO_NODE_REGISTER_ERROR="auto-register unsuccessful"
|
||||
print_warn "Pulse auto-registration reported an error: $register_response"
|
||||
print_warn "Pulse auto-registration response could not be verified; response details are omitted to protect credentials. Check Pulse's node list before re-running the installer."
|
||||
return
|
||||
fi
|
||||
|
||||
|
|
|
|||
172
scripts/installtests/root_registration_diagnostics_test.go
Normal file
172
scripts/installtests/root_registration_diagnostics_test.go
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
//go:build linux
|
||||
|
||||
package installtests
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Exercise the shipped registration functions. Only curl's remote responses
|
||||
// and Proxmox's provider commands are inert adapters; no provider, credential,
|
||||
// guest, service or installed state is accessed by these diagnostic controls.
|
||||
func TestRootInstallerRegistrationDiagnostics(t *testing.T) {
|
||||
const host = "https://fixture.invalid:8006"
|
||||
const pulse = "http://127.0.0.1:7655"
|
||||
const tokenID = "pulse-monitor@pve!pulse-127-0-0-1"
|
||||
const tokenValue = "fixture-monitor-credential"
|
||||
const setupToken = "fixture-setup-credential"
|
||||
for _, mode := range []string{"success", "status", "token-id", "token-value", "node-name", "malformed", "smoke-7", "smoke-22", "smoke-28"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
root := t.TempDir()
|
||||
setupURL := pulse + "/api/setup-script?backup_perms=true&host=" + url.QueryEscape(host) + "&pulse_url=" + url.QueryEscape(pulse) + "&type=pve"
|
||||
command := "curl '" + setupURL + "' | { if [ \"$(id -u)\" -eq 0 ]; then env PULSE_SETUP_TOKEN_FILE=/fixture/token bash; elif command -v sudo >/dev/null 2>&1; then sudo env PULSE_SETUP_TOKEN_FILE=/fixture/token bash; fi; }"
|
||||
setup := map[string]any{
|
||||
"setupToken": setupToken, "type": "pve", "host": host, "url": setupURL, "downloadURL": setupURL,
|
||||
"scriptFileName": "pulse-setup-pve.sh", "command": command, "commandWithEnv": command,
|
||||
"commandWithoutEnv": command, "tokenHint": "fixture-hint", "expires": time.Now().Add(time.Hour).Unix(),
|
||||
}
|
||||
registration := map[string]string{
|
||||
"status": "success", "action": "use_token", "type": "pve", "source": "script", "host": host,
|
||||
"tokenId": tokenID, "tokenValue": tokenValue, "nodeId": "fixture-pve", "nodeName": "fixture-pve",
|
||||
"remoteDetails": "remote-output-only-marker remote-diagnostic-credential \x1b[31m",
|
||||
}
|
||||
switch mode {
|
||||
case "status":
|
||||
registration["status"] = "error"
|
||||
case "token-id":
|
||||
registration["tokenId"] = "other@pve!fixture"
|
||||
case "token-value":
|
||||
registration["tokenValue"] = "remote-diagnostic-credential"
|
||||
case "node-name":
|
||||
registration["nodeName"] = "different-node"
|
||||
}
|
||||
for name, data := range map[string]any{"setup-response": setup, "register-response": registration} {
|
||||
body, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeTestFile(t, filepath.Join(root, name), body, 0600)
|
||||
}
|
||||
if mode == "malformed" {
|
||||
writeTestFile(t, filepath.Join(root, "register-response"), []byte("remote-output-only-marker "+tokenValue+"\r\n\x1b[31m not JSON"), 0600)
|
||||
}
|
||||
writeTestFile(t, filepath.Join(root, "remote-output"), []byte("remote-output-only-marker "+tokenValue+" remote-diagnostic-credential\r\n\x1b[31m"), 0600)
|
||||
saved := map[string][]byte{"pulse": []byte("saved binary\n"), "system.json": []byte("saved configuration\n"), "token": []byte("saved fixture authority\n")}
|
||||
for name, body := range saved {
|
||||
writeTestFile(t, filepath.Join(root, name), body, 0600)
|
||||
}
|
||||
exitCode := "0"
|
||||
if strings.HasPrefix(mode, "smoke-") {
|
||||
exitCode = strings.TrimPrefix(mode, "smoke-")
|
||||
}
|
||||
env := append(rootCurlFixtureEnvironment(t, root, host), "FIXTURE_CURL_EXIT="+exitCode,
|
||||
"PULSE_PVE_HOST_URL="+host, "PULSE_SKIP_AUTO_NODE=", "PULSE_AUTO_BACKUP_PERMS=true")
|
||||
script := `source "$ROOT_INSTALLER_SOURCE"
|
||||
print_info() { :; }
|
||||
print_warn() { printf 'WARN:%s\n' "$*"; }
|
||||
print_success() { printf 'SUCCESS:%s\n' "$*"; }
|
||||
hostname() { printf 'fixture-pve\n'; }
|
||||
pveum() {
|
||||
if [[ "$*" == 'role list' ]]; then
|
||||
printf 'Sys.Audit\nVM.GuestAgent.Audit\nVM.GuestAgent.FileRead\n'
|
||||
fi
|
||||
}
|
||||
create_pve_auto_register_token() {
|
||||
printf -v "$2" '%s' '{"value":"fixture-monitor-credential"}'
|
||||
printf -v "$3" '%s' 0
|
||||
}
|
||||
curl() {
|
||||
[[ "$1" == -q ]] || return 97
|
||||
local phase= arg
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
*/api/setup-script-url) phase=setup ;;
|
||||
*/api2/json/nodes) phase=smoke ;;
|
||||
*/api/auto-register) phase=register ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' "$phase" >> "$FIXTURE_ROOT/stages"
|
||||
case "$phase" in
|
||||
setup) cat "$FIXTURE_ROOT/setup-response" ;;
|
||||
smoke)
|
||||
cat > "$FIXTURE_ROOT/smoke-header"
|
||||
if [[ "$FIXTURE_CURL_EXIT" != 0 ]]; then
|
||||
cat "$FIXTURE_ROOT/remote-output" >&2
|
||||
return "$FIXTURE_CURL_EXIT"
|
||||
fi
|
||||
printf '{"data":[]}' ;;
|
||||
register)
|
||||
cat > "$FIXTURE_ROOT/register-request"
|
||||
cat "$FIXTURE_ROOT/register-response" ;;
|
||||
*) return 98 ;;
|
||||
esac
|
||||
}
|
||||
IN_CONTAINER=false
|
||||
AUTO_NODE_REGISTERED=false
|
||||
AUTO_NODE_REGISTERED_NAME=unchanged
|
||||
AUTO_NODE_REGISTER_ERROR=
|
||||
auto_register_pve_node 600 127.0.0.1 7655 > "$FIXTURE_ROOT/output" 2>&1
|
||||
printf '%s\n%s\n%s\n' "$AUTO_NODE_REGISTERED" "$AUTO_NODE_REGISTERED_NAME" "$AUTO_NODE_REGISTER_ERROR" > "$FIXTURE_ROOT/result"
|
||||
`
|
||||
if exit := runRootCurlFixture(t, script, env); exit != 0 {
|
||||
t.Fatalf("registration fixture failed: exit=%d", exit)
|
||||
}
|
||||
read := func(name string) string {
|
||||
t.Helper()
|
||||
body, err := os.ReadFile(filepath.Join(root, name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return string(body)
|
||||
}
|
||||
output := read("output")
|
||||
for _, forbidden := range []string{tokenValue, setupToken, "remote-diagnostic-credential", "remote-output-only-marker", "tokenValue", "\x1b", "\r"} {
|
||||
if strings.Contains(output, forbidden) {
|
||||
t.Errorf("remote response or credential echoed in %s diagnostics", mode)
|
||||
}
|
||||
}
|
||||
wantResult, wantStages := "false\nunchanged\nauto-register unsuccessful\n", "setup\nsmoke\nregister\n"
|
||||
if mode == "success" {
|
||||
wantResult = "true\nfixture-pve\n\n"
|
||||
if !strings.Contains(output, "Registered fixture-pve with Pulse automatically") {
|
||||
t.Error("normal registration success message lost")
|
||||
}
|
||||
} else if exitCode != "0" {
|
||||
wantResult, wantStages = "false\nunchanged\ntoken smoke check failed\n", "setup\nsmoke\n"
|
||||
if !strings.Contains(output, "curl exit "+exitCode) {
|
||||
t.Error("safe curl exit diagnostic lost")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, "register-request")); !os.IsNotExist(err) {
|
||||
t.Error("failed smoke check continued to registration")
|
||||
}
|
||||
} else if !strings.Contains(output, "could not be verified") || !strings.Contains(output, "Check Pulse's node list before re-running the installer") {
|
||||
t.Error("rejected-response guidance missing")
|
||||
}
|
||||
if got := read("result"); got != wantResult {
|
||||
t.Errorf("registration state changed: got %q, want %q", got, wantResult)
|
||||
}
|
||||
if got := read("stages"); got != wantStages {
|
||||
t.Errorf("request ordering changed: got %q, want %q", got, wantStages)
|
||||
}
|
||||
if read("smoke-header") != "Authorization: PVEAPIToken="+tokenID+"="+tokenValue+"\n" {
|
||||
t.Error("created-credential smoke identity changed")
|
||||
}
|
||||
if exitCode == "0" {
|
||||
var request map[string]string
|
||||
if err := json.Unmarshal([]byte(read("register-request")), &request); err != nil || request["host"] != host || request["authToken"] != setupToken || request["tokenId"] != tokenID || request["tokenValue"] != tokenValue {
|
||||
t.Error("registration request identity changed")
|
||||
}
|
||||
}
|
||||
assertRootCurlFixtureUnchanged(t, root, filepath.Join(root, "ambient-trace"), saved)
|
||||
t.Logf("%s: synthetic response; %s; no saved-state or request-identity change", mode, fmt.Sprintf("curl exit %s", exitCode))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -81,6 +81,7 @@
|
|||
"scripts/installtests/root_curl_config_test.go",
|
||||
"scripts/installtests/root_install_sh_test.go",
|
||||
"scripts/installtests/root_registration_deadline_test.go",
|
||||
"scripts/installtests/root_registration_diagnostics_test.go",
|
||||
"scripts/installtests/safe_profile_migration_test.go",
|
||||
"scripts/installtests/safe_profile_rollback_quiescence_test.go",
|
||||
"scripts/installtests/secure_runtime_platform_matrix_test.go",
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
|
@ -17,6 +19,10 @@ ROOT = Path(__file__).resolve().parents[2]
|
|||
INSTALLER = ROOT / "scripts/install.sh"
|
||||
TOKEN = "synthetic-argument-test-not-a-credential"
|
||||
OPTIONS = ("--token-file", "--action-token-file")
|
||||
# This is a fixture-process watchdog, not an installer latency contract. The
|
||||
# documented consumer starts Python after parsing the full installer; five
|
||||
# seconds interrupted that unchanged consumer during candidate preflight.
|
||||
FIXTURE_TIMEOUT = 15
|
||||
|
||||
|
||||
class AgentInstallerCredentialPathsTest(unittest.TestCase):
|
||||
|
|
@ -53,7 +59,7 @@ main "$@"
|
|||
command = [shutil.which("bash"), str(self.parser if parser else INSTALLER),
|
||||
"--non-interactive", "--output", output, *arguments]
|
||||
result = subprocess.run(command, env=self.env, cwd=self.home,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
capture_output=True, text=True, timeout=FIXTURE_TIMEOUT)
|
||||
self.assertFalse(self.operations.exists(), "argument parsing attempted an install operation")
|
||||
self.assertNotIn(TOKEN, result.stdout + result.stderr, "diagnostic exposed an earlier credential")
|
||||
return result
|
||||
|
|
@ -159,6 +165,33 @@ main "$@"
|
|||
with self.assertRaisesRegex(AssertionError, "parser boundary missing"):
|
||||
agent_installer_test_support.credential_path_parser_fixture()
|
||||
|
||||
def test_documented_consumer_observes_delayed_validator_completion(self):
|
||||
token = self.home / "documented token"
|
||||
token.write_text(TOKEN + "\n")
|
||||
token.chmod(0o600)
|
||||
receipt = self.home / "delayed-consumer.json"
|
||||
self.env.update(EXPECTED_TOKEN=TOKEN, INSTALL_RECEIPT=str(receipt))
|
||||
self.parser.write_text(agent_installer_test_support.credential_path_parser_fixture())
|
||||
# Deliberate interpreter startup delay, not a claim about the cause of
|
||||
# the historical timeout. Run the real private-file validator after it;
|
||||
# elapsed time, an exception or a missing receipt is never acceptance.
|
||||
python = self.home / "tools" / "python3"
|
||||
python.write_text("#!/bin/sh\nsleep 6\nexec " + shlex.quote(sys.executable) + ' "$@"\n')
|
||||
python.chmod(0o700)
|
||||
result = self.run_script(["--token-file", str(token)], parser=True)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertEqual(json.loads(receipt.read_text()), [
|
||||
"--non-interactive", "--output", "json", "--token-file", str(token),
|
||||
])
|
||||
self.assertEqual(token.read_text(), TOKEN + "\n")
|
||||
self.assertEqual(token.stat().st_mode & 0o777, 0o600)
|
||||
|
||||
def test_fixture_timeout_remains_an_error_not_a_negative_control_pass(self):
|
||||
with patch.object(subprocess, "run", side_effect=subprocess.TimeoutExpired("fixture", 15)) as run:
|
||||
with self.assertRaises(subprocess.TimeoutExpired):
|
||||
self.run_script([], parser=True)
|
||||
self.assertEqual(run.call_args.kwargs["timeout"], 15)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue