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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Distinguish container SSH setup refusal from legacy collection
pulse-triage[bot]739a1b37af3e
diff --git a/internal/api/configapi/config_setup_handlers.go b/internal/api/configapi/config_setup_handlers.goindex c9b437eef1..fa179210b0 100644--- a/internal/api/configapi/config_setup_handlers.go+++ b/internal/api/configapi/config_setup_handlers.go@@ -2416,7 +2416,7 @@ func (h *ConfigHandlers) getOrGenerateSSHKeys() SSHKeyPair {if isContainer && !devModeAllowSSH {log.Error().Msg("SECURITY BLOCK: SSH key generation disabled in containerized deployments")- log.Error().Msg("Temperature monitoring via SSH is disabled in containerized deployments")+ log.Error().Msg("This setup refusal does not disable legacy SSH collection with an existing key")log.Error().Msg("See: " + "/docs/SECURITY.md#critical-security-notice-for-container-deployments")log.Error().Msg("To test SSH keys in dev/lab only: PULSE_DEV_ALLOW_CONTAINER_SSH=true (NEVER in production!)")return SSHKeyPair{}diff --git a/internal/api/configapi/container_ssh_setup_test.go b/internal/api/configapi/container_ssh_setup_test.gonew file mode 100644index 0000000000..8725c74bac--- /dev/null+++ b/internal/api/configapi/container_ssh_setup_test.go@@ -0,0 +1,85 @@+package configapi++import (+ "os"+ "path/filepath"+ "strings"+ "testing"++ "github.com/rcourtman/pulse-go-rewrite/internal/logging"+)++func TestContainerSSHSetupRefusalDoesNotPromiseCollectionBlock(t *testing.T) {+ for _, state := range []string{"missing_keys", "existing_keys"} {+ t.Run(state, func(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)+ t.Setenv("PULSE_DOCKER", "true")+ t.Setenv("PULSE_DEV_ALLOW_CONTAINER_SSH", "")+ sshDir := filepath.Join(home, ".ssh")+ fixtures := map[string]string{+ "id_ed25519_sensors": "synthetic private-key preservation sentinel",+ "id_ed25519_sensors.pub": "synthetic public-key preservation sentinel",+ }+ if state == "existing_keys" {+ if err := os.Mkdir(sshDir, 0700); err != nil {+ t.Fatal(err)+ }+ for name, data := range fixtures {+ if err := os.WriteFile(filepath.Join(sshDir, name), []byte(data), 0600); err != nil {+ t.Fatal(err)+ }+ }+ }+ id, lines, _ := logging.GetBroadcaster().Subscribe()+ defer logging.GetBroadcaster().Unsubscribe(id)+ if got := (&ConfigHandlers{}).getOrGenerateSSHKeys(); got != (SSHKeyPair{}) {+ t.Fatal("default container setup returned an SSH key")+ }+ var messages strings.Builder+ capture:+ for {+ select {+ case line := <-lines:+ messages.WriteString(line)+ default:+ break capture+ }+ }+ for _, want := range []string{+ "SSH key generation disabled in containerized deployments",+ "This setup refusal does not disable legacy SSH collection with an existing key",+ "/docs/SECURITY.md#critical-security-notice-for-container-deployments",+ "NEVER in production",+ } {+ if !strings.Contains(messages.String(), want) {+ t.Fatalf("setup diagnostic omitted %q: %s", want, messages.String())+ }+ }+ if strings.Contains(messages.String(), "Temperature monitoring via SSH is disabled") {+ t.Fatal("setup diagnostic falsely promised a collection-wide block")+ }+ if state == "missing_keys" {+ if _, err := os.Stat(sshDir); !os.IsNotExist(err) {+ t.Fatalf("refused setup created or accessed SSH directory: %v", err)+ }+ } else {+ entries, err := os.ReadDir(sshDir)+ if err != nil || len(entries) != len(fixtures) {+ t.Fatalf("refused setup changed SSH inventory: entries=%d err=%v", len(entries), err)+ }+ for name, want := range fixtures {+ path := filepath.Join(sshDir, name)+ got, err := os.ReadFile(path)+ if err != nil || string(got) != want {+ t.Fatalf("refused setup changed existing %s: %v", name, err)+ }+ info, err := os.Stat(path)+ if err != nil || info.Mode().Perm() != 0600 {+ t.Fatalf("refused setup changed existing %s permissions: %v", name, err)+ }+ }+ }+ })+ }+}diff --git a/internal/monitoring/container_ssh_collection_test.go b/internal/monitoring/container_ssh_collection_test.gonew file mode 100644index 0000000000..ea7e822169--- /dev/null+++ b/internal/monitoring/container_ssh_collection_test.go@@ -0,0 +1,86 @@+package monitoring++import (+ "context"+ "errors"+ "fmt"+ "os"+ "path/filepath"+ "strings"+ "testing"+ "time"++ "github.com/stretchr/testify/require"+)++type containerSSHFixtureRunner func(context.Context, string, ...string) ([]byte, error)++func (f containerSSHFixtureRunner) Run(ctx context.Context, name string, args ...string) ([]byte, error) {+ return f(ctx, name, args...)+}++// The runner and keyscan are both synthetic: never contact a real SSH host.+// Default container mode warns, but an existing key still reaches the normal+// host-key and strict SSH path. Missing keys and host-key failures still refuse.+func TestContainerSSHCollectionWarnsWithoutBypassingKeyOrHostTrust(t *testing.T) {+ for _, state := range []string{"missing_key", "existing_key", "host_key_refused"} {+ t.Run(state, func(t *testing.T) {+ home := t.TempDir()+ t.Setenv("HOME", home)+ t.Setenv("PULSE_DOCKER", "true")+ t.Setenv("PULSE_DEV_ALLOW_CONTAINER_SSH", "")+ key := filepath.Join(home, "synthetic-key")+ const contents = "synthetic private-key preservation sentinel"+ if state != "missing_key" {+ require.NoError(t, os.WriteFile(key, []byte(contents), 0600))+ }+ keyscans, commands := 0, 0+ trust, err := NewKnownHostsManager(filepath.Join(home, "known_hosts"), WithKeyscanFunc(func(_ context.Context, host string, port int, _ time.Duration) ([]byte, error) {+ keyscans+++ if state == "host_key_refused" {+ return nil, errors.New("synthetic host-key refusal")+ }+ return []byte(fmt.Sprintf("[%s]:%d ssh-ed25519 AAAA\n", host, port)), nil+ }))+ require.NoError(t, err)+ collector := &TemperatureCollector{+ sshUser: "fixture", sshKeyPath: key, sshPort: 2222, hostKeys: trust,+ runner: containerSSHFixtureRunner(func(_ context.Context, name string, args ...string) ([]byte, error) {+ commands+++ require.Equal(t, "ssh", name)+ command := strings.Join(args, " ")+ for _, want := range []string{"StrictHostKeyChecking=yes", "BatchMode=yes", "UserKnownHostsFile=" + trust.Path(), "-i " + key, "[email protected]"} {+ require.Contains(t, command, want)+ }+ require.Equal(t, pulseSensorsSSHCommand, args[len(args)-1])+ return []byte(`{"coretemp-isa-0000":{"Package id 0":{"temp1_input":44}}}`), nil+ }),+ }+ logs := newMonitoringLogCapture(t)+ temperature, err := collector.CollectTemperature(context.Background(), "container-ssh.invalid", "synthetic-node")+ require.NoError(t, err)+ require.NotNil(t, temperature)+ require.Contains(t, logs.String(), "This is insecure for production deployments.")+ if state == "existing_key" {+ require.True(t, temperature.Available)+ require.Equal(t, 44.0, temperature.CPUPackage)+ require.Equal(t, 1, keyscans)+ require.Equal(t, 1, commands)+ } else {+ require.False(t, temperature.Available)+ require.Zero(t, commands, "missing key or failed host-key trust must not reach SSH execution")+ if state == "missing_key" {+ require.Zero(t, keyscans)+ }+ }+ if state != "missing_key" {+ got, err := os.ReadFile(key)+ require.NoError(t, err)+ require.Equal(t, contents, string(got))+ info, err := os.Stat(key)+ require.NoError(t, err)+ require.Equal(t, os.FileMode(0600), info.Mode().Perm())+ }+ })+ }+}diff --git a/internal/monitoring/temperature.go b/internal/monitoring/temperature.goindex 51d87ad680..c7a0d79b09 100644--- a/internal/monitoring/temperature.go+++ b/internal/monitoring/temperature.go@@ -263,7 +263,7 @@ func (tc *TemperatureCollector) CollectTemperature(ctx context.Context, nodeHost// Extract hostname/IP from the host URL (might be https://hostname:8006)host := extractHostname(nodeHost)- // SECURITY: Block SSH fallback when running in containers (unless dev mode)+ // SECURITY: Warn about legacy SSH collection in containers; this is not a block.// Container compromise = SSH key compromise = root access to infrastructuredevModeAllowSSH := os.Getenv("PULSE_DEV_ALLOW_CONTAINER_SSH") == "true"isContainer := os.Getenv("PULSE_DOCKER") == "true" || system.InContainer()@@ -303,7 +303,7 @@ func (tc *TemperatureCollector) CollectTemperature(ctx context.Context, nodeHostreturn &models.Temperature{Available: false}, nil}- // Direct SSH (legacy method for non-containerized deployments).+ // Direct SSH (legacy method, including containers with an existing usable key).// New setup scripts restrict the key to /usr/local/sbin/pulse-sensors, which emits// the canonical {sensors, smart} payload. Older keys ignore the requested command// and still force sensors -j, so keep the parser backward-compatible.