mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 17:21:13 +01:00
Bring four unclaimed in-app Help guides and their public/docs mirrors into alignment with current main behaviour and add source-bound drift tests: - docs/AUDIT_LOGGING.md: document 31 live API audit event types emitted on main (API token lifecycle, RBAC role and user lifecycle/deprovisioning, action-runner credentials, collector authority reduction, SSO lifecycle, Patrol objectives, and AI command approvals/denials), guarded by a source-derived test in scripts/tests/test_audit_recovery_docs.py. - docs/OPERATIONAL_TRUST.md: document GET /api/ai/patrol/attention/receipts, the 24-hour approval TTL for background/refreshed Patrol action plans vs 5-minute default for direct/interactive plans, and the 31 March 2027 Pulse Mobile retirement date, guarded in scripts/tests/test_production_rollout_docs.py. - docs/ASSISTANT_ARCHITECTURE.md: replace stale pulse_question sequential-tool prose with the actual retired/refusal runtime behaviour in internal/ai/chat/agentic.go and add governed action lifecycle error codes from internal/agentcapabilities/errors.go, guarded in internal/repoctl/ai_architecture_docs_drift_test.go. - docs/UPGRADE_v5.md: replace the post-upgrade "(send a test)" notification step with passive Alerts -> Notifications and Alerts -> History inspection and distinguish public /api/version from authenticated /api/monitoring/scheduler/health, guarded in scripts/tests/test_upgrade_v5_docs.py. Contract-Neutral: Documentation and documentation drift tests only; no runtime, API, schema, or subsystem contract changes. Change-source: pulse-maintainer
313 lines
20 KiB
Python
313 lines
20 KiB
Python
#!/usr/bin/env python3
|
|
"""Keep production decisions consistent with existing safety and edition help.
|
|
|
|
These are source/guidance checks, not native backup, installation, licence or
|
|
notification acceptance. No provider calls or disruptive operations are run.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
DOC = ROOT / "docs/PRODUCTION_SECURITY.md"
|
|
TRUST_DOC = ROOT / "docs/OPERATIONAL_TRUST.md"
|
|
|
|
|
|
def section(heading):
|
|
text = DOC.read_text(encoding="utf-8")
|
|
return " ".join(text.split(heading + "\n", 1)[1].split("\n## ", 1)[0].split())
|
|
|
|
|
|
class ProductionRolloutDocsTest(unittest.TestCase):
|
|
def test_shipped_guide_matches_canonical(self):
|
|
self.assertEqual(DOC.read_bytes(),
|
|
(ROOT / "frontend-modern/public/docs/PRODUCTION_SECURITY.md").read_bytes())
|
|
|
|
def test_api_only_keeps_the_guest_agent_backup_boundary(self):
|
|
text = section("## Choose the least-privileged collection path")
|
|
for boundary in ("API-only does not mean no guest-agent commands",
|
|
"without a Pulse agent installed", "freeze-enabled backups",
|
|
"VM_DISK_MONITORING.md#backup-safety", "automatic updaters",
|
|
"stopping only a Pulse agent is not enough",
|
|
"An OK backup task does not prove guest thaw",
|
|
"Do not run a backup or guest-agent probe"):
|
|
self.assertIn(boundary, text)
|
|
# The actual server collector calls the Proxmox QGA endpoint. API-only
|
|
# does not imply a passive or guest-agent-free transport.
|
|
collector = (ROOT / "internal/monitoring/monitor_pve_guest_builders.go").read_text()
|
|
client = (ROOT / "pkg/proxmox/client.go").read_text()
|
|
self.assertIn("client.GetVMFSInfo(ctx, res.Node, res.VMID)", collector)
|
|
self.assertIn('"/nodes/%s/qemu/%d/agent/get-fsinfo"', client)
|
|
|
|
def test_installation_preserves_paid_edition_and_recoverable_data(self):
|
|
text = section("## Installation and update integrity")
|
|
for boundary in ("version, edition and deployment configuration",
|
|
"consistent private backup", "matching keys", "external stores",
|
|
"does not reverse data migrations", "Community builds",
|
|
"even with an activation key", "continuing Relay",
|
|
"private Pro image or archive", "Do not replace an installed paid runtime",
|
|
"For a Community server installation", "pulse-install",
|
|
"before running it", "same pinned version"):
|
|
self.assertIn(boundary, text)
|
|
install = " ".join((ROOT / "docs/INSTALL.md").read_text().split())
|
|
self.assertIn("Community builds", install)
|
|
self.assertIn("do not include the private Pulse Pro runtime hooks", install)
|
|
self.assertIn("private Pulse Pro Docker image or Linux archive", install)
|
|
deployment = " ".join((ROOT / "docs/DEPLOYMENT_MODELS.md").read_text().split())
|
|
self.assertIn("does not undo data migrations", deployment)
|
|
self.assertIn("Paid Pro installs must keep their private image", deployment)
|
|
|
|
def test_retirement_is_not_a_current_remote_web_or_purchase_offer(self):
|
|
text = section("## Community and Pro boundaries")
|
|
for boundary in ("Relay is no longer sold", "31 March 2027",
|
|
"Existing paired phones keep working until then",
|
|
"current price", "for as long as their subscription continues",
|
|
"including after the app retires", "**not the web UI**",
|
|
"own VPN or tunnel", "ntfy, Gotify or Pushover",
|
|
"phone's browser", "do not plan a new deployment"):
|
|
self.assertIn(boundary, text)
|
|
self.assertNotIn("Relay and Pro add", text)
|
|
plans = " ".join((ROOT / "docs/PULSE_PRO.md").read_text().split())
|
|
self.assertIn("Relay is no longer sold", plans)
|
|
self.assertIn("Relay connects the app, not the web UI", plans)
|
|
self.assertIn("Those Pro features do not end with the app's retirement", plans)
|
|
|
|
def test_current_plan_copy_keeps_free_sso_and_history_distinct(self):
|
|
text = section("## Community and Pro boundaries")
|
|
self.assertIn("90 days of metric history", text)
|
|
self.assertNotIn("Pro adds 90-day history", text)
|
|
self.assertIn("SSO is included with Community and higher tiers", text)
|
|
features = (ROOT / "pkg/licensing/features.go").read_text()
|
|
free = features.split("var freeFeatures = []string{", 1)[1].split("}", 1)[0]
|
|
self.assertRegex(free, r"\bFeatureSSO\b")
|
|
# Metric history is free on every plan: no tier history map remains.
|
|
self.assertRegex(free, r"\bFeatureLongTermMetrics\b")
|
|
self.assertNotIn("TierHistoryDays", features)
|
|
|
|
def test_rollout_does_not_inject_failures_or_hide_faults_on_live_workloads(self):
|
|
text = section("## Production rollout checklist")
|
|
for boundary in ("isolated non-production fixture", "independent monitoring",
|
|
"recovery path", "Do not induce node loss", "failed backup",
|
|
"full disk", "alert storm", "on live workloads",
|
|
"Test notification success does not establish ordinary, grouped or resolved",
|
|
"every covered filesystem", "workload liveness",
|
|
"restore only services and timers active before the pause",
|
|
"monitoring and alerts are unavailable", "independent outage coverage",
|
|
"matching node names or VMIDs do not establish the same resource",
|
|
"normal staged operation", "comparable",
|
|
"database size is not a write rate", "Do not prune history or change polling"):
|
|
self.assertIn(boundary, text)
|
|
self.assertNotIn("Test loss-of-node", text)
|
|
self.assertNotIn("```", text)
|
|
self.assertIn("CONFIGURATION.md#multiple-proxmox-installations", text)
|
|
self.assertIn("TROUBLESHOOTING.md#excessive-cpu-writes-or-database-growth", text)
|
|
|
|
def test_lxc_rollout_checks_collection_and_headroom_at_the_same_limit(self):
|
|
checklist = section("## Production rollout checklist")
|
|
items = [item for item in checklist.split("- [ ] ")
|
|
if item.startswith("Before widening a memory-limited Proxmox LXC rollout")]
|
|
self.assertEqual(len(items), 1)
|
|
item = items[0]
|
|
for requirement in ("same LXC limit and workload", "equal windows at comparable uptime",
|
|
"same swap allowance",
|
|
"peak **container memory**", "process RSS separate",
|
|
"kernel memory kills", "unexpected Pulse restarts", "fresh readings",
|
|
"same guests and backup datastores", "lifetime peak from before",
|
|
"missing evidence as unverified", "Do not change the limit, restart again or induce a kill"):
|
|
with self.subTest(requirement=requirement):
|
|
self.assertIn(requirement, item)
|
|
self.assertIn("TROUBLESHOOTING.md#after-a-memory-cgroup-kill", item)
|
|
self.assertIn("](#compare-lxc-memory-peaks)", item)
|
|
target = (ROOT / "frontend-modern/public/docs/TROUBLESHOOTING.md").read_text(encoding="utf-8")
|
|
self.assertIn("\n##### After a memory-cgroup kill\n", target)
|
|
|
|
def test_lxc_headroom_does_not_treat_lifetime_or_sampled_values_as_window_peaks(self):
|
|
text = section("### Compare LXC memory peaks")
|
|
for evidence in (
|
|
"`memory.peak` at the start and end of each window",
|
|
"from the same container cgroup",
|
|
"the new peak occurred in that window",
|
|
"an upper bound, not the peak for that window",
|
|
"`memory.current` samples",
|
|
"can miss short spikes",
|
|
"its peak and `oom_kill` counter start over",
|
|
"Do not reset counters",
|
|
"ordinary busy polls",
|
|
"Keep the rollout staged if you cannot verify the peaks or that collection stayed fresh",
|
|
):
|
|
with self.subTest(evidence=evidence):
|
|
self.assertIn(evidence, text)
|
|
|
|
def test_lxc_headroom_is_not_inferred_from_memory_moving_to_swap(self):
|
|
text = section("### Compare LXC memory peaks")
|
|
for guidance in (
|
|
"`memory.peak` does not count swapped-out pages",
|
|
"already have `memory.swap.current` readings for the same container cgroup",
|
|
"A lower memory peak with more swap use is not enough to widen the rollout",
|
|
"Keep swap samples separate from memory peaks",
|
|
"Do not change swap or add load just to compare",
|
|
):
|
|
with self.subTest(guidance=guidance):
|
|
self.assertIn(guidance, text)
|
|
|
|
def test_scale_and_privilege_limits_remain_explicit(self):
|
|
text = " ".join(DOC.read_text().split())
|
|
for boundary in ("dedicated read-only or narrowly scoped API token",
|
|
"root` by default", "monitoring-only", "agent:exec",
|
|
"DISCOVERY_ENABLED=false", "127.0.0.1:9191", "AES-256-GCM",
|
|
"not a blanket certification", "simulated 500-node",
|
|
"stage the rollout", "independent security certification"):
|
|
self.assertIn(boundary, text)
|
|
self.assertNotRegex(text, r"(?:--insecure|curl[^\n]*\||--token\s)")
|
|
|
|
def test_linux_profile_choice_matches_installer_authority_boundaries(self):
|
|
text = section("### Choose a Linux agent profile")
|
|
for boundary in ("two different least-privilege profiles",
|
|
"--least-privilege --enable-privileged-helper",
|
|
"root-owned binaries", "no membership in the rootful Docker group",
|
|
"does not remove all root code", "Do not combine it",
|
|
"--grant-smart", "--grant-pct", "PrivateNetwork",
|
|
"root-equivalent", "NoNewPrivileges=false",
|
|
"not the default or full-telemetry parity",
|
|
"not container stats, image-update checks or lifecycle actions",
|
|
"collector-owned rootless socket", "separately enabled action runner",
|
|
"not NAS appliances or non-systemd platforms",
|
|
"Ordinary `--update` preserves the installed profile",
|
|
"not a diagnostic step"):
|
|
with self.subTest(boundary=boundary):
|
|
self.assertIn(boundary, text)
|
|
installer = (ROOT / "scripts/install.sh").read_text()
|
|
# The summary must explain distinct real installer paths, not imply
|
|
# that adding every privilege flag produces the stronger profile.
|
|
for refusal in ("--enable-privileged-helper requires --least-privilege",
|
|
"--enable-privileged-helper cannot be combined with legacy --grant-smart/--grant-pct sudo paths",
|
|
"--least-privilege and --enable-commands are mutually exclusive",
|
|
"--enable-action-runner requires the safe --least-privilege --enable-privileged-helper collector profile"):
|
|
self.assertIn(refusal, installer)
|
|
account = installer.split("provision_least_privilege_user() {", 1)[1].split("\n}\n", 1)[0]
|
|
self.assertIn('"$PRIVILEGED_HELPER_ENABLED" != "true" && "$ENABLE_DOCKER" != "false"', account)
|
|
self.assertIn('usermod -aG docker "$LEAST_PRIVILEGE_USER"', account)
|
|
|
|
def test_rollout_requires_profile_choice_not_root_as_the_only_host_path(self):
|
|
text = section("## Production rollout checklist")
|
|
self.assertIn("Add host agents only for needed local telemetry", text)
|
|
self.assertIn("#choose-a-linux-agent-profile", text)
|
|
self.assertIn("Docker socket authority and reduced telemetry", text)
|
|
self.assertNotIn("Add root agents only", text)
|
|
|
|
def test_operational_upgrade_checks_are_observational_not_action_probes(self):
|
|
text = " ".join(TRUST_DOC.read_text().split("### Read-only checks after upgrading\n", 1)[1].split())
|
|
for boundary in ("existing authenticated browser session", "ordinary collection",
|
|
"same organisation, access scope and filters",
|
|
"An empty queue does not establish complete or healthy collection",
|
|
"Do not disconnect a collector or induce a fault",
|
|
"Recent delivery activity", "recipient's actual message separately",
|
|
"Test success does not establish ordinary, grouped or resolved delivery",
|
|
"execution and verification records separately",
|
|
"not by itself a monitoring failure", "Retry can send a real notification",
|
|
"suppression changes active attention", "restart changes a workload",
|
|
"Do not acknowledge, suppress, retry, dismiss or clear records, send a Test",
|
|
"or approve or run an action merely to validate an upgrade",
|
|
"unverified rather than manufacture one",
|
|
"isolated non-production fixture", "synthetic destinations",
|
|
"disposable workloads", "never against live resources"):
|
|
with self.subTest(boundary=boundary):
|
|
self.assertIn(boundary, text)
|
|
for old_instruction in ("acknowledge and unacknowledge a test item",
|
|
"verify a bounded suppression returns to active attention",
|
|
"exercise notification retry/dead-letter monitoring",
|
|
"complete a review/approve/run/verify journey"):
|
|
self.assertNotIn(old_instruction, text)
|
|
# The original advice crossed real mutation boundaries, not just UI
|
|
# demonstrations. Keep that reason grounded in the current owners.
|
|
queue = (ROOT / "internal/api/alerting/notification_queue.go").read_text()
|
|
self.assertIn("queue.ScheduleRetry(request.ID, 0)", queue)
|
|
actions = (ROOT / "internal/api/actions.go").read_text()
|
|
self.assertIn("h.ActionLifecycle().Execute(", actions)
|
|
# Recent delivery activity lives on Alerts -> Notifications, not History.
|
|
self.assertIn("**Recent delivery activity** in **Alerts → Notifications** (`/alerts/notifications`)", text)
|
|
self.assertIn("**Alerts → History** (`/alerts/history`)", text)
|
|
self.assertNotIn("Recent delivery activity** in Alert History", text)
|
|
destinations_tab = (ROOT / "frontend-modern/src/features/alerts/tabs/DestinationsTab.tsx").read_text()
|
|
self.assertIn("<AlertDeliveryLogCard", destinations_tab)
|
|
alert_tabs = (ROOT / "frontend-modern/src/utils/alertTabsPresentation.ts").read_text()
|
|
self.assertIn("ALERT_TAB_DESTINATIONS_LABEL = 'Notifications'", alert_tabs)
|
|
alert_types = (ROOT / "frontend-modern/src/features/alerts/types.ts").read_text()
|
|
self.assertIn("destinations: 'notifications'", alert_types)
|
|
|
|
def test_operational_upgrade_preserves_recovery_and_access_boundaries(self):
|
|
text = " ".join(TRUST_DOC.read_text().split("## Upgrade and compatibility\n", 1)[1].split())
|
|
for boundary in ("version, edition and deployment configuration", "consistent private backup",
|
|
"matching encryption and audit signing keys", "external stores",
|
|
"not a copy of a live database file or a configuration-only export",
|
|
"Do not broaden permissions or replace keys", "independent monitoring and alert coverage",
|
|
"MIGRATION.md#full-state-recovery", "VM_DISK_MONITORING.md#backup-safety",
|
|
"Reverting a binary does not reverse data migrations", "AUTO_UPDATE.md#rollback",
|
|
"metrics listener private", "not a reason to expose a new listener",
|
|
"authentication, TLS verification and least-privilege collection unchanged",
|
|
"Preserve errors and existing delivery/action records", "locally redacted explanation",
|
|
"not credentials, full inventories, notification payloads or Debug exports",
|
|
"A failed read or an empty queue alone is not a reason to restore data",
|
|
"Do not delete lifecycle, evidence, notification, recovery or action records"):
|
|
with self.subTest(boundary=boundary):
|
|
self.assertIn(boundary, text)
|
|
self.assertEqual(TRUST_DOC.read_bytes(),
|
|
(ROOT / "frontend-modern/public/docs/OPERATIONAL_TRUST.md").read_bytes())
|
|
|
|
def test_pve9_fileread_omission_and_auth_hardening_boundaries_match_runtime(self):
|
|
collection = section("## Choose the least-privileged collection path")
|
|
for phrase in (
|
|
"On Proxmox VE 9+, Pulse setup intentionally omits `VM.GuestAgent.FileRead`",
|
|
"cannot restrict it to `/proc/meminfo`",
|
|
"exposes arbitrary guest files to the API token",
|
|
"AGENT_SECURITY.md#proxmox-deployment-choices",
|
|
):
|
|
with self.subTest(collection=phrase):
|
|
self.assertIn(phrase, collection)
|
|
|
|
creds = section("## Credentials, authentication, and data")
|
|
for phrase in (
|
|
"Browser session writes require the `X-CSRF-Token` header",
|
|
"query parameters and form fields are not accepted",
|
|
"issues CSRF cookies only for validated live sessions",
|
|
"PROXY_AUTH.md#-header-trust-boundary",
|
|
"Failed-login lockout is enforced atomically across login, Basic authentication, password changes and configuration transfer",
|
|
"Admitted sessions and API tokens are rechecked as request bodies arrive",
|
|
"quick-setup credential rotation invalidates prior administrator sessions",
|
|
"SSO provider changes and RBAC administration require full-access instance authority",
|
|
"credential-less loopback trust is disabled",
|
|
):
|
|
with self.subTest(creds=phrase):
|
|
self.assertIn(phrase, creds)
|
|
|
|
security = (ROOT / "internal/api/security.go").read_text(encoding="utf-8")
|
|
self.assertIn('csrfToken := r.Header.Get("X-CSRF-Token")', security)
|
|
self.assertIn("if !ValidateSession(sessionID)", security)
|
|
body_auth = (ROOT / "internal/api/request_body_authority.go").read_text(encoding="utf-8")
|
|
self.assertIn("func retainRequestBodyAuthority(cfg *config.Config, r *http.Request)", body_auth)
|
|
auth_go = (ROOT / "internal/api/auth.go").read_text(encoding="utf-8")
|
|
self.assertIn("RecordLoginAttempt(", auth_go)
|
|
router_go = (ROOT / "internal/api/router.go").read_text(encoding="utf-8")
|
|
self.assertIn("InvalidateUserSessions(r.config.AuthUser)", router_go)
|
|
|
|
def test_operational_trust_plan_ttl_receipts_route_and_mobile_retirement_match_runtime(self):
|
|
trust = " ".join(TRUST_DOC.read_text(encoding="utf-8").split())
|
|
for phrase in (
|
|
"Background Patrol action plans, including refreshed Patrol plans, stay open for approval for 24 hours before expiring.",
|
|
"Direct API and interactive action plans keep the 5-minute default expiry.",
|
|
"GET /api/ai/patrol/attention/receipts",
|
|
"until Pulse Mobile retires on 31 March 2027",
|
|
):
|
|
with self.subTest(phrase=phrase):
|
|
self.assertIn(phrase, trust)
|
|
planner = (ROOT / "internal/actionplanner/planner.go").read_text(encoding="utf-8")
|
|
self.assertIn("DefaultPlanTTL = 5 * time.Minute", planner)
|
|
self.assertIn("DefaultPatrolPlanTTL = 24 * time.Hour", planner)
|
|
attention = (ROOT / "internal/api/attention_handlers.go").read_text(encoding="utf-8")
|
|
self.assertIn('case path == "/receipts":', attention)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|