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.

Reject drift during native updater executable readback

pulse-triage[bot]9c18dcec598a
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index d4748a2b8c..7b73cddd85 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -175,6 +175,17 @@ persistent-file hashes, restoration mode, backup disposition and owned cleanup.
Seven phases cover forward/manual reverse, failed active/inactive/masked installs,
invalid signatures and an incomplete restore that retains its backup without start.
+The independent active-runtime oracle brackets its process-byte read with two
+matching systemd observations after API readiness, including load, activity,
+positive decimal PID and mask/enablement. Both the running executable and the
+final installed executable must match the authenticated fixture hash, not just
+each other. A changed/failed observation, disappearing process or destination
+drift refuses the phase without any service-control action. Portable
+`test_runtime_readback_rejects_post_comparison_drift` controls reject each drift,
+including equally wrong running/installed bytes; the Go harness requires its
+completed verdict. These are acceptance-oracle controls, not a native systemd
+result or evidence of the cause of a customer interruption.
+
The test uses signed local archives/installers and an ephemeral test signer.
The signer is newly generated in this attempt's private directory, must be an
executor-owned regular file and receives an explicit verified `0600` mode before
diff --git a/scripts/installtests/auto_update_systemd.py b/scripts/installtests/auto_update_systemd.py
index 843e1d3a6a..00b4762547 100644
--- a/scripts/installtests/auto_update_systemd.py
+++ b/scripts/installtests/auto_update_systemd.py
@@ -316,7 +316,8 @@ class NativeLab:
def assert_runtime(self, tag, active):
binary = self.root / "install/bin/pulse"
- if digest(binary) != self.receipt["binaries"][tag]:
+ expected_hash = self.receipt["binaries"][tag]
+ if digest(binary) != expected_hash:
raise RuntimeError("installed executable differs from authenticated fixture")
if (self.root / "install/VERSION").read_text() != tag + "\n":
raise RuntimeError("version sidecar differs")
@@ -349,10 +350,20 @@ class NativeLab:
# Type=simple start can return before exec. Bind the observed
# process after application readiness, not to that launch race.
state = self.state()
- if state["ActiveState"] != "active" or state["MainPID"] == "0":
+ if (state["LoadState"] != "loaded" or state["ActiveState"] != "active"
+ or not re.fullmatch(r"[1-9][0-9]*", state["MainPID"])):
raise RuntimeError("served application has no active managed process")
- if digest(Path("/proc") / state["MainPID"] / "exe") != digest(binary):
- raise RuntimeError("running executable differs from installed executable")
+ if digest(Path("/proc") / state["MainPID"] / "exe") != expected_hash:
+ raise RuntimeError("running executable differs from authenticated fixture")
+ # A process or destination can change during the byte read. Do not
+ # accept a stale PID observation, or two equally wrong executables,
+ # as independent proof of the source transaction's final state.
+ observed = self.state()
+ if observed != state:
+ raise RuntimeError("managed process state changed during executable readback")
+ if digest(binary) != expected_hash:
+ raise RuntimeError("installed executable changed during runtime readback")
+ state = observed
elif state["MainPID"] != "0":
raise RuntimeError("inactive fixture retains a managed process")
return state
diff --git a/scripts/installtests/pulse_auto_update_test.go b/scripts/installtests/pulse_auto_update_test.go
index d4b59e0a17..96999de3a0 100644
--- a/scripts/installtests/pulse_auto_update_test.go
+++ b/scripts/installtests/pulse_auto_update_test.go
@@ -35,6 +35,8 @@ func TestAutoUpdateNativeSystemdHarnessContracts(t *testing.T) {
"test_signer_creation_refuses_adoption_wrong_type_owner_or_failed_mode",
"test_real_verifier_accepts_fixture_and_refuses_tampering",
"test_phase_cannot_accept_wrong_bytes_state_mask_persistence_or_backup",
+ "test_managed_process_identity_follows_served_readiness_and_rejects_residuals",
+ "test_runtime_readback_rejects_post_comparison_drift",
"test_connected_linux_control_is_required_without_macho_or_validator_bypass",
} {
if results[name] != "ok" {
diff --git a/scripts/tests/test_auto_update_systemd.py b/scripts/tests/test_auto_update_systemd.py
index 305a3fcb27..25dbf8718e 100644
--- a/scripts/tests/test_auto_update_systemd.py
+++ b/scripts/tests/test_auto_update_systemd.py
@@ -280,7 +280,7 @@ class NativeContracts(unittest.TestCase):
lab.state = unittest.mock.Mock(return_value={**state, "ActiveState": "inactive"})
with self.assertRaises(RuntimeError): lab.assert_runtime("v0.0.2", "inactive")
continue
- lab.state = unittest.mock.Mock(side_effect=[state, observed])
+ lab.state = unittest.mock.Mock(side_effect=[state, observed, observed])
order = []
def response(url, **kwargs):
endpoint = url.rsplit("/", 1)[-1]
@@ -302,6 +302,70 @@ class NativeContracts(unittest.TestCase):
self.assertEqual(order[:2], ["health", "version"])
self.assertEqual(order[2:], [] if mutation == "stopped-after-readiness" else ["process"])
+ def test_runtime_readback_rejects_post_comparison_drift(self):
+ # Portable manager/API observations, never native acceptance. Keep the
+ # final oracle independent of the updater's own executable verifier.
+ mutations = ("", "pid", "activity", "load", "enablement", "installed",
+ "equally-wrong-bytes", "missing-process", "failed-readback")
+ for mutation in mutations:
+ with self.subTest(mutation=mutation), tempfile.TemporaryDirectory() as directory:
+ lab = self.make_phase(directory)
+ state = dict(LoadState="loaded", ActiveState="active", UnitFileState="disabled", MainPID="2")
+ final = state.copy()
+ changes = {
+ "pid": {"MainPID": "3"},
+ "activity": {"ActiveState": "inactive", "MainPID": "0"},
+ "load": {"LoadState": "not-found"},
+ "enablement": {"UnitFileState": "masked"},
+ }
+ final.update(changes.get(mutation, {}))
+ end = OSError("confined manager read failed") if mutation == "failed-readback" else final
+ lab.state = unittest.mock.Mock(side_effect=[state, state, end])
+ binary = lab.root / "install/bin/pulse"
+ expected = lab.receipt["binaries"]["v0.0.2"]
+ original_digest = native.digest
+ def process_digest(path):
+ if str(path) == "/proc/2/exe":
+ if mutation == "missing-process":
+ raise FileNotFoundError("confined missing process")
+ if mutation in ("installed", "equally-wrong-bytes"):
+ binary.write_bytes(b"changed during executable readback\n")
+ return original_digest(binary) if mutation == "equally-wrong-bytes" else expected
+ return original_digest(path)
+ def response(url, **kwargs):
+ return io.BytesIO(json.dumps({"status": "healthy"} if url.endswith("/health")
+ else {"version": "v0.0.2"}).encode())
+ with patch.object(native, "digest", side_effect=process_digest), \
+ patch.object(native.urllib.request, "urlopen", side_effect=response), \
+ patch.object(lab, "run", side_effect=AssertionError("readback cannot control a service")):
+ if mutation:
+ with self.assertRaises((RuntimeError, OSError)):
+ lab.assert_runtime("v0.0.2", "active")
+ self.assertEqual(lab.receipt["phases"], [])
+ else:
+ self.assertEqual(lab.assert_runtime("v0.0.2", "active"), state)
+ self.assertEqual(lab.state.call_count, 3)
+
+ # Refuse malformed or non-active manager identity before constructing
+ # a process path, even when a digest double would otherwise match.
+ for pid, load in (("0", "loaded"), ("-2", "loaded"), ("02", "loaded"),
+ ("2/../1", "loaded"), ("unknown", "loaded"), ("2", "masked")):
+ with self.subTest(pid=pid, load=load), tempfile.TemporaryDirectory() as directory:
+ lab = self.make_phase(directory)
+ state = dict(LoadState=load, ActiveState="active", UnitFileState="disabled", MainPID=pid)
+ lab.state = unittest.mock.Mock(return_value=state)
+ original_digest = native.digest
+ def no_process_digest(path):
+ if str(path).startswith("/proc/"):
+ raise AssertionError("invalid manager identity reached process-byte read")
+ return original_digest(path)
+ def response(url, **kwargs):
+ return io.BytesIO(json.dumps({"status": "healthy"} if url.endswith("/health")
+ else {"version": "v0.0.2"}).encode())
+ with patch.object(native, "digest", side_effect=no_process_digest), \
+ patch.object(native.urllib.request, "urlopen", side_effect=response):
+ with self.assertRaises(RuntimeError): lab.assert_runtime("v0.0.2", "active")
+
def test_cleanup_never_deletes_preexisting_unowned_scratch(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory); marker = root / "prior"; marker.write_text("not ours\n")