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.

Keep ICMP permission diagnostics scoped to the observation host

pulse-triage[bot]5d8ea82da847
diff --git a/internal/availabilityprobe/icmp_diagnostic_test.go b/internal/availabilityprobe/icmp_diagnostic_test.go
new file mode 100644
index 0000000000..983139c2ca
--- /dev/null
+++ b/internal/availabilityprobe/icmp_diagnostic_test.go
@@ -0,0 +1,155 @@
+package availabilityprobe
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+)
+
+func TestICMPProbeDiagnostics(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("synthetic ping fixture requires a POSIX shell; no real ping is used")
+ }
+
+ runners := []struct {
+ name string
+ run func(context.Context, config.AvailabilityTarget) (ProbeResult, error)
+ }{
+ {"Run", func(ctx context.Context, target config.AvailabilityTarget) (ProbeResult, error) {
+ return ProbeResult{}, Run(ctx, target)
+ }},
+ {"Result", func(ctx context.Context, target config.AvailabilityTarget) (ProbeResult, error) {
+ outcome, err := Result(ctx, target)
+ return ProbeResult{Outcome: outcome}, err
+ }},
+ {"DetailedResult", DetailedResult},
+ }
+ const privateMarker = "synthetic-private-ping-details"
+ cases := []struct {
+ name string
+ output string
+ exit int
+ blocked bool
+ wantError string
+ contextErr error
+ missing bool
+ }{
+ {name: "operation-not-permitted", output: "ping: socket: Operation not permitted\n" + privateMarker, exit: 1, blocked: true},
+ {name: "cap-net-raw", output: "ping: missing cap_net_raw capability\n" + privateMarker, exit: 2, blocked: true},
+ {name: "ordinary-error", output: " ping: unknown host\n", exit: 1, wantError: "icmp probe failed: ping: unknown host"},
+ {name: "bounded-output", output: strings.Repeat("x", 300), exit: 1, wantError: "icmp probe failed: " + strings.Repeat("x", 240)},
+ {name: "empty-output", exit: 17, wantError: "icmp probe failed: exit status 17"},
+ {name: "success-with-permission-like-output", output: "Operation not permitted cap_net_raw", exit: 0},
+ {name: "cancelled", contextErr: context.Canceled},
+ {name: "expired", contextErr: context.DeadlineExceeded},
+ {name: "missing-ping", missing: true},
+ }
+ for _, runner := range runners {
+ t.Run(runner.name, func(t *testing.T) {
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ dir := t.TempDir()
+ argsFile := filepath.Join(dir, "args")
+ if !tc.missing {
+ // Shell builtins only: this fixture cannot contact a target or
+ // accidentally delegate to the host's actual ping binary.
+ script := "#!/bin/sh\nprintf '%s\\n' \"$@\" > \"$PULSE_TEST_PING_ARGS\"\nprintf '%s' \"$PULSE_TEST_PING_OUTPUT\" >&2\nexit \"$PULSE_TEST_PING_EXIT\"\n"
+ if err := os.WriteFile(filepath.Join(dir, "ping"), []byte(script), 0700); err != nil {
+ t.Fatal(err)
+ }
+ }
+ t.Setenv("PATH", dir)
+ t.Setenv("PULSE_TEST_PING_ARGS", argsFile)
+ t.Setenv("PULSE_TEST_PING_OUTPUT", tc.output)
+ t.Setenv("PULSE_TEST_PING_EXIT", fmt.Sprint(tc.exit))
+
+ ctx := context.Background()
+ if tc.contextErr == context.Canceled {
+ cancelled, cancel := context.WithCancel(ctx)
+ cancel()
+ ctx = cancelled
+ } else if tc.contextErr == context.DeadlineExceeded {
+ expired, cancel := context.WithDeadline(ctx, time.Now().Add(-time.Second))
+ defer cancel()
+ ctx = expired
+ }
+ target := config.AvailabilityTarget{
+ Address: "192.0.2.10", Protocol: config.AvailabilityProbeICMP, Enabled: true, TimeoutMillis: 1375,
+ }
+ result, err := runner.run(ctx, target)
+ if runner.name == "DetailedResult" && (result.TransportOutcome != result.Outcome || result.Application != nil || result.Certificate != nil) {
+ t.Errorf("ICMP result changed non-diagnostic fields: %+v", result)
+ }
+ switch {
+ case tc.blocked:
+ if err == nil {
+ t.Fatal("permission failure was reported as success")
+ }
+ message := err.Error()
+ for _, required := range []string{"icmp probe blocked", "local permissions", "selected observation host", "server or agent", "docs/CONFIGURATION.md#icmp-probe-privileges", "NoNewPrivileges", "intentional", "restrictions"} {
+ if !strings.Contains(message, required) {
+ t.Errorf("permission diagnostic %q omits %q", message, required)
+ }
+ }
+ for _, unsafe := range []string{privateMarker, "Pulse service unit", "installer", "AmbientCapabilities=", "CapabilityBoundingSet=", "restart", "setcap", "--privileged", "--cap-add", "as root"} {
+ if strings.Contains(message, unsafe) {
+ t.Errorf("permission diagnostic %q contains unsupported advice or raw details %q", message, unsafe)
+ }
+ }
+ if len(message) > 240 {
+ t.Errorf("diagnostic has %d bytes; agent reports truncate after 240", len(message))
+ }
+ case tc.contextErr != nil:
+ if !errors.Is(err, tc.contextErr) {
+ t.Fatalf("error = %v, want %v", err, tc.contextErr)
+ }
+ case tc.missing:
+ if !errors.Is(err, exec.ErrNotFound) || !strings.HasPrefix(err.Error(), "icmp probe failed: ") {
+ t.Fatalf("error = %v, want wrapped missing executable error", err)
+ }
+ case tc.wantError != "":
+ if err == nil || err.Error() != tc.wantError {
+ t.Fatalf("error = %v, want %q", err, tc.wantError)
+ }
+ if tc.output == "" {
+ var exitError *exec.ExitError
+ if !errors.As(err, &exitError) || exitError.ExitCode() != tc.exit {
+ t.Fatalf("error = %v, want wrapped exit %d", err, tc.exit)
+ }
+ }
+ default:
+ if err != nil {
+ t.Fatalf("successful ping returned error: %v", err)
+ }
+ }
+ if runner.name != "Run" {
+ want := OutcomeReachable
+ if err != nil {
+ want = OutcomeUnreachable // Existing classification is unchanged.
+ }
+ if result.Outcome != want {
+ t.Fatalf("outcome = %q, want %q", result.Outcome, want)
+ }
+ }
+ args, argsErr := os.ReadFile(argsFile)
+ if tc.contextErr != nil || tc.missing {
+ if !errors.Is(argsErr, os.ErrNotExist) {
+ t.Fatalf("unstarted ping left arguments: %q, error %v", args, argsErr)
+ }
+ } else if want := strings.Join(pingArgs(target.Address, target.TimeoutMillis), "\n") + "\n"; argsErr != nil || string(args) != want {
+ t.Fatalf("ping arguments = %q, error %v; want %q", args, argsErr, want)
+ }
+ })
+ }
+ })
+ }
+}
diff --git a/internal/availabilityprobe/probe.go b/internal/availabilityprobe/probe.go
index ac2a132018..55fd587f89 100644
--- a/internal/availabilityprobe/probe.go
+++ b/internal/availabilityprobe/probe.go
@@ -200,11 +200,11 @@ func probeICMP(ctx context.Context, target config.AvailabilityTarget) error {
if details == "" {
return fmt.Errorf("icmp probe failed: %w", err)
}
- // Units written before v6.1.0-rc.1 lack AmbientCapabilities=CAP_NET_RAW and
- // in-place updates never rewrite the unit, so ping fails like this on every
- // upgraded install (#1554). Point at the unit instead of echoing ping stderr.
+ // The check runs on the selected server or agent, and a permission failure
+ // does not identify a particular unit setting. Keep the guidance within the
+ // agent's 240-byte error limit without recommending privilege escalation.
if strings.Contains(details, "Operation not permitted") || strings.Contains(details, "cap_net_raw") {
- return fmt.Errorf("icmp probe blocked. The Pulse service unit does not grant CAP_NET_RAW, so ping cannot open a socket. Re-run the Pulse installer to regenerate the unit, or add a systemd override with AmbientCapabilities=CAP_NET_RAW and CapabilityBoundingSet=CAP_NET_RAW, then restart the service")
+ return fmt.Errorf("icmp probe blocked by local permissions on the selected observation host (server or agent). See docs/CONFIGURATION.md#icmp-probe-privileges. Preserve NoNewPrivileges and intentional capability/container restrictions.")
}
if len(details) > 240 {
details = details[:240]
diff --git a/internal/hostagent/availability_icmp_diagnostic_test.go b/internal/hostagent/availability_icmp_diagnostic_test.go
new file mode 100644
index 0000000000..4ecc391b78
--- /dev/null
+++ b/internal/hostagent/availability_icmp_diagnostic_test.go
@@ -0,0 +1,47 @@
+package hostagent
+
+import (
+ "context"
+ "os"
+ "path/filepath"
+ "runtime"
+ "strings"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+)
+
+func TestAvailabilityModuleICMPPermissionDiagnosticSurvivesReport(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("synthetic ping fixture requires a POSIX shell; no real ping is used")
+ }
+ dir := t.TempDir()
+ if err := os.WriteFile(filepath.Join(dir, "ping"), []byte("#!/bin/sh\nprintf '%s' 'ping: socket: Operation not permitted' >&2\nexit 1\n"), 0700); err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("PATH", dir)
+ module := testProbeModule(t, nil) // Exercise the shared core, not the test callback.
+ target := config.NormalizeAvailabilityTarget(config.AvailabilityTarget{
+ ID: "remote-icmp", Address: "192.0.2.10", Protocol: config.AvailabilityProbeICMP, Enabled: true, ConfigRevision: 7,
+ })
+ module.check(context.Background(), target)
+ results := module.snapshotForReport()
+ if len(results) != 1 {
+ t.Fatalf("report has %d observations, want one", len(results))
+ }
+ result := results[0]
+ if result.TargetID != target.ID || result.ConfigRevision != target.ConfigRevision || result.ObservationID == "" || result.CheckedAt.IsZero() {
+ t.Fatalf("report lost observation identity: %+v", result)
+ }
+ if result.Outcome != "unreachable" || result.TransportOutcome != "unreachable" {
+ t.Fatalf("report changed existing ICMP failure classification: %+v", result)
+ }
+ for _, required := range []string{"local permissions", "selected observation host", "server or agent", "docs/CONFIGURATION.md#icmp-probe-privileges", "NoNewPrivileges", "intentional capability/container restrictions."} {
+ if !strings.Contains(result.Error, required) {
+ t.Errorf("agent diagnostic %q lost %q", result.Error, required)
+ }
+ }
+ if len(result.Error) > availabilityErrorLimit || strings.Contains(result.Error, "Pulse service unit") || strings.Contains(result.Error, "installer") {
+ t.Fatalf("agent diagnostic is unbounded or blames the server: %q", result.Error)
+ }
+}