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.

Fix Docker agent reconnect token binding

rcourtman09231a9ef7ae
diff --git a/docs/release-control/v6/internal/records/known-rc-issue-closure-for-ga-docker-agent-reconnect-2026-05-01.md b/docs/release-control/v6/internal/records/known-rc-issue-closure-for-ga-docker-agent-reconnect-2026-05-01.md
new file mode 100644
index 0000000000..8d0898d7a4
--- /dev/null
+++ b/docs/release-control/v6/internal/records/known-rc-issue-closure-for-ga-docker-agent-reconnect-2026-05-01.md
@@ -0,0 +1,46 @@
+# Known RC Issue Closure For GA Docker Agent Reconnect Record
+
+- Date: `2026-05-01`
+- Gate: `known-rc-issue-closure-for-ga`
+- Result: `passed`
+
+## Context
+
+Late RC3 issue triage rechecked `#1447`, where a Docker agent running inside an
+LXC could reconnect initially, then be rejected after the agent container was
+recreated because the server treated the new container-derived identity as a
+different host association.
+
+An earlier pass correctly noted that v6 had agent ID file persistence and
+hostname-plus-token Docker host re-identification, but this pass found one
+remaining gap: after the host was matched, the Docker token-binding guard still
+compared the token against the new raw agent ID.
+
+## Disposition
+
+The fix is in the monitoring-owned Docker report ingest path:
+
+- `resolveDockerHostIdentifier` still owns the canonical Docker host match.
+- `ApplyDockerReport` now resolves token-binding identity from the matched
+ canonical Docker host when one exists, while treating the previous host source
+ ID, previous agent ID, current agent ID, machine ID, and hostname as aliases
+ for the same already-matched host.
+- Token-binding rebuild after API token reload now uses the same canonical
+ Docker host identity rather than reintroducing raw-agent-ID-first bindings.
+- The one-token-per-Docker-agent rule remains intact for genuinely different
+ hosts. A different host using a token that is already bound to another Docker
+ host is still rejected.
+
+## Proof
+
+- `go test ./internal/monitoring -run 'TestApplyDockerReport_(ReconnectWithoutMachineID|RecreatedContainerAgentIDKeepsTokenBinding|TokenBoundToDifferentAgent|SameHostnameDifferentTokens)$' -count=1`
+- `go test ./internal/monitoring -run 'TestApplyDockerReport' -count=1`
+- `go test ./internal/monitoring -count=1`
+- `go test ./cmd/pulse-agent -run 'TestAgentIDFilePersistence|TestRun_PassesStateDirToUpdaterAndHostAgent' -count=1`
+
+## Outcome
+
+The v6 candidate no longer regresses the reported Docker-in-LXC recreation path:
+a recreated container can keep reporting under the same API token after the
+canonical host match succeeds, without weakening token uniqueness for separate
+Docker agents.
diff --git a/docs/release-control/v6/internal/status.json b/docs/release-control/v6/internal/status.json
index f0e089ed54..4af53e8bfa 100644
--- a/docs/release-control/v6/internal/status.json
+++ b/docs/release-control/v6/internal/status.json
@@ -3082,6 +3082,12 @@
"unified-resources"
],
"evidence": [
+ {
+ "repo": "pulse",
+ "path": "docs/release-control/v6/internal/records/known-rc-issue-closure-for-ga-docker-agent-reconnect-2026-05-01.md",
+ "kind": "file",
+ "evidence_tier": "managed-runtime-exercise"
+ },
{
"repo": "pulse",
"path": "docs/release-control/v6/internal/subsystems/monitoring.md",
@@ -4403,6 +4409,12 @@
"kind": "file",
"evidence_tier": "managed-runtime-exercise"
},
+ {
+ "repo": "pulse",
+ "path": "docs/release-control/v6/internal/records/known-rc-issue-closure-for-ga-docker-agent-reconnect-2026-05-01.md",
+ "kind": "file",
+ "evidence_tier": "managed-runtime-exercise"
+ },
{
"repo": "pulse",
"path": "docs/release-control/v6/internal/records/known-rc-issue-closure-for-ga-duplicate-metrics-2026-05-01.md",
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index de7631f808..08c8247e0a 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -640,6 +640,13 @@ monitoring may treat `qnap` and `qnap.local` as the same host when the token
or machine identity already points at one canonical runtime, but it must not
invent broader short-name collapsing on its own or fork away from the
unified-resource monitored-system contract.
+That same Docker host identity boundary also owns token-binding aliases after
+a reconnect match. When `ApplyDockerReport` has already matched a report to an
+existing canonical Docker host, the token uniqueness guard must accept that
+host's stable source ID and previous agent ID as aliases for the current raw
+agent ID so container recreation does not reject the same logical host after it
+has been matched. This must not weaken the one-token-per-Docker-agent rule for
+different hosts.
Node disk-source selection now also routes through one canonical resolver
under `internal/monitoring/`. When a Proxmox node has a linked Pulse host
agent, the node summary must prefer the linked host's canonical disk view over
diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.go
index 410cfe142a..e3941db840 100644
--- a/internal/monitoring/canonical_guardrails_test.go
+++ b/internal/monitoring/canonical_guardrails_test.go
@@ -186,6 +186,38 @@ func TestDockerHostIdentityUsesCanonicalHostnameEquivalence(t *testing.T) {
}
}
+func TestDockerTokenBindingUsesCanonicalHostIdentity(t *testing.T) {
+ requiredSnippets := map[string][]string{
+ "docker_host_identity.go": {
+ "func resolveDockerTokenBindingIdentity(",
+ "preferred = dockerHostStableID(previous)",
+ "previous.AgentID()",
+ "func dockerTokenBindingMatches(",
+ },
+ "monitor_agents.go": {
+ "resolveDockerTokenBindingIdentity(identifier, report, previous, hasPrevious)",
+ "dockerTokenBindingMatches(boundAgentID, tokenBindingAliases)",
+ "Bound Docker agent token to host identity",
+ },
+ "monitor.go": {
+ "Docker host identity bindings",
+ },
+ }
+
+ for file, snippets := range requiredSnippets {
+ data, err := os.ReadFile(file)
+ if err != nil {
+ t.Fatalf("failed to read %s: %v", file, err)
+ }
+ source := string(data)
+ for _, snippet := range snippets {
+ if !strings.Contains(source, snippet) {
+ t.Fatalf("%s must contain %q", file, snippet)
+ }
+ }
+ }
+}
+
func TestGuestMemoryFallbackUsesCanonicalLowTrustSelector(t *testing.T) {
data, err := os.ReadFile("guest_memory_sources.go")
if err != nil {
diff --git a/internal/monitoring/docker_host_identity.go b/internal/monitoring/docker_host_identity.go
index 7a922d3a12..3922f78d6e 100644
--- a/internal/monitoring/docker_host_identity.go
+++ b/internal/monitoring/docker_host_identity.go
@@ -157,6 +157,56 @@ func dockerHostStableID(host *unifiedresources.DockerHostView) string {
return strings.TrimSpace(host.ID())
}
+func resolveDockerTokenBindingIdentity(identifier string, report agentsdocker.Report, previous *unifiedresources.DockerHostView, hasPrevious bool) (string, []string) {
+ preferred := ""
+ if hasPrevious {
+ preferred = dockerHostStableID(previous)
+ }
+ if preferred == "" {
+ preferred = strings.TrimSpace(report.Agent.ID)
+ }
+ if preferred == "" {
+ preferred = strings.TrimSpace(identifier)
+ }
+ if preferred == "" {
+ preferred = strings.TrimSpace(report.Host.MachineID)
+ }
+ if preferred == "" {
+ preferred = strings.TrimSpace(report.Host.Hostname)
+ }
+
+ aliases := uniqueNonEmptyStrings(
+ preferred,
+ identifier,
+ report.Agent.ID,
+ report.Host.MachineID,
+ report.Host.Hostname,
+ )
+ if previous != nil {
+ aliases = uniqueNonEmptyStrings(append(aliases,
+ dockerHostStableID(previous),
+ previous.AgentID(),
+ previous.MachineID(),
+ previous.Hostname(),
+ )...)
+ }
+
+ return preferred, aliases
+}
+
+func dockerTokenBindingMatches(boundAgentID string, aliases []string) bool {
+ boundAgentID = strings.TrimSpace(boundAgentID)
+ if boundAgentID == "" {
+ return false
+ }
+ for _, alias := range aliases {
+ if boundAgentID == strings.TrimSpace(alias) {
+ return true
+ }
+ }
+ return false
+}
+
// dockerHostIDExists checks if a host ID is already in use.
func dockerHostIDExists(id string, hosts []*unifiedresources.DockerHostView) bool {
if strings.TrimSpace(id) == "" {
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index f9af043ae0..c5169678ce 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -955,7 +955,7 @@ type Monitor struct {
vmRRDMemCache map[string]rrdMemCacheEntry
vmAgentMemCache map[string]agentMemCacheEntry
removedDockerHosts map[string]time.Time // Track deliberately removed Docker hosts (ID -> removal time)
- dockerTokenBindings map[string]string // Track token ID -> agent ID bindings to enforce uniqueness
+ dockerTokenBindings map[string]string // Track token ID -> Docker host identity bindings to enforce uniqueness
removedKubernetesClusters map[string]time.Time // Track deliberately removed Kubernetes clusters (ID -> removal time)
kubernetesTokenBindings map[string]string // Track token ID -> agent ID bindings to enforce uniqueness
removedHostAgents map[string]time.Time // Track deliberately removed host agents (ID -> removal time)
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index 3307afd042..6c61e3117e 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -875,13 +875,9 @@ func (m *Monitor) RebuildTokenBindings() {
if _, valid := validTokens[tokenID]; !valid {
continue
}
- // Use AgentID if available, otherwise fall back to host ID
- agentID := strings.TrimSpace(host.AgentID())
- if agentID == "" {
- agentID = strings.TrimSpace(host.HostSourceID())
- }
+ agentID := dockerHostStableID(host)
if agentID == "" {
- agentID = strings.TrimSpace(host.ID())
+ agentID = strings.TrimSpace(host.AgentID())
}
if agentID != "" {
newDockerBindings[tokenID] = agentID
@@ -1010,17 +1006,14 @@ func (m *Monitor) ApplyDockerReport(report agentsdocker.Report, tokenRecord *con
return models.DockerHost{}, fmt.Errorf("docker host %q had monitoring stopped at %v and cannot report again. Use Allow reconnect in Settings -> Infrastructure or rerun the installer with a docker:manage token to clear this block", identifier, removedAt.Format(time.RFC3339))
}
- // Enforce token uniqueness: each token can only be bound to one agent
+ // Enforce token uniqueness: each token can only be bound to one Docker host identity.
if tokenRecord != nil && tokenRecord.ID != "" {
tokenID := strings.TrimSpace(tokenRecord.ID)
- agentID := strings.TrimSpace(report.Agent.ID)
- if agentID == "" {
- agentID = identifier
- }
+ agentID, tokenBindingAliases := resolveDockerTokenBindingIdentity(identifier, report, previous, hasPrevious)
m.mu.Lock()
if boundAgentID, exists := m.dockerTokenBindings[tokenID]; exists {
- if boundAgentID != agentID {
+ if !dockerTokenBindingMatches(boundAgentID, tokenBindingAliases) {
m.mu.Unlock()
// Find the conflicting host to provide helpful error message
conflictingHostname := "unknown"
@@ -1050,6 +1043,9 @@ func (m *Monitor) ApplyDockerReport(report agentsdocker.Report, tokenRecord *con
Msg("Rejecting Docker report: token already bound to different agent")
return models.DockerHost{}, fmt.Errorf("API token%s is already in use by agent %q (host: %s). Each Docker agent must use a unique API token. Generate a new token for this agent", tokenHint, boundAgentID, conflictingHostname)
}
+ if boundAgentID != agentID {
+ m.dockerTokenBindings[tokenID] = agentID
+ }
} else {
// First time seeing this token - bind it to this agent
m.dockerTokenBindings[tokenID] = agentID
@@ -1057,7 +1053,7 @@ func (m *Monitor) ApplyDockerReport(report agentsdocker.Report, tokenRecord *con
Str("tokenID", tokenID).
Str("agentID", agentID).
Str("hostname", report.Host.Hostname).
- Msg("Bound Docker agent token to agent identity")
+ Msg("Bound Docker agent token to host identity")
}
m.mu.Unlock()
}
diff --git a/internal/monitoring/monitor_extra_coverage_test.go b/internal/monitoring/monitor_extra_coverage_test.go
index acf387b1cb..4ff4c31295 100644
--- a/internal/monitoring/monitor_extra_coverage_test.go
+++ b/internal/monitoring/monitor_extra_coverage_test.go
@@ -724,7 +724,7 @@ func TestMonitor_TokenBindings_UseUnifiedReadState(t *testing.T) {
m.RebuildTokenBindings()
- if got := m.dockerTokenBindings["docker-token"]; got != "docker-agent-1" {
+ if got := m.dockerTokenBindings["docker-token"]; got != "docker-source-1" {
t.Fatalf("expected docker binding from unified read-state, got %q", got)
}
if got := m.hostTokenBindings["host-token:host-1"]; got != "host-agent-1" {
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index 3d54c6131a..0374c135f1 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -94,6 +94,46 @@ func TestFindLinkedProxmoxEntityWithHints_UsesExactEndpointHostnameBeforeNameFal
}
}
+func TestApplyDockerReport_RecreatedContainerAgentIDKeepsTokenBinding(t *testing.T) {
+ monitor := newTestMonitor(t)
+ token := &config.APITokenRecord{ID: "token-recreated-container", Name: "Docker Token"}
+
+ firstReport := agentsdocker.Report{
+ Agent: agentsdocker.AgentInfo{
+ ID: "container-machine-id-a",
+ Version: "1.0.0",
+ IntervalSeconds: 30,
+ },
+ Host: agentsdocker.HostInfo{
+ Hostname: "docker-lxc",
+ MachineID: "container-machine-id-a",
+ },
+ Timestamp: time.Now().UTC(),
+ }
+
+ host1, err := monitor.ApplyDockerReport(firstReport, token)
+ if err != nil {
+ t.Fatalf("first ApplyDockerReport failed: %v", err)
+ }
+
+ recreatedReport := firstReport
+ recreatedReport.Agent.ID = "container-machine-id-b"
+ recreatedReport.Host.MachineID = "container-machine-id-b"
+ recreatedReport.Timestamp = firstReport.Timestamp.Add(time.Minute)
+
+ host2, err := monitor.ApplyDockerReport(recreatedReport, token)
+ if err != nil {
+ t.Fatalf("recreated container report should keep the existing token binding: %v", err)
+ }
+
+ if host1.ID != host2.ID {
+ t.Fatalf("expected recreated container to retain host ID %q, got %q", host1.ID, host2.ID)
+ }
+ if got := monitor.dockerTokenBindings[token.ID]; got != host1.ID {
+ t.Fatalf("token binding = %q, want stable host ID %q", got, host1.ID)
+ }
+}
+
func TestEvaluateHostAgentsTriggersOfflineAlert(t *testing.T) {
t.Helper()