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.

Bound legacy removal PID records and required-tool refusal

pulse-triage[bot]c3911ea59f2c
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 933ebc6fb6..f1107f5ade 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -21,7 +21,8 @@ Before server deregistration or local erasure, Unix uninstall selects its
FreeBSD rc.d or SysV manager and requires observed quiescence. Bounded combined
reads reject failed, incomplete, empty, duplicate or diagnostic-bearing state.
The kernel process inventory checks both collector and daemon supervisor, while
-PID files must be regular numeric records that cannot identify another process.
+PID files must be regular numeric records of at most 32 bytes that cannot
+identify another process.
Process arguments are never returned from the reader. Rendered rc.d/SysV stops
retain PID files after refused signals or when termination remains unconfirmed.
@@ -40,7 +41,7 @@ A linked rc.d service or existing appliance bootstrap therefore refuses *before*
remote removal or erasure until its owning activation task can be reconciled;
this step does not claim appliance task, launchd, Windows or native acceptance.
Missing timeout/sysrc or unrecognised manager output also remains a safe refusal.
-`TestInstallSHLegacyTeardownRequiresObservedQuiescence` requires all sixteen
+`TestInstallSHLegacyTeardownRequiresObservedQuiescence` requires all seventeen
production-function/caller/rendered-stop methods in `agent_legacy_teardown.py`,
using closed ordinary-user models and private deletion/signal targets, plus a
real timeout-child termination control. Source models are not installed signed
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 11638d6979..116c78887a 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -22,7 +22,8 @@ Before server deregistration or local erasure, Unix uninstall selects its
FreeBSD rc.d or SysV manager and requires observed quiescence. Bounded combined
reads reject failed, incomplete, empty, duplicate or diagnostic-bearing state.
The kernel process inventory checks both collector and daemon supervisor, while
-PID files must be regular numeric records that cannot identify another process.
+PID files must be regular numeric records of at most 32 bytes that cannot
+identify another process.
Process arguments are never returned from the reader. Rendered rc.d/SysV stops
retain PID files after refused signals or when termination remains unconfirmed.
@@ -41,7 +42,7 @@ A linked rc.d service or existing appliance bootstrap therefore refuses *before*
remote removal or erasure until its owning activation task can be reconciled;
this step does not claim appliance task, launchd, Windows or native acceptance.
Missing timeout/sysrc or unrecognised manager output also remains a safe refusal.
-`TestInstallSHLegacyTeardownRequiresObservedQuiescence` requires all sixteen
+`TestInstallSHLegacyTeardownRequiresObservedQuiescence` requires all seventeen
production-function/caller/rendered-stop methods in `agent_legacy_teardown.py`,
using closed ordinary-user models and private deletion/signal targets, plus a
real timeout-child termination control. Source models are not installed signed
diff --git a/scripts/install.sh b/scripts/install.sh
index fcaec08609..10cc1e28e5 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -1382,12 +1382,16 @@ legacy_agent_processes_absent() {
}
validate_legacy_agent_removal_pidfiles() {
- local inventory="$1" path="" pid="" row="" observed="" parent="" role=""
+ local inventory="$1" path="" pid="" size="" observed="" parent="" role=""
shift
for path in "$@"; do
[[ -e "$path" || -L "$path" ]] || continue
[[ -f "$path" && ! -L "$path" && -r "$path" ]] || return 1
- # Preserve trailing diagnostics/extra lines; do not evaluate a PID file.
+ # Numeric PID records are tiny; refuse oversized files before reading
+ # them into shell memory. Never evaluate their contents.
+ size=$(wc -c < "$path") || return 1
+ [[ "$size" =~ ^[[:space:]]*([0-9]+)[[:space:]]*$ && ${BASH_REMATCH[1]} -le 32 ]] || return 1
+ # Preserve trailing diagnostics/extra lines.
pid=$(cat "$path" && printf '%s' '__pulse_pid_complete__') || return 1
[[ "$pid" =~ ^([1-9][0-9]*)($'\n')?__pulse_pid_complete__$ ]] || return 1
pid="${BASH_REMATCH[1]}"
diff --git a/scripts/installtests/agent_legacy_teardown.py b/scripts/installtests/agent_legacy_teardown.py
index 48cf708bc6..34bdebb18b 100644
--- a/scripts/installtests/agent_legacy_teardown.py
+++ b/scripts/installtests/agent_legacy_teardown.py
@@ -138,6 +138,7 @@ class AgentLegacyTeardown(unittest.TestCase):
for name in ("primary.pid", "child.pid", "sysv.pid"):
(root / name).write_text(("100" if name == "primary.pid" else "101") + "\n")
if pid == "malformed": (root / "child.pid" if platform == "FreeBSD" else root / "sysv.pid").write_text("101\n42\n")
+ if pid == "overlong": (root / "child.pid" if platform == "FreeBSD" else root / "sysv.pid").write_text("1" * 40 + "\n")
if pid == "linked":
p = root / "child.pid" if platform == "FreeBSD" else root / "sysv.pid"
p.unlink(); p.symlink_to(unrelated)
@@ -164,7 +165,7 @@ class AgentLegacyTeardown(unittest.TestCase):
return s
values = dict(INIT_PATH=init, STATE_DIR=root / "state", PRIVILEGED_HELPER_STATE_DIR=root / "helper",
SAFE_PROFILE_STATE_DIR=root / "profile", EVENTS=root / "events", REPLY=reply,
- TRUENAS_BOOTSTRAP_SCRIPT=root / "bootstrap", FIXTURE=root, PLATFORM=platform, MANAGER=manager)
+ TRUENAS_BOOTSTRAP_SCRIPT=root / "bootstrap", FIXTURE=root, PLATFORM=platform, MANAGER=manager, TEST_FAULT=fault)
prefix = "\n".join(k + "=" + shlex.quote(str(v)) for k, v in values.items()) + "\n"
shell = r'''
set -euo pipefail
@@ -182,6 +183,8 @@ command() {
esac
builtin command "$@"
}
+if [[ "$TEST_FAULT" == missing-timeout ]]; then timeout() { return 127; }; fi
+if [[ "$TEST_FAULT" == missing-sysrc ]]; then sysrc() { return 127; }; fi
collector_credential_state_present() { return 0; }
uninstall_collector_registration() {
printf 'remote:remove\n' >> "$EVENTS"
@@ -278,6 +281,15 @@ remove_safe_profile_state_dir() { builtin command rm -r -- "$SAFE_PROFILE_STATE_
self.assertEqual(after, before)
self.assertNotIn("init:remove", events)
+ def test_missing_required_tools_refuse_without_losing_recovery(self):
+ for platform, fault in (("FreeBSD", "missing-timeout"), ("SysV", "missing-timeout"), ("FreeBSD", "missing-sysrc")):
+ with self.subTest(platform=platform, fault=fault):
+ r, events, before, after, _ = self.exercise(platform, fault=fault, flow="caller")
+ self.assertNotEqual(r.returncode, 0, r.stderr)
+ self.assertEqual(after, before)
+ self.assertNotIn("remote:remove", events)
+ self.assertNotIn("service:stop", events)
+
def test_final_process_read_and_orphan_supervisor_are_required(self):
for platform, fault in (("SysV", "failed-final-process"), ("FreeBSD", "failed-final-process"), ("FreeBSD", "orphan-supervisor")):
with self.subTest(platform=platform, fault=fault):
@@ -288,7 +300,7 @@ remove_safe_profile_state_dir() { builtin command rm -r -- "$SAFE_PROFILE_STATE_
def test_pid_ownership_and_unexpected_paths_refuse_before_signals(self):
for platform in ("FreeBSD", "SysV"):
- for args in (dict(fault="pid-reused"), dict(pid="malformed"), dict(pid="linked"), dict(path="linked"),
+ for args in (dict(fault="pid-reused"), dict(pid="malformed"), dict(pid="linked"), dict(pid="overlong"), dict(path="linked"),
dict(path="directory"), dict(path="not-executable")):
with self.subTest(platform=platform, args=args):
r, events, before, after, _ = self.exercise(platform, **args)
diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.go
index a5b3b7235b..e76c11ec2d 100644
--- a/scripts/installtests/install_sh_test.go
+++ b/scripts/installtests/install_sh_test.go
@@ -2656,7 +2656,8 @@ func TestInstallSHFreeBSDRendererUsesDaemonSupervisorPidfile(t *testing.T) {
`parent_pid=\$(ps -o ppid= -p "\${agent_pid}" 2>/dev/null | tr -d '[:space:]')`,
`daemon:*)`,
`/usr/sbin/daemon -r -P \${pidfile} -p \${child_pidfile} -f "\${command}" \${command_args}`,
- `kill -KILL "\${supervisor_pid}" 2>/dev/null || true`,
+ `kill -KILL "\${supervisor_pid}" 2>/dev/null || return 1`,
+ `pulse_agent_wait_stopped "\${supervisor_pid}" || return 1`,
`rm -f \${pidfile} \${child_pidfile}`,
`legacy child pid \${legacy_pid} supervised by pid \${legacy_supervisor}`,
}
@@ -8428,6 +8429,7 @@ func TestInstallSHLegacyTeardownRequiresObservedQuiescence(t *testing.T) {
"test_ignored_stop_disable_and_reactivation_are_not_success",
"test_failed_empty_diagnostic_or_duplicate_reads_are_not_absence",
"test_enablement_refusals_and_unknown_values_retain_recovery",
+ "test_missing_required_tools_refuse_without_losing_recovery",
"test_final_process_read_and_orphan_supervisor_are_required",
"test_pid_ownership_and_unexpected_paths_refuse_before_signals",
"test_every_owned_runlevel_link_and_both_layouts_are_removed",
@@ -8444,7 +8446,7 @@ func TestInstallSHLegacyTeardownRequiresObservedQuiescence(t *testing.T) {
t.Fatalf("legacy manager control %s did not pass:\n%s", name, output)
}
}
- if !strings.Contains(string(output), "\nRan 16 tests in ") || !strings.Contains(string(output), "\nOK\n") {
+ if !strings.Contains(string(output), "\nRan 17 tests in ") || !strings.Contains(string(output), "\nOK\n") {
t.Fatalf("incomplete legacy manager verdict:\n%s", output)
}
t.Logf("%s", output)