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.

Restore remote config signature compatibility

rcourtmane8b3c7fcf777
diff --git a/docs/API.md b/docs/API.md
index 42ce37c979..fa02c7f7f5 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -1166,7 +1166,11 @@ Removes an agent from state.
Returns the server-side config payload for an agent (used by remote config and debugging). Requires `agent:config:read`.
The `config` object includes the merged desired settings, command enablement
decision, and desired-config metadata. When signing is configured, the
-signature covers that metadata with the rest of the config payload:
+signature remains backward-compatible with legacy agents: it covers
+`agentId`, `commandsEnabled`, `settings`, `issuedAt`, and `expiresAt`.
+`desiredConfig` is computed from the signed command decision plus the
+agent-applied settings keys and returned as tamper-evident metadata for newer
+clients to recompute and compare.
```json
{
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index cc72400341..dc8541fdad 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -1919,9 +1919,13 @@ proofs.
The remote-config side of that same Unified Agent boundary now also carries a
backend-owned desired-config fingerprint. `Monitor.GetHostAgentConfig` must
compute the metadata after profile settings and command enablement decisions
-have been merged, and `/api/agents/agent/{id}/config` may sign that metadata
-with the rest of the config payload. Broader applied-state reporting and
-connections-ledger rollout presentation remain outside this backend foundation.
+have been merged. `/api/agents/agent/{id}/config` must keep the existing
+config `signature` backward-compatible with installed agents by signing the
+legacy canonical payload shape only; newer clients validate `desiredConfig` by
+recomputing it from the signed command decision and signed settings payload,
+restricted to the agent-applied settings key schema. Broader applied-state
+reporting and connections-ledger rollout presentation remain outside this
+backend foundation.
That same canonical /api/auto-register path must also complete the live
post-registration contract after persistence: it must trigger discovery refresh
and emit the canonical `node_auto_registered` WebSocket payload instead of
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index d09ef509ee..3c15497ff6 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -3951,9 +3951,13 @@ preserve or re-emit `host-agent:*` aliases.
`GET /api/agents/agent/{id}/config` now also owns desired-config metadata in
the backend API contract. The response `config.desiredConfig` carries a
non-secret versioned hash computed after profile settings and command
-enablement decisions have been merged, and config signatures cover that
-metadata together with `commandsEnabled`, `settings`, `issuedAt`, and
-`expiresAt`.
+enablement decisions have been merged. The existing `signature` field stays
+backward-compatible with installed agents and covers the legacy canonical
+payload shape: `agentId`, `commandsEnabled`, `settings`, `issuedAt`, and
+`expiresAt`. New clients validate `desiredConfig` by recomputing it from the
+signed command decision and the signed settings payload, restricted to the
+agent-applied settings key schema, rather than treating `desiredConfig` itself
+as a direct member of that signature payload.
Agent profile delete and unassign clients must now also route canonical `204`
success handling through shared allowed-status helpers in
`frontend-modern/src/api/responseUtils.ts` instead of open-coding local
diff --git a/internal/api/agent_ingest.go b/internal/api/agent_ingest.go
index b46b2dd785..54b4013320 100644
--- a/internal/api/agent_ingest.go
+++ b/internal/api/agent_ingest.go
@@ -409,7 +409,6 @@ func (h *UnifiedAgentHandlers) signAgentConfig(agentID string, cfg monitoring.Ho
ExpiresAt: expiresAt,
CommandsEnabled: cfg.CommandsEnabled,
Settings: cfg.Settings,
- DesiredConfig: cfg.DesiredConfig,
}
signature, err := remoteconfig.SignConfigPayload(payload, key)
diff --git a/internal/api/unified_agent_handlers_additional_test.go b/internal/api/unified_agent_handlers_additional_test.go
index 652e2eb33c..7d21546916 100644
--- a/internal/api/unified_agent_handlers_additional_test.go
+++ b/internal/api/unified_agent_handlers_additional_test.go
@@ -394,7 +394,6 @@ func TestUnifiedAgentHandlers_HandleConfigSignsDesiredMetadata(t *testing.T) {
ExpiresAt: *resp.Config.ExpiresAt,
CommandsEnabled: resp.Config.CommandsEnabled,
Settings: resp.Config.Settings,
- DesiredConfig: resp.Config.DesiredConfig,
}
if err := remoteconfig.VerifyConfigPayloadSignature(payload, resp.Config.Signature); err != nil {
t.Fatalf("VerifyConfigPayloadSignature: %v", err)
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index 0ccde4ade3..f6af0d9cef 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -385,7 +385,7 @@ func (m *Monitor) GetHostAgentConfig(hostID string) HostAgentConfig {
if profileID != "" {
for _, p := range profiles {
if p.ID == profileID {
- cfg.Settings = p.Config
+ cfg.Settings = p.MergedConfig(profiles)
break
}
}
diff --git a/internal/monitoring/monitor_profiles_test.go b/internal/monitoring/monitor_profiles_test.go
index 44bd1720a8..6d6a865455 100644
--- a/internal/monitoring/monitor_profiles_test.go
+++ b/internal/monitoring/monitor_profiles_test.go
@@ -126,6 +126,68 @@ func TestGetHostAgentConfig_FingerprintIncludesCommandDecision(t *testing.T) {
}
}
+func TestGetHostAgentConfig_UsesMergedProfileConfigForFingerprint(t *testing.T) {
+ tmpDir, err := os.MkdirTemp("", "monitor_profiles_merged_test")
+ if err != nil {
+ t.Fatalf("Failed to create temp dir: %v", err)
+ }
+ defer os.RemoveAll(tmpDir)
+
+ persistence := config.NewConfigPersistence(tmpDir)
+ parent := models.AgentProfile{
+ ID: "parent-profile",
+ Name: "Parent Profile",
+ Config: map[string]interface{}{
+ "enable_docker": true,
+ "log_level": "warn",
+ },
+ }
+ child := models.AgentProfile{
+ ID: "child-profile",
+ Name: "Child Profile",
+ ParentID: "parent-profile",
+ Config: map[string]interface{}{
+ "interval": "45s",
+ "log_level": "debug",
+ },
+ }
+ if err := persistence.SaveAgentProfiles([]models.AgentProfile{parent, child}); err != nil {
+ t.Fatalf("Failed to save profiles: %v", err)
+ }
+ if err := persistence.SaveAgentProfileAssignments([]models.AgentProfileAssignment{{
+ AgentID: "agent-child",
+ ProfileID: "child-profile",
+ }}); err != nil {
+ t.Fatalf("Failed to save assignments: %v", err)
+ }
+
+ m := &Monitor{
+ persistence: persistence,
+ config: &config.Config{},
+ }
+
+ cfg := m.GetHostAgentConfig("agent-child")
+ if cfg.Settings["enable_docker"] != true {
+ t.Fatalf("expected inherited enable_docker=true, got %v", cfg.Settings["enable_docker"])
+ }
+ if cfg.Settings["interval"] != "45s" {
+ t.Fatalf("expected child interval override, got %v", cfg.Settings["interval"])
+ }
+ if cfg.Settings["log_level"] != "debug" {
+ t.Fatalf("expected child log_level override, got %v", cfg.Settings["log_level"])
+ }
+ assertDesiredConfigMetadata(t, cfg)
+
+ childOnly := HostAgentConfig{CommandsEnabled: cfg.CommandsEnabled, Settings: child.Config}
+ childOnlyExpected, err := remoteconfig.BuildDesiredConfigMetadata(childOnly.CommandsEnabled, childOnly.Settings)
+ if err != nil {
+ t.Fatalf("BuildDesiredConfigMetadata child only: %v", err)
+ }
+ if cfg.DesiredConfig.Hash == childOnlyExpected.Hash {
+ t.Fatalf("expected inherited settings to affect desired config hash")
+ }
+}
+
func assertDesiredConfigMetadata(t *testing.T, cfg HostAgentConfig) {
t.Helper()
diff --git a/internal/remoteconfig/client.go b/internal/remoteconfig/client.go
index 9420fa1472..55b2c678ad 100644
--- a/internal/remoteconfig/client.go
+++ b/internal/remoteconfig/client.go
@@ -236,7 +236,6 @@ func (c *Client) Fetch(ctx context.Context) (map[string]interface{}, *bool, erro
ExpiresAt: configResp.Config.ExpiresAt,
CommandsEnabled: configResp.Config.CommandsEnabled,
Settings: configResp.Config.Settings,
- DesiredConfig: configResp.Config.DesiredConfig,
}
if err := VerifyConfigPayloadSignature(payload, configResp.Config.Signature); err != nil {
logger.Warn().
diff --git a/internal/remoteconfig/client_additional_test.go b/internal/remoteconfig/client_additional_test.go
index 4407d2db7a..bfe48fd0e7 100644
--- a/internal/remoteconfig/client_additional_test.go
+++ b/internal/remoteconfig/client_additional_test.go
@@ -39,7 +39,6 @@ func TestClientFetchWithSignature(t *testing.T) {
ExpiresAt: expiresAt,
CommandsEnabled: &commands,
Settings: settings,
- DesiredConfig: &desired,
}
signature, err := SignConfigPayload(payload, priv)
if err != nil {
@@ -83,6 +82,56 @@ func TestClientFetchWithSignature(t *testing.T) {
}
}
+func TestClientFetchRejectsTamperedDesiredConfigWithLegacySignature(t *testing.T) {
+ pub, priv, err := ed25519.GenerateKey(nil)
+ if err != nil {
+ t.Fatalf("GenerateKey: %v", err)
+ }
+ t.Setenv("PULSE_AGENT_CONFIG_PUBLIC_KEYS", base64.StdEncoding.EncodeToString(pub))
+
+ issuedAt := time.Now().UTC()
+ expiresAt := issuedAt.Add(5 * time.Minute)
+ commands := true
+ settings := map[string]interface{}{"interval": "1m"}
+ payload := SignedConfigPayload{
+ AgentID: "agent-1",
+ IssuedAt: issuedAt,
+ ExpiresAt: expiresAt,
+ CommandsEnabled: &commands,
+ Settings: settings,
+ }
+ signature, err := SignConfigPayload(payload, priv)
+ if err != nil {
+ t.Fatalf("SignConfigPayload: %v", err)
+ }
+
+ tampered := DesiredConfigMetadata{Version: desiredConfigFingerprintVersion, Hash: "sha256:0000"}
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ resp := Response{
+ Success: true,
+ AgentID: "agent-1",
+ }
+ resp.Config.CommandsEnabled = &commands
+ resp.Config.Settings = settings
+ resp.Config.DesiredConfig = &tampered
+ resp.Config.IssuedAt = issuedAt
+ resp.Config.ExpiresAt = expiresAt
+ resp.Config.Signature = signature
+ _ = json.NewEncoder(w).Encode(resp)
+ }))
+ defer ts.Close()
+
+ client := New(Config{
+ PulseURL: ts.URL,
+ APIToken: "token-123",
+ AgentID: "agent-1",
+ })
+
+ if _, _, err := client.Fetch(context.Background()); err == nil || !strings.Contains(err.Error(), "desired config fingerprint mismatch") {
+ t.Fatalf("expected desired metadata tamper error, got %v", err)
+ }
+}
+
func TestClientFetchValidatesDesiredConfigMetadata(t *testing.T) {
commands := true
settings := map[string]interface{}{"interval": "1m"}
diff --git a/internal/remoteconfig/signature.go b/internal/remoteconfig/signature.go
index 780419eac2..cf9a9238bc 100644
--- a/internal/remoteconfig/signature.go
+++ b/internal/remoteconfig/signature.go
@@ -14,6 +14,7 @@ import (
"strings"
"time"
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
"github.com/rcourtman/pulse-go-rewrite/internal/utils"
)
@@ -40,7 +41,6 @@ type SignedConfigPayload struct {
ExpiresAt time.Time
CommandsEnabled *bool
Settings map[string]interface{}
- DesiredConfig *DesiredConfigMetadata
}
// DecodeEd25519PrivateKey decodes a base64-encoded Ed25519 private key or seed.
@@ -151,10 +151,6 @@ func canonicalConfigPayload(payload SignedConfigPayload) ([]byte, error) {
ExpiresAt string `json:"expiresAt"`
CommandsEnabled *bool `json:"commandsEnabled,omitempty"`
Settings json.RawMessage `json:"settings,omitempty"`
- DesiredConfig *struct {
- Version string `json:"version"`
- Hash string `json:"hash"`
- } `json:"desiredConfig,omitempty"`
}
var settings json.RawMessage
@@ -166,30 +162,12 @@ func canonicalConfigPayload(payload SignedConfigPayload) ([]byte, error) {
settings = data
}
- var desiredConfig *struct {
- Version string `json:"version"`
- Hash string `json:"hash"`
- }
- if payload.DesiredConfig != nil {
- normalized := normalizeDesiredConfigMetadata(*payload.DesiredConfig)
- if normalized.Version != "" || normalized.Hash != "" {
- desiredConfig = &struct {
- Version string `json:"version"`
- Hash string `json:"hash"`
- }{
- Version: normalized.Version,
- Hash: normalized.Hash,
- }
- }
- }
-
canonical := canonicalPayload{
AgentID: strings.TrimSpace(payload.AgentID),
IssuedAt: payload.IssuedAt.UTC().Format(time.RFC3339Nano),
ExpiresAt: payload.ExpiresAt.UTC().Format(time.RFC3339Nano),
CommandsEnabled: payload.CommandsEnabled,
Settings: settings,
- DesiredConfig: desiredConfig,
}
data, err := json.Marshal(canonical)
@@ -207,8 +185,9 @@ func canonicalDesiredConfigPayload(commandsEnabled *bool, settings map[string]in
}
var rawSettings json.RawMessage
- if len(settings) > 0 {
- data, err := marshalSortedMap(settings)
+ appliedSettings := desiredConfigAppliedSettings(settings)
+ if len(appliedSettings) > 0 {
+ data, err := marshalSortedMap(appliedSettings)
if err != nil {
return nil, fmt.Errorf("marshal canonical settings: %w", err)
}
@@ -228,6 +207,32 @@ func canonicalDesiredConfigPayload(commandsEnabled *bool, settings map[string]in
return data, nil
}
+func desiredConfigAppliedSettings(settings map[string]interface{}) map[string]interface{} {
+ if len(settings) == 0 {
+ return nil
+ }
+
+ allowed := desiredConfigAppliedSettingKeys()
+ filtered := make(map[string]interface{}, len(settings))
+ for key, value := range settings {
+ if _, ok := allowed[key]; ok {
+ filtered[key] = value
+ }
+ }
+ if len(filtered) == 0 {
+ return nil
+ }
+ return filtered
+}
+
+func desiredConfigAppliedSettingKeys() map[string]struct{} {
+ allowed := make(map[string]struct{}, len(models.ValidConfigKeys))
+ for _, def := range models.ValidConfigKeys {
+ allowed[def.Key] = struct{}{}
+ }
+ return allowed
+}
+
func normalizeDesiredConfigMetadata(metadata DesiredConfigMetadata) DesiredConfigMetadata {
return DesiredConfigMetadata{
Version: strings.TrimSpace(metadata.Version),
diff --git a/internal/remoteconfig/signature_test.go b/internal/remoteconfig/signature_test.go
index f3656f2c02..449a167098 100644
--- a/internal/remoteconfig/signature_test.go
+++ b/internal/remoteconfig/signature_test.go
@@ -41,18 +41,14 @@ func TestVerifyConfigPayloadSignature_WithEnvKey(t *testing.T) {
func TestBuildDesiredConfigMetadataStableAndSensitiveToDecisions(t *testing.T) {
commandsEnabled := true
firstSettings := map[string]interface{}{
- "b": 2,
- "a": map[string]interface{}{
- "d": "x",
- "c": []interface{}{"y", float64(3)},
- },
+ "interval": "45s",
+ "enable_docker": true,
+ "log_level": "debug",
}
secondSettings := map[string]interface{}{
- "a": map[string]interface{}{
- "c": []interface{}{"y", float64(3)},
- "d": "x",
- },
- "b": 2,
+ "log_level": "debug",
+ "enable_docker": true,
+ "interval": "45s",
}
first, err := BuildDesiredConfigMetadata(&commandsEnabled, firstSettings)
@@ -81,6 +77,41 @@ func TestBuildDesiredConfigMetadataStableAndSensitiveToDecisions(t *testing.T) {
if withDifferentCommandDecision.Hash == first.Hash {
t.Fatalf("expected command decision to affect desired config fingerprint")
}
+
+ withDifferentSettings, err := BuildDesiredConfigMetadata(&commandsEnabled, map[string]interface{}{
+ "interval": "30s",
+ "enable_docker": true,
+ "log_level": "debug",
+ })
+ if err != nil {
+ t.Fatalf("BuildDesiredConfigMetadata changed settings: %v", err)
+ }
+ if withDifferentSettings.Hash == first.Hash {
+ t.Fatalf("expected applied settings to affect desired config fingerprint")
+ }
+}
+
+func TestBuildDesiredConfigMetadataIgnoresUnknownUnappliedSettings(t *testing.T) {
+ commandsEnabled := true
+ settings := map[string]interface{}{
+ "interval": "1m",
+ "token_value": "secret-like-value",
+ }
+ withoutUnknown := map[string]interface{}{
+ "interval": "1m",
+ }
+
+ got, err := BuildDesiredConfigMetadata(&commandsEnabled, settings)
+ if err != nil {
+ t.Fatalf("BuildDesiredConfigMetadata with unknown: %v", err)
+ }
+ want, err := BuildDesiredConfigMetadata(&commandsEnabled, withoutUnknown)
+ if err != nil {
+ t.Fatalf("BuildDesiredConfigMetadata without unknown: %v", err)
+ }
+ if got != want {
+ t.Fatalf("expected unknown unapplied settings to be excluded from desired metadata, got %#v want %#v", got, want)
+ }
}
func TestValidateDesiredConfigMetadata(t *testing.T) {
@@ -102,7 +133,7 @@ func TestValidateDesiredConfigMetadata(t *testing.T) {
}
}
-func TestVerifyConfigPayloadSignatureCoversDesiredConfigMetadata(t *testing.T) {
+func TestConfigSignatureUsesLegacyPayloadShape(t *testing.T) {
pub, priv, err := ed25519.GenerateKey(nil)
if err != nil {
t.Fatalf("GenerateKey: %v", err)
@@ -111,17 +142,23 @@ func TestVerifyConfigPayloadSignatureCoversDesiredConfigMetadata(t *testing.T) {
commandsEnabled := true
settings := map[string]interface{}{"interval": "1m"}
- metadata, err := BuildDesiredConfigMetadata(&commandsEnabled, settings)
- if err != nil {
- t.Fatalf("BuildDesiredConfigMetadata: %v", err)
- }
+ issuedAt := time.Date(2026, 5, 13, 17, 0, 0, 0, time.UTC)
+ expiresAt := issuedAt.Add(15 * time.Minute)
payload := SignedConfigPayload{
AgentID: "host-1",
- IssuedAt: time.Now().UTC(),
- ExpiresAt: time.Now().UTC().Add(time.Minute),
+ IssuedAt: issuedAt,
+ ExpiresAt: expiresAt,
CommandsEnabled: &commandsEnabled,
Settings: settings,
- DesiredConfig: &metadata,
+ }
+
+ canonical, err := canonicalConfigPayload(payload)
+ if err != nil {
+ t.Fatalf("canonicalConfigPayload: %v", err)
+ }
+ expectedCanonical := `{"agentId":"host-1","issuedAt":"2026-05-13T17:00:00Z","expiresAt":"2026-05-13T17:15:00Z","commandsEnabled":true,"settings":{"interval":"1m"}}`
+ if string(canonical) != expectedCanonical {
+ t.Fatalf("canonical payload = %s, want %s", string(canonical), expectedCanonical)
}
sig, err := SignConfigPayload(payload, priv)
@@ -131,13 +168,6 @@ func TestVerifyConfigPayloadSignatureCoversDesiredConfigMetadata(t *testing.T) {
if err := VerifyConfigPayloadSignature(payload, sig); err != nil {
t.Fatalf("VerifyConfigPayloadSignature: %v", err)
}
-
- tampered := metadata
- tampered.Hash = "sha256:0000"
- payload.DesiredConfig = &tampered
- if err := VerifyConfigPayloadSignature(payload, sig); err == nil {
- t.Fatalf("expected signature verification to fail after desired metadata tamper")
- }
}
func TestDecodeEd25519PrivateKey(t *testing.T) {