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.

Fail closed on invalid agent CA bundles

rcourtman3308bb733ead
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index c72c7e496f..8bfe6ecb41 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -81,6 +81,8 @@ management, and fleet control surfaces.
59. `frontend-modern/src/components/Settings/useVMwareSettingsPanelState.ts`
60. `frontend-modern/src/components/Settings/MonitoredSystemAdmissionPreview.tsx`
61. `internal/hostagent/proxmox_setup.go`
+62. `internal/remoteconfig/client.go`
+63. `internal/agenttls/config.go`
## Shared Boundaries
@@ -192,7 +194,7 @@ an add-only capacity posture.
path must treat it as the existing system until live inventory rebuild
catches up, rather than as a fresh enrolment competing for another
monitored-system slot.
-4. Keep shared agent-side TLS identity fail-closed across `cmd/pulse-agent/main.go`, `internal/hostagent/`, `internal/agentupdate/`, and adjacent remote-config transport. Self-signed deployments may use a canonical pinned Pulse server certificate fingerprint, but lifecycle transport must route that pin through reporting, enrollment, command websocket, remote-config, and self-update clients instead of widening `PULSE_INSECURE_SKIP_VERIFY` into a blanket MITM carve-out.
+4. Keep shared agent-side TLS identity fail-closed across `cmd/pulse-agent/main.go`, `internal/hostagent/`, `internal/agentupdate/`, `internal/remoteconfig/client.go`, and `internal/agenttls/config.go`. Self-signed deployments may use a canonical pinned Pulse server certificate fingerprint, but lifecycle transport must route that pin through reporting, enrollment, command websocket, remote-config, and self-update clients instead of widening `PULSE_INSECURE_SKIP_VERIFY` into a blanket MITM carve-out. A configured custom CA bundle is part of that same trust boundary: if the bundle is unreadable or invalid, lifecycle transport must refuse the connection path rather than silently downgrading back to system roots.
5. Keep release-grade updater trust fail-closed across `internal/agentupdate/`, `internal/dockeragent/`, and the shared `internal/api/unified_agent.go` download helpers. When release builds embed trusted update signing keys, published agent binaries and installer assets must carry detached `.sig` plus `.sshsig` sidecars; updater/runtime paths must require `X-Signature-Ed25519` in addition to `X-Checksum-Sha256`, and installer-owned download flows must require the matching base64-encoded `X-Signature-SSHSIG`, instead of silently downgrading to checksum-only trust.
6. Keep shared `internal/api/` helper edits isolated from agent lifecycle semantics: Patrol-specific status transport or alert-trigger wiring changes in shared handlers must not bleed into auto-register, installer, or fleet-control behavior unless this contract moves in the same slice.
The same isolation rule applies to AI settings payload work in `internal/api/ai_handlers.go`: provider auth fields, masked-secret echoes, and provider-test model selection remain AI/runtime plus API-contract ownership and must not be reinterpreted as lifecycle setup or registration semantics just because they share backend helper layers.
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index 14dbc9f4fe..a03d9271f8 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -633,9 +633,11 @@
"frontend-modern/src/utils/proxmoxSettingsPresentation.ts",
"frontend-modern/src/utils/unifiedAgentInventoryPresentation.ts",
"frontend-modern/src/utils/unifiedAgentStatusPresentation.ts",
+ "internal/agenttls/config.go",
"internal/api/agent_install_command_shared.go",
"internal/api/config_setup_handlers.go",
"internal/api/unified_agent.go",
+ "internal/remoteconfig/client.go",
"scripts/install.ps1",
"scripts/install.sh"
],
@@ -694,6 +696,22 @@
"internal/agentupdate/update_http_test.go"
]
},
+ {
+ "id": "agent-runtime-transport-trust",
+ "label": "agent runtime transport trust proof",
+ "match_prefixes": [],
+ "match_files": [
+ "internal/agenttls/config.go",
+ "internal/remoteconfig/client.go"
+ ],
+ "allow_same_subsystem_tests": false,
+ "test_prefixes": [],
+ "exact_files": [
+ "internal/agenttls/config_test.go",
+ "internal/remoteconfig/client_additional_test.go",
+ "internal/remoteconfig/client_test.go"
+ ]
+ },
{
"id": "proxmox-unified-agent-setup-runtime",
"label": "proxmox unified agent setup runtime proof",
diff --git a/internal/agentupdate/update.go b/internal/agentupdate/update.go
index 9d8f3081e1..6b32592fdd 100644
--- a/internal/agentupdate/update.go
+++ b/internal/agentupdate/update.go
@@ -127,9 +127,10 @@ type Config struct {
// Updater handles automatic updates for Pulse agents.
type Updater struct {
- cfg Config
- client *http.Client
- logger zerolog.Logger
+ cfg Config
+ client *http.Client
+ logger zerolog.Logger
+ configErr error
checkMu sync.Mutex
checkInProgress bool
@@ -157,27 +158,36 @@ func New(cfg Config) *Updater {
Msg("Invalid agent update check interval; using default")
}
+ var (
+ client *http.Client
+ configErr error
+ )
tlsConfig, err := agenttls.NewClientTLSConfig(cfg.CACertPath, cfg.InsecureSkipVerify, cfg.ServerFingerprint)
if err != nil {
- logger.Warn().Err(err).Str("ca_cert_path", strings.TrimSpace(cfg.CACertPath)).Msg("Invalid custom CA bundle; continuing with default TLS roots")
- tlsConfig, _ = agenttls.NewClientTLSConfig("", cfg.InsecureSkipVerify, cfg.ServerFingerprint)
- }
-
- transport := &http.Transport{
- TLSClientConfig: tlsConfig,
- }
-
- u := &Updater{
- cfg: cfg,
- client: &http.Client{
+ configErr = fmt.Errorf("invalid CA bundle: %w", err)
+ logger.Error().
+ Err(err).
+ Str("ca_cert_path", strings.TrimSpace(cfg.CACertPath)).
+ Msg("Invalid custom CA bundle; refusing to fall back to default TLS roots")
+ } else {
+ transport := &http.Transport{
+ TLSClientConfig: tlsConfig,
+ }
+ client = &http.Client{
Transport: transport,
Timeout: downloadTimeout,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
// Prevent credential leakage (X-API-Token / Authorization) on redirects.
return fmt.Errorf("server returned redirect to %s", req.URL.Redacted())
},
- },
- logger: logger,
+ }
+ }
+
+ u := &Updater{
+ cfg: cfg,
+ client: client,
+ logger: logger,
+ configErr: configErr,
}
u.performUpdateFn = u.performUpdate
u.initialDelay = 5 * time.Second
@@ -192,6 +202,11 @@ func (u *Updater) RunLoop(ctx context.Context) {
return
}
+ if u.configErr != nil {
+ u.logger.Error().Err(u.configErr).Msg("auto-update disabled due to invalid TLS client configuration")
+ return
+ }
+
if u.cfg.CurrentVersion == developmentVersion {
u.logger.Debug().Msg("Auto-update disabled in development mode")
return
@@ -245,6 +260,11 @@ func (u *Updater) CheckAndUpdate(ctx context.Context) {
return
}
+ if u.configErr != nil {
+ u.logger.Error().Err(u.configErr).Msg("Skipping update check - invalid TLS client configuration")
+ return
+ }
+
if u.cfg.PulseURL == "" {
u.logger.Debug().Msg("skipping update check - no pulse URL configured")
return
@@ -338,6 +358,9 @@ func (u *Updater) finishCheck() {
// getServerVersion fetches the current version from the Pulse server.
func (u *Updater) getServerVersion(ctx context.Context) (string, error) {
+ if u.configErr != nil {
+ return "", fmt.Errorf("invalid updater configuration: %w", u.configErr)
+ }
if err := u.validatePulseURL(); err != nil {
return "", fmt.Errorf("invalid Pulse URL: %w", err)
}
@@ -411,6 +434,13 @@ func (u *Updater) newAuthedGetRequest(ctx context.Context, requestURL string) (*
}
func (u *Updater) getWithRetry(ctx context.Context, requestURL, operation string) (*http.Response, error) {
+ if u.configErr != nil {
+ return nil, fmt.Errorf("invalid updater configuration: %w", u.configErr)
+ }
+ if u.client == nil {
+ return nil, fmt.Errorf("%s client is not configured", operation)
+ }
+
var lastErr error
for attempt := 1; attempt <= updateRequestMaxAttempts; attempt++ {
diff --git a/internal/agentupdate/update_http_test.go b/internal/agentupdate/update_http_test.go
index 46e580903d..91565052ef 100644
--- a/internal/agentupdate/update_http_test.go
+++ b/internal/agentupdate/update_http_test.go
@@ -167,6 +167,29 @@ func TestNew_UsesPinnedServerFingerprintForHTTPTransport(t *testing.T) {
}
}
+func TestNew_InvalidCustomCABundleFailsClosed(t *testing.T) {
+ certPath := filepath.Join(t.TempDir(), "invalid.pem")
+ if err := os.WriteFile(certPath, []byte("not-a-cert"), 0o600); err != nil {
+ t.Fatalf("write cert: %v", err)
+ }
+
+ u := New(Config{
+ PulseURL: "https://pulse.example.com",
+ CurrentVersion: "1.0.0",
+ CACertPath: certPath,
+ })
+
+ if u.client != nil {
+ t.Fatal("expected updater HTTP client to remain disabled when the custom CA bundle is invalid")
+ }
+ if u.configErr == nil {
+ t.Fatal("expected invalid CA bundle to populate configErr")
+ }
+ if _, err := u.getServerVersion(context.Background()); err == nil || !strings.Contains(err.Error(), "invalid CA bundle") {
+ t.Fatalf("expected invalid CA bundle error, got %v", err)
+ }
+}
+
func configureTrustedUpdateSigningKey(t *testing.T) ed25519.PrivateKey {
t.Helper()
diff --git a/internal/remoteconfig/client.go b/internal/remoteconfig/client.go
index 76686c87a3..c0c7c5eafb 100644
--- a/internal/remoteconfig/client.go
+++ b/internal/remoteconfig/client.go
@@ -3,6 +3,7 @@ package remoteconfig
import (
"context"
"encoding/json"
+ "errors"
"fmt"
"io"
@@ -69,28 +70,33 @@ const maxHTTPErrorBodyBytes = 4096
// New creates a new remote config client.
func New(cfg Config) *Client {
cfg, cfgErr := normalizeConfig(cfg)
+ configErr := cfgErr
+ var httpClient *http.Client
tlsConfig, err := agenttls.NewClientTLSConfig(cfg.CACertPath, cfg.InsecureSkipVerify, cfg.ServerFingerprint)
if err != nil {
- cfg.Logger.Warn().Err(err).Str("ca_cert_path", strings.TrimSpace(cfg.CACertPath)).Msg("Invalid custom CA bundle; continuing with default TLS roots")
- tlsConfig, _ = agenttls.NewClientTLSConfig("", cfg.InsecureSkipVerify, cfg.ServerFingerprint)
- }
-
- httpClient := &http.Client{
- Timeout: 10 * time.Second,
- Transport: &http.Transport{
- Proxy: http.ProxyFromEnvironment,
- TLSClientConfig: tlsConfig,
- },
- CheckRedirect: func(req *http.Request, via []*http.Request) error {
- return fmt.Errorf("server returned redirect to %s", req.URL)
- },
+ cfg.Logger.Error().
+ Err(err).
+ Str("ca_cert_path", strings.TrimSpace(cfg.CACertPath)).
+ Msg("Invalid custom CA bundle; refusing to fall back to default TLS roots")
+ configErr = errors.Join(configErr, fmt.Errorf("invalid CA bundle: %w", err))
+ } else {
+ httpClient = &http.Client{
+ Timeout: 10 * time.Second,
+ Transport: &http.Transport{
+ Proxy: http.ProxyFromEnvironment,
+ TLSClientConfig: tlsConfig,
+ },
+ CheckRedirect: func(req *http.Request, via []*http.Request) error {
+ return fmt.Errorf("server returned redirect to %s", req.URL)
+ },
+ }
}
return &Client{
cfg: cfg,
httpClient: httpClient,
- configErr: cfgErr,
+ configErr: configErr,
}
}
diff --git a/internal/remoteconfig/client_additional_test.go b/internal/remoteconfig/client_additional_test.go
index 25b5ebfdfb..137e6bd28d 100644
--- a/internal/remoteconfig/client_additional_test.go
+++ b/internal/remoteconfig/client_additional_test.go
@@ -8,6 +8,8 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
+ "os"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -235,6 +237,27 @@ func TestClientNew_UsesPinnedServerFingerprint(t *testing.T) {
}
}
+func TestClientNew_InvalidCustomCABundleFailsClosed(t *testing.T) {
+ certPath := filepath.Join(t.TempDir(), "invalid.pem")
+ if err := os.WriteFile(certPath, []byte("not-a-cert"), 0o600); err != nil {
+ t.Fatalf("write cert: %v", err)
+ }
+
+ client := New(Config{
+ PulseURL: "https://pulse.example",
+ APIToken: "token",
+ AgentID: "agent-1",
+ CACertPath: certPath,
+ })
+
+ if client.httpClient != nil {
+ t.Fatal("expected HTTP client to remain disabled when the custom CA bundle is invalid")
+ }
+ if _, _, err := client.Fetch(context.Background()); err == nil || !strings.Contains(err.Error(), "invalid CA bundle") {
+ t.Fatalf("expected invalid CA bundle error, got %v", err)
+ }
+}
+
func TestClientFetchResolveAgentIDError(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.Path, "/lookup") {